类net.minecraft.inventory.SimpleInventory源码实例Demo

下面列出了怎么用net.minecraft.inventory.SimpleInventory的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: bleachhack-1.14   文件: CmdPeek.java
@Override
public void onCommand(String command, String[] args) throws Exception {
	ItemStack item = mc.player.inventory.getMainHandStack();
	
	if (!(item.getItem() instanceof BlockItem)) {
		BleachLogger.errorMessage("Must be holding a containter to peek.");
		return;
	}
	
	if (!(((BlockItem) item.getItem()).getBlock() instanceof ShulkerBoxBlock)
			 && !(((BlockItem) item.getItem()).getBlock() instanceof ChestBlock)
			 && !(((BlockItem) item.getItem()).getBlock() instanceof DispenserBlock)
			 && !(((BlockItem) item.getItem()).getBlock() instanceof HopperBlock)) {
		BleachLogger.errorMessage("Must be holding a containter to peek.");
		return;
	}
	
	List<ItemStack> items = ItemContentUtils.getItemsInContainer(item);
	
	SimpleInventory inv = new SimpleInventory(items.toArray(new ItemStack[27]));
	
	BleachQueue.queue.add(() -> {
		mc.openScreen(new ShulkerBoxScreen(
				new ShulkerBoxScreenHandler(420, mc.player.inventory, inv),
				mc.player.inventory,
				item.getName()));
	});
}
 
private ItemStack getResultFromRecipeStack() {
    SimpleInventory inv = new SimpleInventory(getInventory().getStack(5));
    // This should under no circumstances not be present. If it is, this method has been called before isValidRecipe and you should feel bad.
    FabricationRecipe recipe = getRecipe(inv).orElseThrow(() -> new IllegalStateException("Not a valid recipe."));
    return recipe.craft(inv);
}
 
private Optional<FabricationRecipe> getRecipe(SimpleInventory input) {
    return this.world.getRecipeManager().getFirstMatch(GalacticraftRecipes.FABRICATION_TYPE, input, this.world);
}
 
private boolean isValidRecipe(ItemStack input) {
        // TODO check up on this
        return getRecipe(new SimpleInventory(input)).isPresent() && hasMandatoryMaterials();
//        return !input.isEmpty() && hasMandatoryMaterials();
    }
 
源代码5 项目: LibGui   文件: SyncedGuiDescription.java
/**
 * Gets the block inventory at the context.
 *
 * <p>If no inventory is found, returns a simple mutable inventory
 * with the specified number of slots.
 *
 * <p>Searches for these implementations in the following order:
 * <ol>
 *     <li>Blocks implementing {@code InventoryProvider}</li>
 *     <li>Block entities implementing {@code InventoryProvider}</li>
 *     <li>Block entities implementing {@code Inventory}</li>
 * </ol>
 *
 * @param ctx  the context
 * @param size the fallback inventory size
 * @return the found inventory
 * @since 2.0.0
 */
public static Inventory getBlockInventory(ScreenHandlerContext ctx, int size) {
	return getBlockInventory(ctx, () -> new SimpleInventory(size));
}