net.minecraftforge.items.ItemStackHandler Java Examples

The following examples show how to use net.minecraftforge.items.ItemStackHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RecipeMapCategory.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public RecipeMapCategory(RecipeMap<?> recipeMap, IGuiHelper guiHelper) {
    this.recipeMap = recipeMap;
    FluidTank[] importFluidTanks = new FluidTank[recipeMap.getMaxFluidInputs()];
    for (int i = 0; i < importFluidTanks.length; i++)
        importFluidTanks[i] = new FluidTank(16000);
    FluidTank[] exportFluidTanks = new FluidTank[recipeMap.getMaxFluidOutputs()];
    for (int i = 0; i < exportFluidTanks.length; i++)
        exportFluidTanks[i] = new FluidTank(16000);
    this.modularUI = recipeMap.createJeiUITemplate(
        (importItems = new ItemStackHandler(recipeMap.getMaxInputs())),
        (exportItems = new ItemStackHandler(recipeMap.getMaxOutputs())),
        (importFluids = new FluidTankList(false, importFluidTanks)),
        (exportFluids = new FluidTankList(false, exportFluidTanks))
    ).build(new BlankUIHolder(), Minecraft.getMinecraft().player);
    this.modularUI.initWidgets();
    this.backgroundDrawable = guiHelper.createBlankDrawable(modularUI.getWidth(), modularUI.getHeight() * 2 / 3);
}
 
Example #2
Source File: BackpackDataItems.java    From WearableBackpacks with MIT License 6 votes vote down vote up
public static void generateLoot(ItemStackHandler items, String tableStr, long seed,
                                World world, EntityPlayer player) {
	Random rnd = new Random(seed);
	double maxFullness = (0.6 + rnd.nextDouble() * 0.2);
	int maxOccupiedSlots = (int)Math.ceil(items.getSlots() * maxFullness);
	
	LootTableManager manager = world.getLootTableManager();
	LootTable table = manager.getLootTableFromLocation(new ResourceLocation(tableStr));
	LootContext context = new LootContext(((player != null) ? player.getLuck() : 0),
	                                      (WorldServer)world, manager, player, null, null);
	List<ItemStack> loot = table.generateLootForPools(rnd, context);
	Collections.shuffle(loot);
	
	List<Integer> randomizedSlots = new ArrayList<Integer>(items.getSlots());
	for (int i = 0; i < items.getSlots(); i++) randomizedSlots.add(i);
	Collections.shuffle(randomizedSlots);
	for (int i = 0; (i < maxOccupiedSlots) && (i < loot.size()); i++) {
		ItemStack stack = loot.get(i);
		int slot = randomizedSlots.get(i);
		items.setStackInSlot(slot, stack);
	}
}
 
Example #3
Source File: CraftingPlateRecipeManager.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static boolean tick(World world, BlockPos pos, ItemStack input, ItemStackHandler inventoryHandler, Function<IManaCapability, Double> consumeMana) {
	ICraftingPlateRecipe recipe = null;

	for (ICraftingPlateRecipe search : recipes) {
		if (search.doesRecipeExistInWorld(world, pos) || search.doesRecipeExistForItem(input)) {
			recipe = search;
			break;
		}
	}
	if (recipe == null) return false;

	if (!recipe.isDone(world, pos, input)) {
		recipe.tick(world, pos, input, inventoryHandler, consumeMana);
	} else {
		recipe.complete(world, pos, input, inventoryHandler);
		return true;
	}
	return false;
}
 
Example #4
Source File: TileEntityPhysicsInfuser.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
public TileEntityPhysicsInfuser() {
    handler = new ItemStackHandler(EnumInfuserCore.values().length) {
        @Override
        protected void onContentsChanged(int slot) {
            sendUpdateToClients = true;
        }
    };
    sendUpdateToClients = false;
    isTryingToAssembleShip = false;
    isTryingToDisassembleShip = false;
    isPhysicsEnabled = false;
    isTryingToAlignShip = false;
    coreOffsets = new HashMap<>();
    coreOffsetsPrevTick = new HashMap<>();
    for (EnumInfuserCore enumInfuserCore : EnumInfuserCore.values()) {
        coreOffsets.put(enumInfuserCore, 0D);
        coreOffsetsPrevTick.put(enumInfuserCore, 0D);
    }
}
 
Example #5
Source File: MetaTileEntityFisher.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected IItemHandlerModifiable createImportItemHandler() {
    return new ItemStackHandler(1) {
        @Nonnull
        @Override
        public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
            if(OreDictUnifier.getOreDictionaryNames(stack).contains("string")) {
                return super.insertItem(slot, stack, simulate);
            }
            return stack;
        }
    };
}
 
Example #6
Source File: PacketOpenFilterContainer.java    From MiningGadgets with MIT License 5 votes vote down vote up
public static void handle(PacketOpenFilterContainer msg, Supplier<NetworkEvent.Context> ctx) {
    ctx.get().enqueueWork(() -> {
        ServerPlayerEntity sender = ctx.get().getSender();
        if (sender == null)
            return;

        Container container = sender.openContainer;
        if (container == null)
            return;

        ItemStack stack = MiningGadget.getGadget(sender);
        if( stack.isEmpty() )
            return;

        ItemStackHandler ghostInventory = new ItemStackHandler(30) {
            @Override
            protected void onContentsChanged(int slot) {
                stack.getOrCreateTag().put(MiningProperties.KEY_FILTERS, serializeNBT());
            }
        };

        ghostInventory.deserializeNBT(stack.getOrCreateChildTag(MiningProperties.KEY_FILTERS));
        sender.openContainer(new SimpleNamedContainerProvider(
                (windowId, playerInventory, playerEntity) -> new FilterContainer(windowId, playerInventory, ghostInventory), new StringTextComponent("")
        ));
    });

    ctx.get().setPacketHandled(true);
}
 
Example #7
Source File: SimpleMachineMetaTileEntity.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public SimpleMachineMetaTileEntity(ResourceLocation metaTileEntityId, RecipeMap<?> recipeMap, OrientedOverlayRenderer renderer, int tier, boolean hasFrontFacing) {
    super(metaTileEntityId, recipeMap, renderer, tier);
    this.hasFrontFacing = hasFrontFacing;
    this.chargerInventory = new ItemStackHandler(1) {
        @Override
        public int getSlotLimit(int slot) {
            return 1;
        }
    };
}
 
Example #8
Source File: AutomationItemStackHandler.java    From EmergingTechnology with MIT License 5 votes vote down vote up
public AutomationItemStackHandler(ItemStackHandler hidden, int validInputSlot, int validOutputSlot) {
	super();
	mainHandler = hidden;

	this.validOutputSlot = validOutputSlot;
	this.validInputSlot = validInputSlot;
}
 
Example #9
Source File: CraftingRecipeResolver.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public CraftingRecipeResolver(World world, ItemStackHandler craftingGrid, CraftingRecipeMemory recipeMemory) {
    this.world = world;
    this.craftingGrid = craftingGrid;
    this.recipeMemory = recipeMemory;
    this.itemSourceList = new ItemSourceList(world);
    this.itemSourceList.addItemListChangeCallback(this::notifyStoredItemsChanged);
}
 
Example #10
Source File: SimpleGeneratorMetaTileEntity.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public SimpleGeneratorMetaTileEntity(ResourceLocation metaTileEntityId, FuelRecipeMap recipeMap, OrientedOverlayRenderer renderer, int tier) {
    super(metaTileEntityId, tier);
    this.containerInventory = new ItemStackHandler(2);
    this.overlayRenderer = renderer;
    this.recipeMap = recipeMap;
    this.workableHandler = createWorkableHandler();
}
 
Example #11
Source File: ContainerBackpack.java    From WearableBackpacks with MIT License 5 votes vote down vote up
@SideOnly(Side.CLIENT)
public ContainerBackpack(EntityPlayer player, NBTTagCompound data) {
	this.player   = player;
	this.backpack = null;
	this.data     = null;
	
	size  = BackpackSize.parse(data.getTag(TAG_SIZE));
	items = new ItemStackHandler(size.getColumns() * size.getRows());
	
	title = data.getString(TAG_TITLE);
	titleLocalized = data.getBoolean(TAG_LOCALIZED);
	
	setupSlots();
}
 
Example #12
Source File: MetaTileEntityQuantumTank.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public MetaTileEntityQuantumTank(ResourceLocation metaTileEntityId, int tier, int maxFluidCapacity) {
    super(metaTileEntityId);
    this.tier = tier;
    this.maxFluidCapacity = maxFluidCapacity;
    this.containerInventory = new ItemStackHandler(2);
    initializeInventory();
}
 
Example #13
Source File: ContainerEngineeringTable.java    From Cyberware with MIT License 5 votes vote down vote up
public void checkForNewBoxes()
{
	for (int i = 0; i < playerInv.mainInventory.length; i++)
	{
		if (!this.componentBoxList.contains(i))
		{
			ItemStack stack = playerInv.mainInventory[i];
			if (stack != null && stack.getItem() == CyberwareContent.componentBox.ib)
			{
				if (!stack.hasTagCompound())
				{
					stack.setTagCompound(new NBTTagCompound());
				}
				if (!stack.getTagCompound().hasKey("contents"))
				{
					ItemStackHandler slots = new ItemStackHandlerComponent(18);
					stack.getTagCompound().setTag("contents", slots.serializeNBT());
				}
				if (componentBox == null )
				{
					componentBox = i;
					componentBoxIndex = componentBoxList.size();
				}

				componentBoxList.add(i);
			}
		}
	}
}
 
Example #14
Source File: FairyJarRecipe.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void tick(World world, BlockPos pos, ItemStack input, ItemStackHandler inventoryHandler, Function<IManaCapability, Double> consumeMana) {
	TileEntity tileEntity = world.getTileEntity(pos.offset(EnumFacing.UP));
	if (!(tileEntity instanceof TileJar)) return;
	TileJar jar = (TileJar) tileEntity;

	if (jar.fairy != null
			&& jar.fairy.infusedSpell.isEmpty()
			&& !jar.fairy.isDepressed
			&& !ManaManager.isManaFull(jar.fairy.handler)) {
		ManaManager.forObject(jar.fairy.handler).addMana(consumeMana.apply(jar.fairy.handler)).close();
		jar.markDirty();
	}
}
 
Example #15
Source File: ItemHelperTests.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void test_removeInputsFromInventory_ore()
{
    ItemStackHandler inv = new ItemStackHandler(2);
    inv.setStackInSlot(0, new ItemStack(Items.APPLE));
    inv.setStackInSlot(1, new ItemStack(Items.STICK, 3));

    RecipeInputImpl input1 = new RecipeInputImpl("stickWood", 2);
    RecipeInputImpl input2 = RecipeInputImpl.create(new ItemStack(Items.APPLE, 1));
    ItemHelper.removeInputsFromInventory(Lists.newArrayList(input1, input2), inv, 0, 2);

    assertTrue(inv.getStackInSlot(0).isEmpty());
    assertEquals(1, inv.getStackInSlot(1).getCount());
}
 
Example #16
Source File: SteamBoiler.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public SteamBoiler(ResourceLocation metaTileEntityId, boolean isHighPressure, OrientedOverlayRenderer renderer, int baseSteamOutput) {
    super(metaTileEntityId);
    this.renderer = renderer;
    this.isHighPressure = isHighPressure;
    this.baseSteamOutput = baseSteamOutput;
    BRONZE_BACKGROUND_TEXTURE = getGuiTexture("%s_gui");
    BRONZE_SLOT_BACKGROUND_TEXTURE = getGuiTexture("slot_%s");
    SLOT_FURNACE_BACKGROUND = getGuiTexture("slot_%s_furnace_background");
    this.containerInventory = new ItemStackHandler(2);
}
 
Example #17
Source File: ItemHelperTests.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void test_removeInputsFromInventory_stacks()
{
    ItemStackHandler inv = new ItemStackHandler(2);
    inv.setStackInSlot(0, new ItemStack(Items.APPLE));
    inv.setStackInSlot(1, new ItemStack(Items.STICK, 3));

    RecipeInputImpl input1 = RecipeInputImpl.create(new ItemStack(Items.STICK, 2));
    RecipeInputImpl input2 = RecipeInputImpl.create(new ItemStack(Items.APPLE, 1));
    ItemHelper.removeInputsFromInventory(Lists.newArrayList(input1, input2), inv, 0, 2);

    assertTrue(inv.getStackInSlot(0).isEmpty());
    assertEquals(1, inv.getStackInSlot(1).getCount());
}
 
Example #18
Source File: SteamCoalBoiler.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public IItemHandlerModifiable createImportItemHandler() {
    return new ItemStackHandler(1) {
        @Nonnull
        @Override
        public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
            if (TileEntityFurnace.getItemBurnTime(stack) <= 0)
                return stack;
            return super.insertItem(slot, stack, simulate);
        }
    };
}
 
Example #19
Source File: SimpleItemFilter.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public SimpleItemFilter() {
    this.itemFilterSlots = new ItemStackHandler(MAX_MATCH_SLOTS) {
        @Override
        public int getSlotLimit(int slot) {
            return getMaxStackSize();
        }
    };
}
 
Example #20
Source File: MetaTileEntityCokeOven.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected IItemHandlerModifiable createExportItemHandler() {
    return new ItemStackHandler(1);
}
 
Example #21
Source File: MetaTileEntityPrimitiveBlastFurnace.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected IItemHandlerModifiable createExportItemHandler() {
    return new ItemStackHandler(2);
}
 
Example #22
Source File: MetaTileEntityQuantumChest.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected IItemHandlerModifiable createImportItemHandler() {
    return new ItemStackHandler(1);
}
 
Example #23
Source File: MetaTileEntityQuantumChest.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected IItemHandlerModifiable createExportItemHandler() {
    return new ItemStackHandler(1);
}
 
Example #24
Source File: MetaTileEntityCokeOvenHatch.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void initializeInventory() {
    super.initializeInventory();
    this.fluidInventory = new FluidTankList(false);
    this.itemInventory = new ItemStackHandler(0);
}
 
Example #25
Source File: MetaTileEntityCokeOvenHatch.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void removeFromMultiBlock(MultiblockControllerBase controllerBase) {
    super.removeFromMultiBlock(controllerBase);
    this.fluidInventory = new FluidTankList(false);
    this.itemInventory = new ItemStackHandler(0);
}
 
Example #26
Source File: MetaTileEntityPrimitiveBlastFurnace.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void initializeInventory() {
    super.initializeInventory();
    ItemStackHandler emptyHandler = new ItemStackHandler(0);
    this.itemInventory = new ItemHandlerProxy(emptyHandler, emptyHandler);
}
 
Example #27
Source File: SimpleItemFilter.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ItemStackHandler getItemFilterSlots() {
    return itemFilterSlots;
}
 
Example #28
Source File: FluidFilterContainer.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ItemStackHandler getFilterInventory() {
    return filterInventory;
}
 
Example #29
Source File: MetaTileEntityCharger.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected IItemHandlerModifiable createExportItemHandler() {
    return new ItemStackHandler(0);
}
 
Example #30
Source File: MetaTileEntityCokeOven.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected IItemHandlerModifiable createImportItemHandler() {
    return new ItemStackHandler(1);
}