net.minecraftforge.items.IItemHandlerModifiable Java Examples
The following examples show how to use
net.minecraftforge.items.IItemHandlerModifiable.
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: MetaTileEntityFluidHatch.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
public ModularUI.Builder createTankUI(IFluidTank fluidTank, IItemHandlerModifiable containerInventory, String title, EntityPlayer entityPlayer) { Builder builder = ModularUI.defaultBuilder(); builder.image(7, 16, 81, 55, GuiTextures.DISPLAY); TankWidget tankWidget = new TankWidget(fluidTank, 69, 52, 18, 18) .setHideTooltip(true).setAlwaysShowFull(true); builder.widget(tankWidget); builder.label(11, 20, "gregtech.gui.fluid_amount", 0xFFFFFF); builder.dynamicLabel(11, 30, tankWidget::getFormattedFluidAmount, 0xFFFFFF); builder.dynamicLabel(11, 40, tankWidget::getFluidLocalizedName, 0xFFFFFF); return builder.label(6, 6, title) .widget(new FluidContainerSlotWidget(containerInventory, 0, 90, 17, !isExportHatch) .setBackgroundTexture(GuiTextures.SLOT, GuiTextures.IN_SLOT_OVERLAY)) .widget(new ImageWidget(91, 36, 14, 15, GuiTextures.TANK_ICON)) .widget(new SlotWidget(containerInventory, 1, 90, 54, true, false) .setBackgroundTexture(GuiTextures.SLOT, GuiTextures.OUT_SLOT_OVERLAY)) .bindPlayerInventory(entityPlayer.inventory); }
Example #2
Source File: CapabilityProviderItem.java From customstuff4 with GNU General Public License v3.0 | 6 votes |
@Nullable private IItemHandlerModifiable getItemHandlerCapability(@Nullable EnumFacing facing) { Capability<IItemHandler> capability = CapabilityItemHandler.ITEM_HANDLER_CAPABILITY; List<IItemHandlerModifiable> handlers = Lists.newLinkedList(); for (ItemModule module : modules.values()) { if (module.hasCapability(capability, facing)) handlers.add((IItemHandlerModifiable) module.getCapability(capability, facing)); } if (handlers.size() == 1) return handlers.get(0); else if (handlers.size() > 1) return new CombinedInvWrapper(handlers.toArray(new IItemHandlerModifiable[handlers.size()])); else return null; }
Example #3
Source File: SlotItemHandlerGeneric.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void putStack(ItemStack stack) { if (this.getItemHandler() instanceof IItemHandlerModifiable) { //System.out.printf("SlotItemHandlerGeneric#putStack() - setStackInSlot() - slot: %3d stack: %s\n", this.getSlotIndex(), stack); ((IItemHandlerModifiable) this.getItemHandler()).setStackInSlot(this.getSlotIndex(), stack); } else { EnderUtilities.logger.warn("SlotItemHandlerGeneric#putStack() by insertItem() - things will not work well!"); this.getItemHandler().insertItem(this.getSlotIndex(), stack, false); } this.onSlotChanged(); }
Example #4
Source File: ItemHelper.java From customstuff4 with GNU General Public License v3.0 | 6 votes |
public static void removeInputsFromInventory(List<RecipeInput> inputs, IItemHandlerModifiable inv, int start, int numSlots) { List<RecipeInput> remaining = Lists.newLinkedList(inputs); for (int i = start; i < start + numSlots; i++) { ItemStack stack = inv.getStackInSlot(i); for (Iterator<RecipeInput> iterator = remaining.iterator(); iterator.hasNext(); ) { RecipeInput input = iterator.next(); if (stackMatchesRecipeInput(stack, input, true)) { extractInput(input, inv, i); iterator.remove(); break; } } } }
Example #5
Source File: AbstractRecipeLogic.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
protected void trySearchNewRecipe() { long maxVoltage = getMaxVoltage(); Recipe currentRecipe = null; IItemHandlerModifiable importInventory = getInputInventory(); IMultipleTankHandler importFluids = getInputTank(); if (previousRecipe != null && previousRecipe.matches(false, importInventory, importFluids)) { //if previous recipe still matches inputs, try to use it currentRecipe = previousRecipe; } else { boolean dirty = checkRecipeInputsDirty(importInventory, importFluids); if (dirty || forceRecipeRecheck) { this.forceRecipeRecheck = false; //else, try searching new recipe for given inputs currentRecipe = findRecipe(maxVoltage, importInventory, importFluids); if (currentRecipe != null) { this.previousRecipe = currentRecipe; } } } if (currentRecipe != null && setupAndConsumeRecipeInputs(currentRecipe)) { setupRecipe(currentRecipe); } }
Example #6
Source File: EnergyContainerHandler.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
public boolean dischargeOrRechargeEnergyContainers(IItemHandlerModifiable itemHandler, int slotIndex) { ItemStack stackInSlot = itemHandler.getStackInSlot(slotIndex); if (stackInSlot.isEmpty()) { return false; } IElectricItem electricItem = stackInSlot.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null); if (electricItem == null || !electricItem.canProvideChargeExternally()) { return false; } int machineTier = GTUtility.getTierByVoltage(Math.max(getInputVoltage(), getOutputVoltage())); if (getEnergyCanBeInserted() > 0) { double chargePercent = getEnergyStored() / (getEnergyCapacity() * 1.0); if (chargePercent <= 0.5) { long dischargedBy = electricItem.discharge(getEnergyCanBeInserted(), machineTier, false, true, false); addEnergy(dischargedBy); return dischargedBy > 0L; } else if (chargePercent >= 0.9) { long chargedBy = electricItem.charge(getEnergyStored(), machineTier, false, false); removeEnergy(chargedBy); return chargedBy > 0L; } } return false; }
Example #7
Source File: RecipeMapGroupOutput.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
protected ServerWidgetGroup createItemOutputWidgetGroup(IItemHandlerModifiable itemHandler, ServerWidgetGroup widgetGroup) { int[] inputSlotGrid = determineSlotsGrid(itemHandler.getSlots()); int itemSlotsToLeft = inputSlotGrid[0]; int itemSlotsToDown = inputSlotGrid[1]; int startInputsX = 106; int startInputsY = 32 - (int) (itemSlotsToDown / 2.0 * 18); for (int i = 0; i < itemSlotsToDown; i++) { for (int j = 0; j < itemSlotsToLeft; j++) { int slotIndex = i * itemSlotsToLeft + j; int x = startInputsX + 18 * j; int y = startInputsY + 18 * i; widgetGroup.addWidget(new SlotWidget(itemHandler, slotIndex, x, y, true, false) .setBackgroundTexture(getOverlaysForSlot(true, false, false))); } } return widgetGroup; }
Example #8
Source File: EnergyContainerBatteryBuffer.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
@Override public long changeEnergy(long energyToAdd) { boolean isDischarge = energyToAdd < 0L; energyToAdd = Math.abs(energyToAdd); long initialEnergyToAdd = energyToAdd; IItemHandlerModifiable inventory = getInventory(); for (int i = 0; i < inventory.getSlots(); i++) { ItemStack batteryStack = inventory.getStackInSlot(i); IElectricItem electricItem = getBatteryContainer(batteryStack); if (electricItem == null) continue; long charged = chargeItem(electricItem, energyToAdd, getTier(), isDischarge); energyToAdd -= charged; if(energyToAdd == 0L) break; } long energyAdded = initialEnergyToAdd - energyToAdd; if(energyAdded > 0L) { notifyEnergyListener(false); } return energyAdded; }
Example #9
Source File: TileEntitySimple.java From customstuff4 with GNU General Public License v3.0 | 6 votes |
@Nullable private IItemHandlerModifiable getItemHandlerCapability(@Nullable EnumFacing facing) { Capability<IItemHandler> capability = CapabilityItemHandler.ITEM_HANDLER_CAPABILITY; List<IItemHandlerModifiable> handlers = Lists.newLinkedList(); for (TileEntityModule module : modules.values()) { if (module.hasCapability(capability, facing)) handlers.add((IItemHandlerModifiable) module.getCapability(capability, facing)); } if (handlers.size() == 1) return handlers.get(0); else if (handlers.size() > 1) return new CombinedInvWrapper(handlers.toArray(new IItemHandlerModifiable[handlers.size()])); else return null; }
Example #10
Source File: GTUtility.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
public static void readItems(IItemHandlerModifiable handler, String tagName, NBTTagCompound tag) { if (tag.hasKey(tagName)) { NBTTagList tagList = tag.getTagList(tagName, Constants.NBT.TAG_COMPOUND); for (int i = 0; i < tagList.tagCount(); i++) { int slot = tagList.getCompoundTagAt(i).getInteger("Slot"); if (slot >= 0 && slot < handler.getSlots()) { handler.setStackInSlot(slot, new ItemStack(tagList.getCompoundTagAt(i))); } } } }
Example #11
Source File: MetaTileEntityChest.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
private static void sortInventorySlotContents(IItemHandlerModifiable inventory) { //stack item stacks with equal items and compounds for (int i = 0; i < inventory.getSlots(); i++) { for (int j = i + 1; j < inventory.getSlots(); j++) { ItemStack stack1 = inventory.getStackInSlot(i); ItemStack stack2 = inventory.getStackInSlot(j); if (!stack1.isEmpty() && ItemStack.areItemsEqual(stack1, stack2) && ItemStack.areItemStackTagsEqual(stack1, stack2)) { int maxStackSize = Math.min(stack1.getMaxStackSize(), inventory.getSlotLimit(i)); int itemsCanAccept = Math.min(stack2.getCount(), maxStackSize - Math.min(stack1.getCount(), maxStackSize)); if (itemsCanAccept > 0) { stack1.grow(itemsCanAccept); stack2.shrink(itemsCanAccept); } } } } //create itemstack pairs and sort them out by attributes ArrayList<ItemStack> inventoryContents = new ArrayList<>(); for (int i = 0; i < inventory.getSlots(); i++) { ItemStack itemStack = inventory.getStackInSlot(i); if (!itemStack.isEmpty()) { inventory.setStackInSlot(i, ItemStack.EMPTY); inventoryContents.add(itemStack); } } inventoryContents.sort(GTUtility.createItemStackComparator()); for (int i = 0; i < inventoryContents.size(); i++) { inventory.setStackInSlot(i, inventoryContents.get(i)); } }
Example #12
Source File: BlockOben.java From Sakura_mod with MIT License | 5 votes |
@Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { TileEntityOben te = (TileEntityOben) worldIn.getTileEntity(pos); IItemHandler inventory = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP); if (inventory != null && inventory.getStackInSlot(0) != ItemStack.EMPTY) { Block.spawnAsEntity(worldIn, pos, inventory.getStackInSlot(0)); ((IItemHandlerModifiable) inventory).setStackInSlot(0, ItemStack.EMPTY); } super.breakBlock(worldIn, pos, state); }
Example #13
Source File: ChoppingContext.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
public ChoppingContext(IItemHandlerModifiable inner, @Nullable PlayerEntity player, int axeLevel, int fortune, Random random) { super(inner, player != null ? player::getPositionVec : null, 64); this.player = player; this.axeLevel = axeLevel; this.fortune = fortune; this.random = random; }
Example #14
Source File: EnergyContainerBatteryBuffer.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public long getInputAmperage() { long inputAmperage = 0L; IItemHandlerModifiable inventory = getInventory(); for (int i = 0; i < inventory.getSlots(); i++) { ItemStack batteryStack = inventory.getStackInSlot(i); IElectricItem electricItem = getBatteryContainer(batteryStack); if (electricItem == null) continue; inputAmperage++; } return inputAmperage; }
Example #15
Source File: EnergyContainerBatteryBuffer.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public long getEnergyStored() { long energyStored = 0L; IItemHandlerModifiable inventory = getInventory(); for (int i = 0; i < inventory.getSlots(); i++) { ItemStack batteryStack = inventory.getStackInSlot(i); IElectricItem electricItem = getBatteryContainer(batteryStack); if (electricItem == null) continue; energyStored += electricItem.getCharge(); } return energyStored; }
Example #16
Source File: AbstractRecipeLogic.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
protected boolean setupAndConsumeRecipeInputs(Recipe recipe) { int[] resultOverclock = calculateOverclock(recipe.getEUt(), getMaxVoltage(), recipe.getDuration()); int totalEUt = resultOverclock[0] * resultOverclock[1]; IItemHandlerModifiable importInventory = getInputInventory(); IItemHandlerModifiable exportInventory = getOutputInventory(); IMultipleTankHandler importFluids = getInputTank(); IMultipleTankHandler exportFluids = getOutputTank(); return (totalEUt >= 0 ? getEnergyStored() >= (totalEUt > getEnergyCapacity() / 2 ? resultOverclock[0] : totalEUt) : (getEnergyStored() - resultOverclock[0] <= getEnergyCapacity())) && MetaTileEntity.addItemsToItemHandler(exportInventory, true, recipe.getAllItemOutputs(exportInventory.getSlots())) && MetaTileEntity.addFluidsToFluidHandler(exportFluids, true, recipe.getFluidOutputs()) && recipe.matches(true, importInventory, importFluids); }
Example #17
Source File: InventoryCraftingEnderUtilities.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
public InventoryCraftingEnderUtilities(int width, int height, IItemHandlerModifiable craftMatrix, ItemHandlerCraftResult resultInventory, EntityPlayer player, Container container) { super(container, 0, 0); // dummy this.inventoryWidth = width; this.inventoryHeight = height; this.craftMatrix = craftMatrix; this.craftResult = resultInventory; this.player = player; }
Example #18
Source File: MetaTileEntityMultiFurnace.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, IMultipleTankHandler fluidInputs) { int currentItemsEngaged = 0; int maxItemsLimit = 32 * heatingCoilLevel; ArrayList<CountableIngredient> recipeInputs = new ArrayList<>(); ArrayList<ItemStack> recipeOutputs = new ArrayList<>(); for (int index = 0; index < inputs.getSlots(); index++) { ItemStack stackInSlot = inputs.getStackInSlot(index); if (stackInSlot.isEmpty()) continue; Recipe matchingRecipe = recipeMap.findRecipe(maxVoltage, Collections.singletonList(stackInSlot), Collections.emptyList(), 0); CountableIngredient inputIngredient = matchingRecipe == null ? null : matchingRecipe.getInputs().get(0); if (inputIngredient != null && (maxItemsLimit - currentItemsEngaged) >= inputIngredient.getCount()) { ItemStack outputStack = matchingRecipe.getOutputs().get(0).copy(); int overclockAmount = Math.min(stackInSlot.getCount() / inputIngredient.getCount(), (maxItemsLimit - currentItemsEngaged) / inputIngredient.getCount()); recipeInputs.add(new CountableIngredient(inputIngredient.getIngredient(), inputIngredient.getCount() * overclockAmount)); if (!outputStack.isEmpty()) { outputStack.setCount(outputStack.getCount() * overclockAmount); recipeOutputs.add(outputStack); } currentItemsEngaged += inputIngredient.getCount() * overclockAmount; } if (currentItemsEngaged >= maxItemsLimit) break; } return recipeInputs.isEmpty() ? null : recipeMap.recipeBuilder() .inputsIngredients(recipeInputs) .outputs(recipeOutputs) .EUt(Math.max(1, 16 / heatingCoilDiscount)) .duration((int) Math.max(1.0, 256 * (currentItemsEngaged / (maxItemsLimit * 1.0)))) .build().getResult(); }
Example #19
Source File: InventoryUtils.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
public static void sortInventoryWithinRange(IItemHandlerModifiable inv, SlotRange range) { List<ItemTypeByName> blocks = new ArrayList<ItemTypeByName>(); List<ItemTypeByName> items = new ArrayList<ItemTypeByName>(); final int lastSlot = Math.min(range.lastInc, inv.getSlots() - 1); // Get the different items that are present in the inventory for (int i = range.first; i <= lastSlot; i++) { ItemStack stack = inv.getStackInSlot(i); if (stack.isEmpty() == false) { ItemTypeByName type = new ItemTypeByName(stack); if (stack.getItem() instanceof ItemBlock) { if (blocks.contains(type) == false) { blocks.add(type); } } else if (items.contains(type) == false) { items.add(type); } } } Collections.sort(blocks); Collections.sort(items); int slots = sortInventoryWithinRangeByTypes(inv, blocks, range); sortInventoryWithinRangeByTypes(inv, items, new SlotRange(range.first + slots, range.lastExc - (range.first + slots))); }
Example #20
Source File: RecipeMapGroupOutput.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Builder createUITemplate(DoubleSupplier progressSupplier, IItemHandlerModifiable importItems, IItemHandlerModifiable exportItems, FluidTankList importFluids, FluidTankList exportFluids) { ModularUI.Builder builder = ModularUI.defaultBuilder(); builder.widget(new ProgressWidget(progressSupplier, 77, 22, 20, 20, progressBarTexture, moveType)); addInventorySlotGroup(builder, importItems, importFluids, false); BooleanWrapper booleanWrapper = new BooleanWrapper(); ServerWidgetGroup itemOutputGroup = createItemOutputWidgetGroup(exportItems, new ServerWidgetGroup(() -> !booleanWrapper.getCurrentMode())); ServerWidgetGroup fluidOutputGroup = createFluidOutputWidgetGroup(exportFluids, new ServerWidgetGroup(booleanWrapper::getCurrentMode)); builder.widget(itemOutputGroup).widget(fluidOutputGroup); ToggleButtonWidget buttonWidget = new ToggleButtonWidget(176 - 7 - 20, 60, 20, 20, GuiTextures.BUTTON_SWITCH_VIEW, booleanWrapper::getCurrentMode, booleanWrapper::setCurrentMode) .setTooltipText("gregtech.gui.toggle_view"); builder.widget(buttonWidget); return builder; }
Example #21
Source File: LootTableHelper.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
public static void fillInventory(IItemHandlerModifiable inventory, Random rand, List<ItemStack> lootList) { List<Integer> randomSlots = getEmptySlotsRandomized(inventory, rand); shuffleItems(lootList, randomSlots.size(), rand); for (ItemStack itemstack : lootList) { if (randomSlots.isEmpty()) { return; } if (itemstack.isEmpty()) { inventory.setStackInSlot(randomSlots.remove(randomSlots.size() - 1), ItemStack.EMPTY); } else { inventory.setStackInSlot(randomSlots.remove(randomSlots.size() - 1), itemstack); } } }
Example #22
Source File: SteamCoalBoiler.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@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 #23
Source File: RecipeMap.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
protected void addSlot(ModularUI.Builder builder, int x, int y, int slotIndex, IItemHandlerModifiable itemHandler, FluidTankList fluidHandler, boolean isFluid, boolean isOutputs) { if (!isFluid) { builder.widget(new SlotWidget(itemHandler, slotIndex, x, y, true, !isOutputs) .setBackgroundTexture(getOverlaysForSlot(isOutputs, false, slotIndex == itemHandler.getSlots() - 1))); } else { builder.widget(new TankWidget(fluidHandler.getTankAt(slotIndex), x, y, 18, 18) .setAlwaysShowFull(true) .setBackgroundTexture(getOverlaysForSlot(isOutputs, true, slotIndex == fluidHandler.getTanks() - 1)) .setContainerClicking(true, !isOutputs)); } }
Example #24
Source File: ItemHelper.java From customstuff4 with GNU General Public License v3.0 | 5 votes |
static void extractInput(RecipeInput input, IItemHandlerModifiable from, int slot) { if (input.isOreClass()) { from.extractItem(slot, input.getOreClass().getAmount(), false); } else { ItemStack toExtract = input.getStack().getItemStack(); from.extractItem(slot, toExtract.getCount(), false); } }
Example #25
Source File: MetaTileEntityItemCollector.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected IItemHandlerModifiable createExportItemHandler() { return new ItemStackHandler(INVENTORY_SIZES[MathHelper.clamp(getTier(), 0, INVENTORY_SIZES.length - 1)]); }
Example #26
Source File: MetaTileEntityPump.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected IItemHandlerModifiable createImportItemHandler() { return new ItemStackHandler(1); }
Example #27
Source File: MetaTileEntityPump.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected IItemHandlerModifiable createExportItemHandler() { return new ItemStackHandler(1); }
Example #28
Source File: MetaTileEntityBlockBreaker.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected IItemHandlerModifiable createExportItemHandler() { return new ItemStackHandler(getInventorySize()); }
Example #29
Source File: SteamAlloySmelter.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
@Override public IItemHandlerModifiable createExportItemHandler() { return new ItemStackHandler(1); }
Example #30
Source File: SteamCompressor.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
@Override public IItemHandlerModifiable createImportItemHandler() { return new ItemStackHandler(1); }