net.minecraftforge.items.ItemHandlerHelper Java Examples
The following examples show how to use
net.minecraftforge.items.ItemHandlerHelper.
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: CartHopperBehaviourItems.java From Signals with GNU General Public License v3.0 | 6 votes |
@Override public boolean tryTransfer(IItemHandler from, IItemHandler to, List<Pair<TileEntity, EnumFacing>> filters){ int totalExtracted = 0; for(int i = 0; i < from.getSlots(); i++) { ItemStack extracted = from.extractItem(i, MAX_TRANSFER_RATE - totalExtracted, true); if(!extracted.isEmpty() && passesFilters(extracted, filters)) { ItemStack leftover = ItemHandlerHelper.insertItemStacked(to, extracted, false); int leftoverCount = !leftover.isEmpty() ? leftover.getCount() : 0; int actuallyExtracted = extracted.getCount() - leftoverCount; if(actuallyExtracted > 0) { from.extractItem(i, actuallyExtracted, false); totalExtracted += actuallyExtracted; if(totalExtracted >= MAX_TRANSFER_RATE) break; } } } return totalExtracted > 0; }
Example #2
Source File: BlockTFBattery.java From TofuCraftReload with MIT License | 6 votes |
@Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (!worldIn.isRemote) { ItemStack stack = playerIn.getHeldItem(hand); TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof TileEntityTofuBattery) { IFluidHandlerItem handler = FluidUtil.getFluidHandler(ItemHandlerHelper.copyStackWithSize(stack, 1)); if (handler != null) { FluidUtil.interactWithFluidHandler(playerIn, hand, tileentity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing)); return true; } else { playerIn.openGui(TofuMain.instance, TofuGuiHandler.ID_BATTERY_GUI, worldIn, pos.getX(), pos.getY(), pos.getZ()); } } } return true; }
Example #3
Source File: GTItemFluidTube.java From GT-Classic with GNU Lesser General Public License v3.0 | 6 votes |
public ActionResult<ItemStack> tryPickUpFluid(@Nonnull World world, @Nonnull EntityPlayer player, @Nonnull EnumHand hand, ItemStack itemstack, FluidStack fluidStack) { RayTraceResult mop = this.rayTrace(world, player, true); ActionResult<ItemStack> ret = ForgeEventFactory.onBucketUse(player, world, itemstack, mop); if (ret != null) return ret; if (mop == null) { return ActionResult.newResult(EnumActionResult.PASS, itemstack); } BlockPos clickPos = mop.getBlockPos(); if (world.isBlockModifiable(player, clickPos)) { FluidActionResult result = FluidUtil.tryPickUpFluid(itemstack, player, world, clickPos, mop.sideHit); if (result.isSuccess()) { ItemHandlerHelper.giveItemToPlayer(player, result.getResult()); itemstack.shrink(1); return ActionResult.newResult(EnumActionResult.SUCCESS, itemstack); } } return ActionResult.newResult(EnumActionResult.FAIL, itemstack); }
Example #4
Source File: ItemHandlerCrafting.java From customstuff4 with GNU General Public License v3.0 | 6 votes |
@Nonnull @Override public ItemStack extractItem(int slot, int amount, boolean simulate) { if (slot == rows * columns) { ItemStack result = getCraftResult(); if (result.isEmpty() || amount < result.getCount()) return ItemStack.EMPTY; amount = result.getCount(); if (!simulate) { removeItems(); setStackInSlot(rows * columns, ItemStack.EMPTY); return ItemHandlerHelper.copyStackWithSize(result, amount); } } return super.extractItem(slot, amount, simulate); }
Example #5
Source File: MetaItem.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
@Override @SideOnly(Side.CLIENT) public String getItemStackDisplayName(ItemStack stack) { if (stack.getItemDamage() >= metaItemOffset) { T item = getItem(stack); if (item == null) { return "invalid item"; } String unlocalizedName = String.format("metaitem.%s.name", item.unlocalizedName); if (item.getNameProvider() != null) { return item.getNameProvider().getItemStackDisplayName(stack, unlocalizedName); } IFluidHandlerItem fluidHandlerItem = ItemHandlerHelper.copyStackWithSize(stack, 1) .getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); if (fluidHandlerItem != null) { FluidStack fluidInside = fluidHandlerItem.drain(Integer.MAX_VALUE, false); return I18n.format(unlocalizedName, fluidInside == null ? I18n.format("metaitem.fluid_cell.empty") : fluidInside.getLocalizedName()); } return I18n.format(unlocalizedName); } return super.getItemStackDisplayName(stack); }
Example #6
Source File: Filler.java From EmergingTechnology with MIT License | 6 votes |
@Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (worldIn.isRemote) { return true; } ItemStack itemStackHeld = playerIn.getHeldItemMainhand(); Item itemHeld = itemStackHeld.getItem(); if (itemHeld == Items.BUCKET) { ItemHandlerHelper.giveItemToPlayer(playerIn, new ItemStack(Items.WATER_BUCKET)); itemStackHeld.shrink(1); } return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ); }
Example #7
Source File: BlockBarrel.java From Sakura_mod with MIT License | 6 votes |
@Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { if (world.isRemote) { return true; } ItemStack stack = player.getHeldItem(hand); TileEntity tile = world.getTileEntity(pos); if (tile instanceof TileEntityBarrel) { IFluidHandlerItem handler = FluidUtil.getFluidHandler(ItemHandlerHelper.copyStackWithSize(stack, 1)); if (handler != null) { FluidUtil.interactWithFluidHandler(player, hand, tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)); return true; } player.openGui(SakuraMain.instance, SakuraGuiHandler.ID_BARREL, world, pos.getX(), pos.getY(), pos.getZ()); return true; } return true; }
Example #8
Source File: BlockBarrelDistillation.java From Sakura_mod with MIT License | 6 votes |
@Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { if (world.isRemote) { return true; } ItemStack stack = player.getHeldItem(hand); TileEntity tile = world.getTileEntity(pos); if (tile instanceof TileEntityDistillation) { IFluidHandlerItem handler = FluidUtil.getFluidHandler(ItemHandlerHelper.copyStackWithSize(stack, 1)); if (handler != null) { FluidUtil.interactWithFluidHandler(player, hand, tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)); return true; } player.openGui(SakuraMain.instance, SakuraGuiHandler.ID_DISTILLATION, world, pos.getX(), pos.getY(), pos.getZ()); return true; } return true; }
Example #9
Source File: BlockTFStorage.java From TofuCraftReload with MIT License | 6 votes |
@Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { if (worldIn.isRemote) { return true; } else { ItemStack stack = playerIn.getHeldItem(hand); TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof TileEntityTFStorage) { IFluidHandlerItem handler = FluidUtil.getFluidHandler(ItemHandlerHelper.copyStackWithSize(stack, 1)); if (handler != null) { FluidUtil.interactWithFluidHandler(playerIn, hand, tileentity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)); return true; } else { playerIn.openGui(TofuMain.instance, TofuGuiHandler.ID_STORAGE_MACHINE_GUI, worldIn, pos.getX(), pos.getY(), pos.getZ()); } } return true; } }
Example #10
Source File: EntityFluidCow.java From Moo-Fluids with GNU General Public License v3.0 | 5 votes |
private boolean attemptToGetFluidFromCow(final ItemStack currentItemStack, final EntityPlayer entityPlayer) { boolean canGetFluid = false; if (!currentItemStack.isEmpty() && entityFluid != null) { ItemStack filledItemStack = ItemHandlerHelper.copyStackWithSize(currentItemStack, 1); IFluidHandlerItem fluidHandlerItem = FluidUtil.getFluidHandler(filledItemStack); if (fluidHandlerItem != null) { if (fluidHandlerItem.fill( new FluidStack(entityFluid, Fluid.BUCKET_VOLUME), true) == Fluid.BUCKET_VOLUME) { filledItemStack = fluidHandlerItem.getContainer(); currentItemStack.shrink(1); if (currentItemStack.isEmpty()) { entityPlayer.inventory.setInventorySlotContents( entityPlayer.inventory.currentItem, filledItemStack.copy()); } else { ItemHandlerHelper.giveItemToPlayer(entityPlayer, filledItemStack.copy()); } canGetFluid = true; } } } return canGetFluid; }
Example #11
Source File: EntityFluidCow.java From Moo-Fluids with GNU General Public License v3.0 | 5 votes |
private boolean attemptToHealCowWithFluidContainer(final ItemStack currentItemStack, final EntityPlayer entityPlayer) { boolean cowHealed = false; if (!currentItemStack.isEmpty() && entityFluid != null) { IFluidHandlerItem fluidHandlerItem = FluidUtil.getFluidHandler(currentItemStack); if (fluidHandlerItem != null) { FluidStack containedFluid = fluidHandlerItem .drain(new FluidStack(entityFluid, Fluid.BUCKET_VOLUME), false); ItemStack emptyItemStack; if (containedFluid != null && containedFluid.getFluid().getName().equalsIgnoreCase(entityFluid.getName())) { fluidHandlerItem.drain(new FluidStack(entityFluid, Fluid.BUCKET_VOLUME), false); emptyItemStack = fluidHandlerItem.getContainer(); currentItemStack.shrink(1); if (currentItemStack.isEmpty()) { entityPlayer.inventory.setInventorySlotContents( entityPlayer.inventory.currentItem, emptyItemStack.copy()); } else { ItemHandlerHelper.giveItemToPlayer(entityPlayer, emptyItemStack.copy()); } heal(4F); cowHealed = true; } } } return cowHealed; }
Example #12
Source File: ItemBreakingTracker.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void onItemBroken(PlayerEntity player, ItemStack stack) { int scrappingLevel = EnchantmentHelper.getEnchantmentLevel(SurvivalistMod.SCRAPING.get(), stack); if (player.getClass().getName().equals("com.rwtema.extrautils2.fakeplayer.XUFakePlayer")) return; boolean fortune = rnd.nextDouble() > 0.9 / (1 + scrappingLevel); ItemStack ret = null; for (Triple<ItemStack, ItemStack, ItemStack> scraping : scrapingRegistry) { ItemStack source = scraping.getLeft(); if (source.getItem() != stack.getItem()) continue; ItemStack good = scraping.getMiddle(); ItemStack bad = scraping.getRight(); ret = fortune ? good.copy() : bad.copy(); break; } if (ret != null) { SurvivalistMod.LOGGER.debug("Item broke (" + stack + ") and the player got " + ret + " in return!"); SurvivalistMod.channel.sendTo(new ScrapingMessage(stack, ret), ((ServerPlayerEntity) player).connection.netManager, NetworkDirection.PLAY_TO_CLIENT); ItemHandlerHelper.giveItemToPlayer(player, ret); } }
Example #13
Source File: SawmillBlock.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Deprecated @Override public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) { TileEntity te = worldIn.getTileEntity(pos); if (te instanceof SawmillTileEntity) return ItemHandlerHelper.calcRedstoneFromInventory(((SawmillTileEntity) te).getInventory()); return 0; }
Example #14
Source File: GTTileTesseractSlave.java From GT-Classic with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean onRightClick(EntityPlayer player, EnumHand arg1, EnumFacing arg2, Side arg3) { ItemStack slotStack = this.getStackInSlot(0); if (slotStack.isEmpty() || !player.isSneaking()) { return false; } ItemHandlerHelper.giveItemToPlayer(player, slotStack.copy()); slotStack.shrink(1); setTarget(null); this.targetPos = null; IC2.audioManager.playOnce(player, Ic2Sounds.wrenchUse); return true; }
Example #15
Source File: CapabilityMinecartDestination.java From Signals with GNU General Public License v3.0 | 5 votes |
/** * * @param cart * @return true if there was a valid hopper (not necessarily if extracted an item) */ private boolean extractFuelFromHopper(EntityMinecart cart, BlockPos pos){ boolean foundHopper = false; for(EnumFacing dir : EnumFacing.VALUES) { BlockPos neighbor = pos; for(int offsetTimes = 0; offsetTimes < (dir == EnumFacing.UP ? 2 : 1); offsetTimes++) { neighbor = neighbor.offset(dir); TileEntity te = cart.world.getTileEntity(neighbor); if(te instanceof TileEntityHopper) { EnumFacing hopperDir = cart.world.getBlockState(neighbor).getValue(BlockHopper.FACING); if(hopperDir.getOpposite() == dir) { TileEntityHopper hopper = (TileEntityHopper)te; for(int i = 0; i < hopper.getSizeInventory(); i++) { ItemStack stack = hopper.getStackInSlot(i); if(!stack.isEmpty() && getFuelInv().isItemValidForSlot(0, stack)) { ItemStack inserted = stack.copy(); inserted.setCount(1); ItemStack left = ItemHandlerHelper.insertItemStacked(getEngineItemHandler(), inserted, false); if(left.isEmpty()) { stack.shrink(1); hopper.markDirty(); return true; } } } foundHopper = true; } } } } return foundHopper; }
Example #16
Source File: PacketUpdateCraftingPlateSlot.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void handle(@NotNull MessageContext ctx) { if (ctx.side.isServer()) return; World world = LibrarianLib.PROXY.getClientPlayer().world; if (world == null) return; if (!world.isBlockLoaded(pos)) return; TileEntity entity = world.getTileEntity(pos); if (entity instanceof TileCraftingPlate) { TileCraftingPlate plate = (TileCraftingPlate) entity; if (!plate.isInventoryEmpty() && CraftingPlateRecipeManager.doesRecipeExistForItem(stack)) { ItemHandlerHelper.insertItem(plate.input.getHandler(), stack, false); } else if (!(CraftingPlateRecipeManager.doesRecipeExistForItem(stack))) { for (int i = 0; i < plate.realInventory.getHandler().getSlots(); i++) { if (plate.realInventory.getHandler().getStackInSlot(i).isEmpty()) { plate.realInventory.getHandler().insertItem(i, stack, false); if (plate.renderHandler != null) { ((TileCraftingPlateRenderer) plate.renderHandler).update(i, stack); } break; } } } } }
Example #17
Source File: ProxiedItemStackHandler.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
@Override @Nonnull public ItemStack extractItem(int slot, int amount, boolean simulate) { if (amount == 0) return ItemStack.EMPTY; validateSlotIndex(slot); ItemStack existing = readStack(slot); if (existing.isEmpty()) return ItemStack.EMPTY; int toExtract = Math.min(amount, existing.getMaxStackSize()); if (existing.getCount() <= toExtract) { if (!simulate) writeStack(slot, ItemStack.EMPTY); return existing; } else { if (!simulate) writeStack(slot, ItemHandlerHelper.copyStackWithSize(existing, existing.getCount() - toExtract)); return ItemHandlerHelper.copyStackWithSize(existing, toExtract); } }
Example #18
Source File: ProxiedItemStackHandler.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
@Override @Nonnull public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { if (stack.isEmpty()) return ItemStack.EMPTY; validateSlotIndex(slot); ItemStack existing = readStack(slot); int limit = getStackLimit(slot, stack); if (!existing.isEmpty()) { if (!ItemHandlerHelper.canItemStacksStack(stack, existing)) return stack; limit -= existing.getCount(); } if (limit <= 0) return stack; boolean reachedLimit = stack.getCount() > limit; if (!simulate) writeStack(slot, reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack); return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - limit) : ItemStack.EMPTY; }
Example #19
Source File: GTBlockMortar.java From GT-Classic with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand h, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack playerStack = player.getHeldItemMainhand(); if (playerStack.isEmpty()) { return false; } int matches = 0; for (IRecipeInput inputMatcher : INPUT_LIST) { if (inputMatcher.matches(playerStack)) { matches++; } } if (matches == 0) { return false; } if (IC2.platform.isSimulating()) { int chance = this == GTBlocks.ironMortar ? 2 : 15; if (worldIn.rand.nextInt(chance) != 0) { return true; } for (MultiRecipe recipe : RECIPE_LIST.getRecipeList()) { IRecipeInput inputStack = recipe.getInputs().get(0); ItemStack outputStack = recipe.getOutputs().getAllOutputs().get(0); if (inputStack.matches(playerStack)) { playerStack.shrink(inputStack.getAmount()); ItemHandlerHelper.giveItemToPlayer(player, outputStack.copy()); } } } worldIn.playSound(player, pos, SoundEvents.BLOCK_ANVIL_BREAK, SoundCategory.BLOCKS, 1.0F, 1.0F); return true; }
Example #20
Source File: GTItemFluidTube.java From GT-Classic with GNU Lesser General Public License v3.0 | 5 votes |
public ActionResult<ItemStack> tryPlaceFluid(@Nonnull World world, @Nonnull EntityPlayer player, @Nonnull EnumHand hand, ItemStack itemstack, FluidStack fluidStack) { RayTraceResult mop = this.rayTrace(world, player, false); ActionResult<ItemStack> ret = ForgeEventFactory.onBucketUse(player, world, itemstack, mop); if (ret != null) return ret; if (mop == null || mop.typeOfHit != RayTraceResult.Type.BLOCK) { return ActionResult.newResult(EnumActionResult.PASS, itemstack); } BlockPos clickPos = mop.getBlockPos(); if (world.isBlockModifiable(player, clickPos)) { BlockPos targetPos = clickPos.offset(mop.sideHit); if (player.canPlayerEdit(targetPos, mop.sideHit, itemstack)) { FluidActionResult result = FluidUtil.tryPlaceFluid(player, world, targetPos, itemstack, fluidStack); if (result.isSuccess() && !player.capabilities.isCreativeMode) { player.addStat(StatList.getObjectUseStats(this)); itemstack.shrink(1); ItemStack emptyStack = new ItemStack(GTItems.testTube); if (itemstack.isEmpty()) { return ActionResult.newResult(EnumActionResult.SUCCESS, emptyStack); } else { ItemHandlerHelper.giveItemToPlayer(player, emptyStack); return ActionResult.newResult(EnumActionResult.SUCCESS, itemstack); } } } } return ActionResult.newResult(EnumActionResult.FAIL, itemstack); }
Example #21
Source File: GTTileEnergyTransmitter.java From GT-Classic with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean onRightClick(EntityPlayer player, EnumHand arg1, EnumFacing arg2, Side arg3) { ItemStack slotStack = this.getStackInSlot(0); if (slotStack.isEmpty() || !player.isSneaking()) { return false; } ItemHandlerHelper.giveItemToPlayer(player, slotStack.copy()); slotStack.shrink(1); this.targetPos = null; IC2.audioManager.playOnce(player, Ic2Sounds.wrenchUse); return true; }
Example #22
Source File: GTTileRedstoneTransmitter.java From GT-Classic with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean onRightClick(EntityPlayer player, EnumHand arg1, EnumFacing arg2, Side arg3) { ItemStack slotStack = this.getStackInSlot(0); if (slotStack.isEmpty() || !player.isSneaking()) { return false; } ItemHandlerHelper.giveItemToPlayer(player, slotStack.copy()); slotStack.shrink(1); this.onBlockBreak(); this.targetPos = null; IC2.audioManager.playOnce(player, Ic2Sounds.wrenchUse); return true; }
Example #23
Source File: CoverConveyor.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
protected int moveInventoryItems(IItemHandler sourceInventory, IItemHandler targetInventory, int maxTransferAmount) { int itemsLeftToTransfer = maxTransferAmount; for (int srcIndex = 0; srcIndex < sourceInventory.getSlots(); srcIndex++) { ItemStack sourceStack = sourceInventory.extractItem(srcIndex, itemsLeftToTransfer, true); if (sourceStack.isEmpty()) { continue; } if (!itemFilterContainer.testItemStack(sourceStack)) { continue; } ItemStack remainder = ItemHandlerHelper.insertItemStacked(targetInventory, sourceStack, true); int amountToInsert = sourceStack.getCount() - remainder.getCount(); if (amountToInsert > 0) { sourceStack = sourceInventory.extractItem(srcIndex, amountToInsert, false); if (!sourceStack.isEmpty()) { ItemHandlerHelper.insertItemStacked(targetInventory, sourceStack, false); itemsLeftToTransfer -= sourceStack.getCount(); if (itemsLeftToTransfer == 0) { break; } } } } return maxTransferAmount - itemsLeftToTransfer; }
Example #24
Source File: GTTileDisplayScreen.java From GT-Classic with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean onRightClick(EntityPlayer player, EnumHand arg1, EnumFacing arg2, Side arg3) { ItemStack slotStack = this.getStackInSlot(0); if (slotStack.isEmpty() || !player.isSneaking()) { return false; } ItemHandlerHelper.giveItemToPlayer(player, slotStack.copy()); slotStack.shrink(1); this.resetTargetPos(); IC2.audioManager.playOnce(player, Ic2Sounds.wrenchUse); return true; }
Example #25
Source File: BlockCampfirePot.java From Sakura_mod with MIT License | 5 votes |
@Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (worldIn.isRemote) { return true; } ItemStack stack = playerIn.getHeldItem(hand); TileEntity tile = worldIn.getTileEntity(pos); if (hand == EnumHand.MAIN_HAND) { if (tile instanceof TileEntityCampfirePot) { TileEntityCampfirePot tileEntityCampfire = (TileEntityCampfirePot) tile; IFluidHandlerItem handler = FluidUtil.getFluidHandler(ItemHandlerHelper.copyStackWithSize(stack, 1)); if (handler != null) { FluidUtil.interactWithFluidHandler(playerIn, hand, tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing)); return true; } if (WorldUtil.isItemFuel(stack)) { tileEntityCampfire.setBurningTime(tileEntityCampfire.getBurningTime() + TileEntityFurnace.getItemBurnTime(stack)); setState(true, worldIn, pos); if(stack.getItem().hasContainerItem(stack)) stack = stack.getItem().getContainerItem(stack); else stack.shrink(1); return true; } if (stack.getItem() == Items.FLINT_AND_STEEL) { tileEntityCampfire.setBurningTime(tileEntityCampfire.getBurningTime() + 10000); setState(true, worldIn, pos); stack.damageItem(1, playerIn); return true; } playerIn.openGui(SakuraMain.instance, SakuraGuiHandler.ID_CAMPFIREPOT, worldIn, pos.getX(), pos.getY(), pos.getZ()); return true; } } return true; }
Example #26
Source File: MetaItem.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@SideOnly(Side.CLIENT) protected int getColorForItemStack(ItemStack stack, int tintIndex) { T metaValueItem = getItem(stack); if (metaValueItem != null && metaValueItem.getColorProvider() != null) { return metaValueItem.getColorProvider().getItemStackColor(stack, tintIndex); } IFluidHandlerItem fluidContainerItem = ItemHandlerHelper.copyStackWithSize(stack, 1) .getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); if (tintIndex == 0 && fluidContainerItem != null) { FluidStack fluidStack = fluidContainerItem.drain(Integer.MAX_VALUE, false); return fluidStack == null ? 0x666666 : RenderUtil.getFluidColor(fluidStack); } return 0xFFFFFF; }
Example #27
Source File: MetaTileEntityCokeOven.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
private void finishCurrentRecipe() { this.maxProgressDuration = 0; this.currentProgress = 0; ItemHandlerHelper.insertItemStacked(exportItems, outputStack, false); this.exportFluids.fill(outputFluid, true); markDirty(); }
Example #28
Source File: MetaItem.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override @SideOnly(Side.CLIENT) public void addInformation(ItemStack itemStack, @Nullable World worldIn, List<String> lines, ITooltipFlag tooltipFlag) { T item = getItem(itemStack); if (item == null) return; String unlocalizedTooltip = "metaitem." + item.unlocalizedName + ".tooltip"; if (I18n.hasKey(unlocalizedTooltip)) { lines.addAll(Arrays.asList(I18n.format(unlocalizedTooltip).split("/n"))); } IElectricItem electricItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null); if (electricItem != null) { lines.add(I18n.format("metaitem.generic.electric_item.tooltip", electricItem.getCharge(), electricItem.getMaxCharge(), GTValues.VN[electricItem.getTier()])); } IFluidHandlerItem fluidHandler = ItemHandlerHelper.copyStackWithSize(itemStack, 1) .getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); if (fluidHandler != null) { IFluidTankProperties fluidTankProperties = fluidHandler.getTankProperties()[0]; FluidStack fluid = fluidTankProperties.getContents(); if (fluid != null) { lines.add(I18n.format("metaitem.generic.fluid_container.tooltip", fluid.amount, fluidTankProperties.getCapacity(), fluid.getLocalizedName())); } else lines.add(I18n.format("metaitem.generic.fluid_container.tooltip_empty")); } for (IItemBehaviour behaviour : getBehaviours(itemStack)) { behaviour.addInformation(itemStack, lines); } }
Example #29
Source File: MetaTileEntityItemCollector.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
protected void moveItemsInEffectRange() { List<EntityItem> itemsInRange = getWorld().getEntitiesWithinAABB(EntityItem.class, areaBoundingBox); for (EntityItem entityItem : itemsInRange) { double distanceX = (areaCenterPos.getX() + 0.5) - entityItem.posX; double distanceZ = (areaCenterPos.getZ() + 0.5) - entityItem.posZ; double distance = MathHelper.sqrt(distanceX * distanceX + distanceZ * distanceZ); if(!itemFilter.testItemStack(entityItem.getItem())) { continue; } if (distance >= 0.7) { if(!entityItem.cannotPickup()) { double directionX = distanceX / distance; double directionZ = distanceZ / distance; entityItem.motionX = directionX * MOTION_MULTIPLIER * getTier(); entityItem.motionZ = directionZ * MOTION_MULTIPLIER * getTier(); entityItem.velocityChanged = true; entityItem.setPickupDelay(1); } } else { ItemStack itemStack = entityItem.getItem(); ItemStack remainder = ItemHandlerHelper.insertItemStacked(exportItems, itemStack, false); if (remainder.isEmpty()) { entityItem.setDead(); } else if (itemStack.getCount() > remainder.getCount()) { entityItem.setItem(remainder); } } } if (getTimer() % 5 == 0) { pushItemsIntoNearbyHandlers(getFrontFacing()); } }
Example #30
Source File: MetaTileEntityBlockBreaker.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
private void addToInventoryOrDropItems(List<ItemStack> drops) { EnumFacing outputFacing = getOutputFacing(); double itemSpawnX = getPos().getX() + 0.5 + outputFacing.getFrontOffsetX(); double itemSpawnY = getPos().getX() + 0.5 + outputFacing.getFrontOffsetX(); double itemSpawnZ = getPos().getX() + 0.5 + outputFacing.getFrontOffsetX(); for(ItemStack itemStack : drops) { ItemStack remainStack = ItemHandlerHelper.insertItemStacked(exportItems, itemStack, false); if(!remainStack.isEmpty()) { EntityItem entityitem = new EntityItem(getWorld(), itemSpawnX, itemSpawnY, itemSpawnZ, remainStack); entityitem.setDefaultPickupDelay(); getWorld().spawnEntity(entityitem); } } }