@Override public void render(TileEntityPlasticMixer te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) { IFluidTank tank = te.getTank(); if (tank.getFluidAmount() == 0) return; GlStateManager.pushMatrix(); GlStateManager.translate(x, y, z); GlStateManager.enableBlend(); GlStateManager.disableAlpha(); GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); AxisAlignedBB bounds = getRenderBounds(tank); PneumaticCraftUtils.renderFluid(tank.getFluid().getFluid(), bounds); GlStateManager.disableBlend(); GlStateManager.enableAlpha(); GlStateManager.popMatrix(); }
protected void readCapabilities(NBTTagCompound nbt, @Nullable EnumFacing side){ IItemHandler inventory = this.getInventory(side); if(inventory != null && inventory instanceof IItemHandlerModifiable && nbt.hasKey("Inventory")){ for(int i = 0; i < inventory.getSlots(); i++){ // clear the inventory, otherwise empty stacks doesn't get overriden while syncing. Forge Bug? ((IItemHandlerModifiable) inventory).setStackInSlot(i, ItemStack.EMPTY); } CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(inventory, side, nbt.getTag("Inventory")); } IFluidHandler tank = getTank(side); if(tank != null && tank instanceof IFluidTank && nbt.hasKey("FluidTank")){ CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.readNBT(tank, side, nbt.getCompoundTag("FluidTank")); } IEnergyStorage energy = getEnergy(side); if(energy != null && energy instanceof EnergyStorage && nbt.hasKey("Energy")){ CapabilityEnergy.ENERGY.readNBT(energy, side, nbt.getTag("Energy")); } }
public static void extractFluidsFromTanks(List<IFluidTank> tanks, List<FluidStack> fluids) { LinkedList<IFluidTank> remaining = Lists.newLinkedList(tanks); for (FluidStack stack : fluids) { for (Iterator<IFluidTank> iterator = remaining.iterator(); iterator.hasNext(); ) { IFluidTank tank = iterator.next(); if (tank.getFluid() != null && tank.getFluid().getFluid().getName().equals(stack.getFluid().getName())) { FluidStack drained = tank.drain(stack.amount, false); if (drained != null && drained.amount == stack.amount) { tank.drain(stack.amount, true); iterator.remove(); break; } } } } }
@Nullable @Override public IFluidTank getFluidTank(String name) { String moduleName; String sourceName; TileEntityModule module; if (name.contains(":")) { String[] split = name.split(":"); moduleName = split[0]; sourceName = split[1]; } else { moduleName = name; sourceName = name; } module = modules.get(moduleName); if (module instanceof FluidSource) return ((FluidSource) module).getFluidTank(sourceName); return null; }
@Override @Nonnull public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) { ItemStack result = new ItemStack(this); TileEntityTank tile = getTileEntity(world, pos, TileEntityTank.class); if (tile != null) { IFluidTank tank = tile.getTank(); if (tank.getFluidAmount() > 0) { NBTTagCompound tankTag = tile.getItemNBT(); if (tankTag.hasKey("Amount")) tankTag.setInteger("Amount", tank.getCapacity()); NBTTagCompound nbt = ItemUtils.getItemTag(result); nbt.setTag("tank", tankTag); } } return result; }
static AxisAlignedBB getRenderBounds(IFluidTank tank, AxisAlignedBB tankBounds) { float percent = (float) tank.getFluidAmount() / (float) tank.getCapacity(); double tankHeight = tankBounds.maxY - tankBounds.minY; double y1 = tankBounds.minY, y2 = (tankBounds.minY + (tankHeight * percent)); if (tank.getFluid().getFluid().getDensity() < 0) { double yOff = tankBounds.maxY - y2; // lighter than air fluids move to the top of the tank y1 += yOff; y2 += yOff; } return new AxisAlignedBB(tankBounds.minX, y1, tankBounds.minZ, tankBounds.maxX, y2, tankBounds.maxZ); }
@Override public void actionPerformed(IGuiWidget widget) { super.actionPerformed(widget); if (widget instanceof WidgetFluidStack) { boolean leftClick = Mouse.isButtonDown(0); boolean middleClick = Mouse.isButtonDown(2); boolean shift = PneumaticCraftRepressurized.proxy.isSneakingInGui(); IFluidTank tank = logistics.getTankFilter(widget.getID()); if (tank.getFluidAmount() > 0) { if (middleClick) { logistics.setFilter(widget.getID(), null); } else if (leftClick) { tank.drain(shift ? tank.getFluidAmount() / 2 : 1000, true); if (tank.getFluidAmount() < 1000) { tank.drain(1000, true); } } else { tank.fill(new FluidStack(tank.getFluid().getFluid(), shift ? tank.getFluidAmount() : 1000), true); } NetworkHandler.sendToServer(new PacketSetLogisticsFluidFilterStack(logistics, tank.getFluid(), widget.getID())); } else { fluidSearchGui = new GuiLogisticsLiquidFilter(this); editingSlot = widget.getID(); mc.displayGuiScreen(fluidSearchGui); } } }
protected void writeCapabilities(NBTTagCompound nbt, @Nullable EnumFacing side){ IItemHandler inventory = this.getInventory(side); if(inventory != null && inventory instanceof IItemHandlerModifiable){ nbt.setTag("Inventory", CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.writeNBT(inventory, side)); } IFluidHandler tank = getTank(side); if(tank != null && tank instanceof IFluidTank){ nbt.setTag("FluidTank", CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.writeNBT(tank, side)); } IEnergyStorage energy = getEnergy(side); if(energy != null && energy instanceof EnergyStorage){ nbt.setTag("Energy", CapabilityEnergy.ENERGY.writeNBT(energy, side)); } }
private void extractInputFluids(MachineRecipe recipe) { List<IFluidTank> remaining = Arrays.stream(supplier.inputTanks) .map(fluidSource::getFluidTank) .collect(Collectors.toCollection(LinkedList::new)); ItemHelper.extractFluidsFromTanks(remaining, recipe.getFluidRecipeInput()); }
private MachineRecipe getActiveRecipe() { NonNullList<ItemStack> input = invHandler.getInputStacks(); List<FluidStack> inputFluid = Arrays.stream(supplier.inputTanks) .map(fluidSource::getFluidTank) .map(IFluidTank::getFluid) .collect(Collectors.toList()); return MachineManager.findMatchingRecipe(supplier.recipeList, input, inputFluid, tile.getWorld()); }
@Override public void detectAndSendChanges() { super.detectAndSendChanges(); for (int i = 0; i < tanks.size(); i++) { IFluidTank tank = tanks.get(i); FluidStack prev = fluidStacks.get(i); FluidStack current = tank.getFluid(); if (!ItemHelper.fluidStackEqual(prev, current)) { PacketSyncContainerFluid packet = new PacketSyncContainerFluid(windowId, i, current); for (IContainerListener listener : listeners) { if (listener instanceof EntityPlayerMP) { EntityPlayerMP player = (EntityPlayerMP) listener; CustomStuff4.network.sendTo(packet, player); } } fluidStacks.set(i, current == null ? null : current.copy()); } } }
@Override public void update() { if (hasFuel()) { ItemStack melt = inventory.getStackInSlot(0); MeltingRecipe recipe = MelteryHandler.getMelteryRecipe(melt); if (recipe != null) { if (progress > recipe.getUsableTemperature()) { FluidStack fluidStack = recipe.getResult(); if ((tank.getCapacity() - tank.getFluidAmount()) >= tank.fill(fluidStack, false)) { tank.fill(fluidStack, true); world.playSound(null, pos, SoundEvents.ITEM_BUCKET_FILL_LAVA, SoundCategory.BLOCKS, 1.0f, 0.75f); melt.shrink(1); } else { world.playSound(null, pos, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 1.0f, 0.75f); } setProgress(0); } incrementProcress(); } } if(tank.getFluidAmount() > 0) { for (EnumFacing facing : EnumFacing.HORIZONTALS) { BlockPos side = pos.offset(facing); if (!world.isAirBlock(side)) { if (world.getTileEntity(side) != null) { TileEntity tile = world.getTileEntity(side); if (!(tile instanceof TileMeltery) && tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite())) { IFluidHandler fluidHandler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite()); if (fluidHandler instanceof IFluidTank) { FluidUtil.tryFluidTransfer(fluidHandler, tank, 140, true); } } } } } } }
public void drawFluidTank(IFluidTank tank, int x, int y) { FluidStack fluid = tank.getFluid(); TextureManager manager = Minecraft.getMinecraft().renderEngine; if (fluid != null) { manager.bindTexture(manager.getResourceLocation(0)); float amount = fluid.amount; float capacity = tank.getCapacity(); float scale = amount / capacity; int fluidTankHeight = 60; int fluidAmount = (int) (scale * fluidTankHeight); drawFluid(x, y + fluidTankHeight - fluidAmount, fluid.getFluid().getIcon(fluid), 16, fluidAmount); } }
public void updateConnections() { ticksSinceLastConnectionUpdate = 0; connectedNorth = false; connectedSouth = false; connectedEast = false; connectedWest = false; connectedDown = false; connectedUp = false; for (EnumFacing e : EnumFacing.VALUES) { if (this.world.getTileEntity(this.pos.offset(e)) instanceof IFluidTank) { // LogHelper.info("Connection point found to the : " + e.toString()); switch (e) { case NORTH: connectedNorth = true; break; case SOUTH: connectedSouth = true; break; case EAST: connectedEast = true; break; case WEST: connectedWest = true; break; case UP: connectedUp = true; break; case DOWN: connectedDown = true; break; } } } }
public FluidTankInfo[] getFluidTankInfo(ITankManager manager) { Object[] tanks = manager.getTanks(); List<FluidTankInfo> infos = new ArrayList<FluidTankInfo>(); for(int slot : availableSlots) { if(slot <= tanks.length-1 && tanks[slot] instanceof IFluidTank) { infos.add(((IFluidTank)tanks[slot]).getInfo()); } } return infos.toArray(new FluidTankInfo[] {}); }
@Override public boolean isValidInventory(BlockPos pos) { if (worldObj.getTileEntity(pos) != null) { return worldObj.getTileEntity(pos) instanceof IFluidHandler || worldObj.getTileEntity(pos) instanceof IFluidTank || worldObj.getTileEntity(pos) instanceof IFluidBlock || worldObj.getTileEntity(pos) instanceof IFluidContainerItem; } else { return false; } }
/** * Gets all the pipe connections at the specified location * @param world the world * @param x the x position * @param y the y position * @param z the z position * @param type the type of the pipe * @return all the pipe connections at the specified location */ public static List<ForgeDirection> getConnections(IBlockAccess world, int x, int y, int z, PipeType type) { List<ForgeDirection> connections = new ArrayList<ForgeDirection>(); Location location = new Location(world, x, y, z); // Loop Through All Valid Directions for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { // Get a location based on the current direction Location dirLoc = location.getFromDirection(direction); if (dirLoc.getTile() != null) { if (dirLoc.getTile() instanceof IPipe) { // If it's a pipe of the same type then connect IPipe pipe = (IPipe)dirLoc.getTile(); if (pipe.getType() == type) { connections.add(direction); } } else if (dirLoc.getTile() instanceof IInventory && type == PipeType.ITEM) { // If it's an inventory and it's the item type then connect connections.add(direction); } else if ((dirLoc.getTile() instanceof IFluidTank || dirLoc.getTile() instanceof IFluidHandler) && type == PipeType.FLUID) { // If it's a fluid related inventory and the pipe type is fluid then connect connections.add(direction); } } } return connections; }
@Override public void actionPerformed(IGuiWidget widget){ super.actionPerformed(widget); if(widget instanceof WidgetFluidStack) { boolean leftClick = Mouse.isButtonDown(0); boolean middleClick = Mouse.isButtonDown(2); boolean shift = PneumaticCraft.proxy.isSneakingInGui(); IFluidTank tank = logistics.getTankFilter(widget.getID()); if(tank.getFluidAmount() > 0) { if(middleClick) { logistics.setFilter(widget.getID(), (FluidStack)null); } else if(leftClick) { tank.drain(shift ? tank.getFluidAmount() / 2 : 1000, true); if(tank.getFluidAmount() < 1000) { tank.drain(1000, true); } } else { tank.fill(new FluidStack(tank.getFluid().getFluid(), shift ? tank.getFluidAmount() : 1000), true); } NetworkHandler.sendToServer(new PacketSetLogisticsFluidFilterStack(logistics, tank.getFluid(), widget.getID())); } else { fluidSearchGui = new GuiLogisticsLiquidFilter(this); editingSlot = widget.getID(); mc.displayGuiScreen(fluidSearchGui); } } }
public IFluidTank readFromNBT(@Nonnull NBTTagCompound nbt) { if(!nbt.hasKey("emptyTank")) { FluidStack liquid = FluidStack.loadFluidStackFromNBT(nbt); if(liquid != null) { setLiquid(liquid); } } return this; }
public static @Nonnull String MB(IFluidTank tank) { if (tank == null) { return MB(0, 0); } FluidStack fluid = tank.getFluid(); if (fluid != null) { return MB(fluid, tank.getCapacity()); } return MB(tank.getFluidAmount(), tank.getCapacity()); }
public WidgetFluidTank(IFluidTank tank, int posX, int posY, ForgeDirection direction) { this.tank = tank; this.posX = posX; this.posY = posY; this.direction = direction; }
private AxisAlignedBB getRenderBounds(IFluidTank tank) { return TankRenderHelper.getRenderBounds(tank, TANK_BOUNDS); }
public WidgetTank(int id, int x, int y, IFluidTank tank) { super(id, x, y, 16, 64); this.tank = tank; }
public WidgetFluidStack(int id, int x, int y, IFluidTank tank) { super(id, x, y); this.tank = tank; }
@Override public IFluidTank getTank() { return tank; }
public IFluidTank getTank() { return tank; }
public IFluidTank getTankFilter(int filterIndex) { return fluidFilters[filterIndex]; }
public IFluidTank getFluidTank() { return fluidTank; }
@Nullable @Override public IFluidTank getFluidTank(String name) { return tank; }
protected void addTank(IFluidTank tank) { tanks.add(tank); fluidStacks.add(null); }
public void putFluidInTank(int tankId, @Nullable FluidStack fluid) { IFluidTank tank = tanks.get(tankId); tank.drain(Integer.MAX_VALUE, true); tank.fill(fluid, true); }
public GuiContainerPressureCooker(InventoryPlayer playerInventory, TileEntity entity) { super(new ContainerPressureCooker(playerInventory, entity)); this.playerInventory = playerInventory; this.handler = (IItemHandlerModifiable) entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); this.fluidTank = (IFluidTank) entity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); }
public GuiContainerDrinkMachine(InventoryPlayer playerInventory, TileEntity entity) { super(new ContainerDrinkMachine(playerInventory, entity)); this.playerInventory = playerInventory; this.handler = (IItemHandlerModifiable) entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); this.fluidTank = (IFluidTank) entity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); }
protected void addFluidTank(IFluidTank fluidTank, int x, int y, int width, int height) { this.fluidtanks.add(Pair.of(fluidTank, new GuiSpace(x, y, width, height))); }
public WidgetFluidStack(int id, int x, int y, IFluidTank tank){ super(id, x, y); this.tank = tank; }