@Override public boolean isItemValidForSlot(int slot, ItemStack stack) { if (!formed) return false; if (master() != null) return master().isItemValidForSlot(slot, stack); if (slot == 1 || slot == 3 || slot == 5) return false; if (slot == 4) return (tank2.getFluidAmount() <= 0 ? FluidContainerRegistry.isEmptyContainer(stack) : FluidContainerRegistry.fillFluidContainer( tank2.getFluid(), Utils.copyStackWithAmount(stack, 1)) != null); FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(stack); if (fs == null) return false; RefineryRecipe partialRecipe = DieselHandler.findIncompleteRefineryRecipe(fs, null); if (partialRecipe == null) return false; if (slot == 0) return (tank0.getFluidAmount() <= 0 || fs.isFluidEqual(tank0.getFluid())) && (tank1.getFluidAmount() <= 0 || DieselHandler.findIncompleteRefineryRecipe(fs, tank1.getFluid()) != null); if (slot == 2) return (tank1.getFluidAmount() <= 0 || fs.isFluidEqual(tank1.getFluid())) && (tank0.getFluidAmount() <= 0 || DieselHandler.findIncompleteRefineryRecipe(fs, tank0.getFluid()) != null); return false; }
private void outputActiveLava() { FluidStack fluid = tank[1].getFluid(); if (fluid != null) { if (itemStacks[2] != null && itemStacks[2].stackSize == 1) { ItemStack itemStack = itemStacks[2]; if (FluidContainerRegistry.isEmptyContainer(itemStack)) { if (fluid.amount >= FluidContainerRegistry.BUCKET_VOLUME) { FluidStack oneBucketOfFluid = new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME); ItemStack filledBucket = FluidContainerRegistry.fillFluidContainer( oneBucketOfFluid, FluidContainerRegistry.EMPTY_BUCKET); itemStacks[2] = filledBucket; fluid.amount -= FluidContainerRegistry.BUCKET_VOLUME; } } else if (itemStack.getItem() instanceof IFluidContainerItem && (workingTick % 20) == 10) { if (fluid.amount >= FluidContainerRegistry.BUCKET_VOLUME) { IFluidContainerItem fluidContainerItem = (IFluidContainerItem) itemStack.getItem(); FluidStack fluidStack = fluid.copy(); if (fluidStack.amount > FluidContainerRegistry.BUCKET_VOLUME) fluidStack.amount = FluidContainerRegistry.BUCKET_VOLUME; int amount = fluidContainerItem.fill(itemStack, fluidStack, true); if (amount > 0) { fluid.amount -= amount; } if (fluid.amount == 0) tank[1].setFluid(null); } } } } }
@Override public boolean canExtractItem(int slotID, ItemStack itemstack, int side) { if (slotID == 1) { return ChargeUtils.canBeOutputted(itemstack, true); } else if (slotID == 0) { return FluidContainerRegistry.isEmptyContainer(itemstack); } return false; }
@Override public boolean isItemValidForSlot(int slotID, ItemStack itemstack) { if (slotID == 1) { return false; } else if (slotID == 0) { return FluidContainerRegistry.isEmptyContainer(itemstack); } else if (slotID == 2) { return ChargeUtils.canBeDischarged(itemstack); } return true; }
@Override public boolean onBlockActivated( World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { if (world.isRemote) return true; TileEntityJarOHoney tile = Utils.getTileEntity(world, x, y, z, TileEntityJarOHoney.class); if (tile == null) return false; ItemStack stack = player.getCurrentEquippedItem(); if (FluidContainerRegistry.isFilledContainer(stack)) { FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(stack); if (fluidStack.isFluidEqual(tile.getHoney())) if (fluidStack.amount + tile.getHoney().amount > TileEntityJarOHoney.HONEY_MAX_AMOUNT) return true; else { tile.addHoney(fluidStack.amount); ItemStack container = stack.getItem().getContainerItem(stack); stack.stackSize--; if (stack.stackSize <= 0) player.setCurrentItemOrArmor(0, container); else if (!player.inventory.addItemStackToInventory(container)) Utils.dropStack(world, x, y, z, container); return true; } } else if (FluidContainerRegistry.isEmptyContainer(stack)) { ItemStack filledContainer = FluidContainerRegistry.fillFluidContainer(tile.getHoney(), stack); if (filledContainer != null) { stack.stackSize--; if (stack.stackSize <= 0) player.setCurrentItemOrArmor(0, filledContainer); else if (!player.inventory.addItemStackToInventory(filledContainer)) Utils.dropStack(world, x, y, z, filledContainer); tile.drainHoney(FluidContainerRegistry.getFluidForFilledItem(filledContainer).amount); return true; } } else { player.getFoodStats().addStats(1, 0.8F); player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 100, 1)); tile.drainHoney(100); } return false; }
public static ItemStack fillFluidContainer(FluidTank tank, ItemStack containerIn) { if (tank.getFluidAmount() > 0) if (FluidContainerRegistry.isEmptyContainer(containerIn)) { ItemStack filledContainer = FluidContainerRegistry.fillFluidContainer(tank.getFluid(), containerIn); if (filledContainer != null) { FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(filledContainer); if (fs.amount <= tank.getFluidAmount()) { tank.drain(fs.amount, true); return filledContainer; } } } return null; }
public ItemStack removeLiquid(ItemStack is) { if (is == null) return is; if (FluidContainerRegistry.isEmptyContainer(is)) { ItemStack out = FluidContainerRegistry.fillFluidContainer(fluid, is); if (out != null) { FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(out); fluid.amount -= fs.amount; is = null; if (fluid.amount == 0) { fluid = null; } worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); return out; } } return is; }
public static boolean fillPlayerItemFromFluidHandler( World world, IFluidHandler handler, EntityPlayer player, FluidStack tankFluid) { ItemStack equipped = player.getCurrentEquippedItem(); if (equipped == null) return false; if (FluidContainerRegistry.isEmptyContainer(equipped)) { ItemStack filledStack = FluidContainerRegistry.fillFluidContainer(tankFluid, equipped); FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(filledStack); if (fluid == null || filledStack == null) return false; if (!player.capabilities.isCreativeMode) if (equipped.stackSize == 1) { player.inventory.setInventorySlotContents(player.inventory.currentItem, filledStack); equipped.stackSize -= 1; if (equipped.stackSize <= 0) equipped = null; } else { if (equipped.stackSize == 1) { player.inventory.setInventorySlotContents(player.inventory.currentItem, null); player.inventory.addItemStackToInventory(filledStack); } else { equipped.stackSize -= 1; if (filledStack != null && !player.inventory.addItemStackToInventory(filledStack)) player.func_146097_a(filledStack, false, true); } player.openContainer.detectAndSendChanges(); ((EntityPlayerMP) player) .sendContainerAndContentsToPlayer( player.openContainer, player.openContainer.getInventory()); } handler.drain(ForgeDirection.UNKNOWN, fluid.amount, true); return true; } else if (equipped.getItem() instanceof IFluidContainerItem) { IFluidContainerItem container = (IFluidContainerItem) equipped.getItem(); if (container.fill(equipped, tankFluid, false) > 0) { int fill = container.fill(equipped, tankFluid, true); handler.drain(ForgeDirection.UNKNOWN, fill, true); player.openContainer.detectAndSendChanges(); ((EntityPlayerMP) player) .sendContainerAndContentsToPlayer( player.openContainer, player.openContainer.getInventory()); return true; } } return false; }
public static ItemStack fillFluidContainer( FluidTank tank, ItemStack containerIn, ItemStack containerOut) { if (tank.getFluidAmount() > 0 && containerIn != null) { if (FluidContainerRegistry.isEmptyContainer(containerIn)) { ItemStack filledContainer = FluidContainerRegistry.fillFluidContainer(tank.getFluid(), containerIn); if (filledContainer != null) { FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(filledContainer); if (fs.amount <= tank.getFluidAmount() && (containerOut == null || OreDictionary.itemMatches(containerOut, filledContainer, true))) { tank.drain(fs.amount, true); return filledContainer; } } } else if (containerIn.getItem() instanceof IFluidContainerItem) { IFluidContainerItem iContainer = (IFluidContainerItem) containerIn.getItem(); int available = tank.getFluidAmount(); int space = iContainer.getCapacity(containerIn) - (iContainer.getFluid(containerIn) == null ? 0 : iContainer.getFluid(containerIn).amount); if (available >= space && iContainer.fill(containerIn, tank.getFluid(), false) == space) // Fill in one go { ItemStack filledContainer = copyStackWithAmount(containerIn, 1); int filled = iContainer.fill(filledContainer, tank.getFluid(), true); if (containerOut == null || (OreDictionary.itemMatches(containerOut, filledContainer, true) && ItemStack.areItemStackTagsEqual(filledContainer, containerOut))) { tank.drain(filled, true); return filledContainer; } } else { int filled = iContainer.fill(containerIn, tank.getFluid(), true); tank.drain(filled, true); } } } return null; }
@Override public void updateEntity() { if (!worldObj.isRemote) { careForInventorySlot(); if (worldObj.isRaining() && !this.getSealed() && worldObj.canBlockSeeTheSky(xCoord, yCoord, zCoord)) { if (this.fluid == null) fluid = new FluidStack(TFCFluid.FRESHWATER, 1); else if (this.fluid != null && fluid.getFluid() == TFCFluid.FRESHWATER) fluid.amount = Math.min(fluid.amount + 1, 10000); } processTimer++; if (processTimer > 100) { ProcessItems(); processTimer = 0; } if (fluid != null && fluid.amount == 0) fluid = null; if (mode == MODE_IN) { FluidStack inLiquid = FluidContainerRegistry.getFluidForFilledItem(getInputStack()); if (inLiquid != null) { if (this.fluid == null) { this.fluid = inLiquid.copy(); this.setInventorySlotContents( 0, getInputStack().getItem().getContainerItem(getInputStack())); } else if (inLiquid.isFluidEqual(this.fluid)) { if (addLiquid(inLiquid.amount)) { this.setInventorySlotContents( 0, getInputStack().getItem().getContainerItem(getInputStack())); } } } } else if (mode == MODE_OUT) { if (FluidContainerRegistry.isEmptyContainer(getInputStack())) { this.setInventorySlotContents(0, this.removeLiquid(getInputStack())); } } } }
/** * This attempts to remove a portion of the water in this container and put it into a valid * Container Item */ public ItemStack removeLiquid(ItemStack is) { if (is == null || is.stackSize > 1) return is; if (FluidContainerRegistry.isEmptyContainer(is)) { ItemStack out = FluidContainerRegistry.fillFluidContainer(fluid, is); if (out != null) { FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(out); fluid.amount -= fs.amount; is = null; if (fluid.amount == 0) { fluid = null; } worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); return out; } } else if (fluid != null && is.getItem() instanceof IFluidContainerItem) { FluidStack isfs = ((IFluidContainerItem) is.getItem()).getFluid(is); if (isfs == null || fluid.isFluidEqual(isfs)) { fluid.amount -= ((IFluidContainerItem) is.getItem()).fill(is, fluid, true); if (fluid.amount == 0) fluid = null; worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } } return is; }
@Override public ItemStack transferStackInSlot(EntityPlayer player, int slotID) { ItemStack stack = null; Slot currentSlot = (Slot) inventorySlots.get(slotID); if (currentSlot != null && currentSlot.getHasStack()) { ItemStack slotStack = currentSlot.getStack(); stack = slotStack.copy(); if (ChargeUtils.canBeDischarged(slotStack)) { if (slotID != 4) { if (!mergeItemStack(slotStack, 4, 5, false)) { return null; } } else { if (!mergeItemStack(slotStack, 5, inventorySlots.size(), true)) { return null; } } } else if (FluidContainerRegistry.isEmptyContainer(slotStack) || FluidContainerRegistry.isFilledContainer(slotStack)) { if (slotID != 2 && slotID != 3) { if (!mergeItemStack(slotStack, 2, 3, false)) { return null; } } else { if (!mergeItemStack(slotStack, 5, inventorySlots.size(), true)) { return null; } } } else if (slotStack.getItem() instanceof IGasItem) { if (slotID != 0 && slotID != 1) { if (((IGasItem) slotStack.getItem()) .canProvideGas( slotStack, tileEntity.gasTank.getGas() != null ? tileEntity.gasTank.getGas().getGas() : null)) { if (!mergeItemStack(slotStack, 0, 1, false)) { return null; } } else if (((IGasItem) slotStack.getItem()) .canReceiveGas( slotStack, tileEntity.gasTank.getGas() != null ? tileEntity.gasTank.getGas().getGas() : null)) { if (!mergeItemStack(slotStack, 1, 2, false)) { return null; } } } else { if (!mergeItemStack(slotStack, 5, inventorySlots.size(), true)) { return null; } } } else { if (slotID >= 5 && slotID <= 31) { if (!mergeItemStack(slotStack, 32, inventorySlots.size(), false)) { return null; } } else if (slotID > 31) { if (!mergeItemStack(slotStack, 5, 31, false)) { return null; } } else { if (!mergeItemStack(slotStack, 5, inventorySlots.size(), true)) { return null; } } } if (slotStack.stackSize == 0) { currentSlot.putStack((ItemStack) null); } else { currentSlot.onSlotChanged(); } if (slotStack.stackSize == stack.stackSize) { return null; } currentSlot.onPickupFromSlot(player, slotStack); } return stack; }
@Override public void onUpdate() { ChargeUtils.discharge(2, this); if (inventory[0] != null) { if (fluidTank.getFluid() != null && fluidTank.getFluid().amount >= FluidContainerRegistry.BUCKET_VOLUME) { if (FluidContainerRegistry.isEmptyContainer(inventory[0])) { ItemStack tempStack = FluidContainerRegistry.fillFluidContainer(fluidTank.getFluid(), inventory[0]); if (tempStack != null) { if (inventory[1] == null) { fluidTank.drain(FluidContainerRegistry.BUCKET_VOLUME, true); inventory[1] = tempStack; inventory[0].stackSize--; if (inventory[0].stackSize <= 0) { inventory[0] = null; } } else if (tempStack.isItemEqual(inventory[1]) && tempStack.getMaxStackSize() > inventory[1].stackSize) { fluidTank.drain(FluidContainerRegistry.BUCKET_VOLUME, true); inventory[1].stackSize++; inventory[0].stackSize--; if (inventory[0].stackSize <= 0) { inventory[0] = null; } } } } } } if (!worldObj.isRemote && worldObj.getWorldTime() % 20 == 0) { if (getEnergy() >= 100 && (fluidTank.getFluid() == null || fluidTank.getFluid().amount + FluidContainerRegistry.BUCKET_VOLUME <= 10000)) { if (suck(true)) { PacketHandler.sendPacket( Transmission.CLIENTS_RANGE, new PacketTileEntity() .setParams(Object3D.get(this), getNetworkedData(new ArrayList())), Object3D.get(this), 50D); } clean(true); } } super.onUpdate(); if (fluidTank.getFluid() != null) { for (ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS) { TileEntity tileEntity = Object3D.get(this).getFromSide(orientation).getTileEntity(worldObj); if (tileEntity instanceof IFluidHandler) { FluidStack toDrain = new FluidStack(fluidTank.getFluid(), Math.min(100, fluidTank.getFluidAmount())); fluidTank.drain( ((IFluidHandler) tileEntity).fill(orientation.getOpposite(), toDrain, true), true); if (fluidTank.getFluid() == null || fluidTank.getFluid().amount <= 0) { break; } } } } }
@Override public void updateEntity() { if (!worldObj.isRemote) { ItemStack itemstack = storage[INPUT_SLOT]; BarrelPreservativeRecipe preservative = BarrelManager.getInstance() .findMatchingPreservativeRepice(this, itemstack, fluid, sealed); if (itemstack != null && fluid != null && fluid.getFluid() == TFCFluids.FRESHWATER) { if (TFC_ItemHeat.hasTemp(itemstack)) { float temp = TFC_ItemHeat.getTemp(itemstack); if (fluid.amount >= 1 && temp > 1) { temp -= 50; fluid.amount -= 1; TFC_ItemHeat.setTemp(itemstack, temp); TFC_ItemHeat.handleItemHeat(itemstack); } } } if (fluid != null && itemstack != null && itemstack.getItem() instanceof IFood) { float w = ((IFood) itemstack.getItem()).getFoodWeight(itemstack); if (fluid.getFluid() == TFCFluids.VINEGAR) { // If the food is brined then we attempt to pickle it if (Food.isBrined(itemstack) && !Food.isPickled(itemstack) && w / fluid.amount <= Global.FOOD_MAX_WEIGHT / this.getMaxLiquid() && this.getSealed() && sealtime != 0 && TFC_Time.getTotalHours() - sealtime >= 4) { fluid.amount -= 1 * w; Food.setPickled(itemstack, true); } } } if (preservative == null) { // No preservative was matched - decay normally TFC_Core.handleItemTicking(this, this.worldObj, xCoord, yCoord, zCoord); } else { float env = preservative.getEnvironmentalDecayFactor(); float base = preservative.getBaseDecayModifier(); if (Float.isNaN(env) || env < 0.0) { TFC_Core.handleItemTicking(this, this.worldObj, xCoord, yCoord, zCoord); } else if (Float.isNaN(base) || base < 0.0) { TFC_Core.handleItemTicking(this, this.worldObj, xCoord, yCoord, zCoord, env); } else { TFC_Core.handleItemTicking(this, this.worldObj, xCoord, yCoord, zCoord, env, base); } } // If lightning can strike here then it means that the barrel can see the sky, so rain can hit // it. If true then we fill // the barrel when its raining. if (!this.getSealed() && worldObj.canLightningStrikeAt(xCoord, yCoord + 1, zCoord)) { int count = getInvCount(); if (count == 0 || count == 1 && this.getInputStack() != null) { if (this.fluid == null) fluid = new FluidStack(TFCFluids.FRESHWATER, 1); else if (this.fluid != null && fluid.getFluid() == TFCFluids.FRESHWATER) fluid.amount = Math.min(fluid.amount + 1, getMaxLiquid()); } } // We only want to bother ticking food once per 5 seconds to keep overhead low. processTimer++; if (processTimer > 100) { processItems(); processTimer = 0; } // Here we handle item stacks that are too big for MC to handle such as when making mortar. // If the stack is > its own max stack size then we split it and add it to the invisible solid // storage area or // spawn the item in the world if there is no room left. if (this.getFluidLevel() > 0 && getInputStack() != null) { int count = 1; while (this.getInputStack().stackSize > getInputStack().getMaxStackSize()) { ItemStack is = getInputStack().splitStack(getInputStack().getMaxStackSize()); if (count < this.storage.length && this.getStackInSlot(count) == null) { this.setInventorySlotContents(count, is); } else { worldObj.spawnEntityInWorld(new EntityItem(worldObj, xCoord, yCoord, zCoord, is)); } count++; } } // Move any items in the solid storage slots to the main slot if they exist and the barrel has // liquid. else if (this.getFluidLevel() > 0 && getInputStack() == null && this.getInvCount() > 0) { for (int i = 0; i < storage.length; i++) { if (storage[i] != null) { storage[INPUT_SLOT] = storage[i].copy(); storage[i] = null; break; } } } // Reset our fluid if all of the liquid is gone. if (fluid != null && fluid.amount == 0) fluid = null; // Handle adding fluids to the barrel if the barrel is currently in input mode. if (mode == MODE_IN) { ItemStack container = getInputStack(); FluidStack inLiquid = FluidContainerRegistry.getFluidForFilledItem(container); if (container != null && container.getItem() instanceof IFluidContainerItem) { FluidStack isfs = ((IFluidContainerItem) container.getItem()).getFluid(container); if (isfs != null && addLiquid(isfs)) { ((IFluidContainerItem) container.getItem()) .drain( container, ((IFluidContainerItem) container.getItem()).getCapacity(container), true); } } else if (inLiquid != null && container != null && container.stackSize == 1) { if (addLiquid(inLiquid)) { this.setInventorySlotContents(0, FluidContainerRegistry.drainFluidContainer(container)); } } } // Drain liquid from the barrel to a container if the barrel is in output mode. else if (mode == MODE_OUT) { ItemStack container = getInputStack(); if (container != null && fluid != null && container.getItem() instanceof IFluidContainerItem) { FluidStack isfs = ((IFluidContainerItem) container.getItem()).getFluid(container); if (isfs == null || fluid.isFluidEqual(isfs)) { fluid.amount -= ((IFluidContainerItem) container.getItem()).fill(container, fluid, true); if (fluid.amount == 0) fluid = null; } } else if (FluidContainerRegistry.isEmptyContainer(container)) { this.setInventorySlotContents(0, this.removeLiquid(getInputStack())); } } } }