Posted May 31, 20178 yr Hey guys, so i'm working on creating a machine that has 2 FluidTanks 1 for water, and 1 for lava, but im running into a little problem: https://gyazo.com/2941bbccab4a2d50d42a0e74f25c4955 thats basically what's happening, and im not sure how to solve it, so i was wondering if one of you guys could help, here's my code: Block onActivated: @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing enumFacing, float side, float hitX, float hitY) { if(!world.isRemote) { ItemStack heldItem = player.getHeldItem(hand); Item item = heldItem.getItem(); final TileEntityOriginator originator = (TileEntityOriginator) world.getTileEntity(pos); IFluidHandler waterHandler = originator.waterTank; IFluidHandler lavaHandler = originator.lavaTank; if (originator != null && !player.isSneaking() && item != Items.LAVA_BUCKET && item != Items.WATER_BUCKET) { player.openGui(TechExpansion.instance, GuiHandler.GUI_ORIGINATOR, world, pos.getX(), pos.getY(), pos.getZ()); } else { if (item == Items.WATER_BUCKET) { FluidActionResult res = FluidUtil.interactWithFluidHandler(heldItem, waterHandler, player); if (res.isSuccess()) { player.setHeldItem(hand, res.getResult()); } } else if (item == Items.LAVA_BUCKET) { FluidActionResult res1 = FluidUtil.interactWithFluidHandler(heldItem, lavaHandler, player); if (res1.isSuccess()) { player.setHeldItem(hand, res1.getResult()); } } } } return true; } TileEntity: public class TileEntityOriginator extends TileEntityInventory { public static FluidTank waterTank; public static FluidTank lavaTank; public static final int SIZE = 3; public int cookTime; public int totalCookTime; public TileEntityOriginator() { super(SIZE); waterTank = new FluidTank(10000); lavaTank = new FluidTank(10000); } @Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); nbt.setInteger("CookTime", (short)this.cookTime); nbt.setInteger("TotalCookTime", this.totalCookTime); waterTank.writeToNBT(nbt); lavaTank.writeToNBT(nbt); return super.writeToNBT(nbt); } @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); this.cookTime = nbt.getInteger("CookTime"); this.totalCookTime = nbt.getInteger("TotalCookTime"); waterTank.readFromNBT(nbt); lavaTank.readFromNBT(nbt); } @Override public void update() { } public int getCookTime() { return 100; } @Override public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) { return this.getCapability(capability, facing) != null; } @Nullable @Override public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) { if(capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) { if(facing == EnumFacing.UP) { return (T) waterTank; } if(facing == EnumFacing.DOWN) { return (T) lavaTank; } } return super.getCapability(capability, facing); } } and my GUI: @Override public void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { mc.getTextureManager().bindTexture(Originator); drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); renderFluid(); if (this.isPointInRegion(8, 5, 19, 69, mouseX, mouseY)) { List<String> water = new ArrayList<String>(); water.add(originator.waterTank.getFluidAmount() + " / " + originator.waterTank.getCapacity() + " MB"); GuiUtils.drawHoveringText(water, mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.fontRenderer); } if (this.isPointInRegion(148, 5, 19, 69, mouseX, mouseY)) { List<String> lava = new ArrayList<String>(); lava.add(originator.lavaTank.getFluidAmount() + " / " + originator.lavaTank.getCapacity() + " MB"); GuiUtils.drawHoveringText(lava, mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.fontRenderer); } } public void renderFluid() { GlStateManager.pushMatrix(); GlStateManager.enableBlend(); final Minecraft mc = Minecraft.getMinecraft(); final Tessellator tessellator = Tessellator.getInstance(); final VertexBuffer buffer = tessellator.getBuffer(); buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); mc.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); setupRenderState(); if (originator.waterTank != null && originator.waterTank.getFluidAmount() > 0) { final int color = originator.waterTank.getFluid().getFluid().getColor(); int i = originator.waterTank.getFluidAmount() * 65 / originator.waterTank.getCapacity(); final TextureAtlasSprite still = mc.getTextureMapBlocks().getTextureExtry(originator.waterTank.getFluid().getFluid().getStill().toString()); addTexturedQuad(buffer, still, guiLeft + 10, guiTop + 7, 15, i, color); } if (originator.lavaTank != null && originator.lavaTank.getFluidAmount() > 0) { final int color = originator.lavaTank.getFluid().getFluid().getColor(); int i = originator.lavaTank.getFluidAmount() * 65 / originator.lavaTank.getCapacity(); final TextureAtlasSprite lavaStill = mc.getTextureMapBlocks().getTextureExtry(originator.lavaTank.getFluid().getFluid().getStill().toString()); addTexturedQuad(buffer, lavaStill, guiLeft + 150, guiTop + 7, 15, i, color); } tessellator.draw(); cleanupRenderState(); GlStateManager.disableBlend(); GlStateManager.popMatrix(); } public static void setupRenderState() { GlStateManager.pushMatrix(); RenderHelper.disableStandardItemLighting(); GlStateManager.enableBlend(); GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); if (Minecraft.isAmbientOcclusionEnabled()) { GL11.glShadeModel(GL11.GL_SMOOTH); } else { GL11.glShadeModel(GL11.GL_FLAT); } } public static void addTexturedQuad(VertexBuffer buffer, TextureAtlasSprite sprite, double x, double y, double width, double height, int color) { if (sprite == null) { return; } final int alpha = color >> 24 & 0xFF; final int red = color >> 16 & 0xFF; final int green = color >> 8 & 0xFF; final int blue = color & 0xFF; addTextureQuad(buffer, sprite, x, y, width, height, red, green, blue, alpha); } public static void addTextureQuad(VertexBuffer buffer, TextureAtlasSprite sprite, double x, double y, double width, double height, int red, int green, int blue, int alpha) { double minU; double maxU; double minV; double maxV; final double size = 16f; final double x2 = x + width; final double y2 = y + height; final double u = x % 1d; double u1 = u + width; while (u1 > 1f) { u1 -= 1f; } final double vy = y % 1d; double vy1 = vy + height; while (vy1 > 1f) { vy1 -= 1f; } minU = sprite.getMinU(); maxU = sprite.getMaxU(); minV = sprite.getMinV(); maxV = sprite.getMaxV(); buffer.pos(x, y, 0).color(red, green, blue, alpha).tex(minU, maxV).endVertex(); buffer.pos(x, y2, 0).color(red, green, blue, alpha).tex(minU, minV).endVertex(); buffer.pos(x2, y2, 0).color(red, green, blue, alpha).tex(maxU, minV).endVertex(); buffer.pos(x2, y, 0).color(red, green, blue, alpha).tex(maxU, maxV).endVertex(); } public static void cleanupRenderState() { GlStateManager.disableBlend(); GlStateManager.popMatrix(); RenderHelper.enableStandardItemLighting(); }
May 31, 20178 yr Your tanks should not be in static fields, each instance of the TileEntity should have its own tanks. I'm not entirely sure what's causing that behaviour in the GUI, but it may be related to the static fields. How are you syncing the tanks to the client? Post the code that does this. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
May 31, 20178 yr Author 18 hours ago, Choonster said: Your tanks should not be in static fields, each instance of the TileEntity should have its own tanks. I'm not entirely sure what's causing that behaviour in the GUI, but it may be related to the static fields. How are you syncing the tanks to the client? Post the code that does this. Ok i have removed the static fields, as for my syncing all i really have is this: @Nullable @Override public SPacketUpdateTileEntity getUpdatePacket() { NBTTagCompound data = new NBTTagCompound(); writeToNBT(data); return new SPacketUpdateTileEntity(this.pos, 1, data); } @Override @SideOnly(Side.CLIENT) public void onDataPacket(NetworkManager networkManager, SPacketUpdateTileEntity s35PacketUpdateTileEntity) { readFromNBT(s35PacketUpdateTileEntity.getNbtCompound()); world.markBlockRangeForRenderUpdate(this.pos, this.pos); this.world.notifyBlockUpdate(this.pos, world.getBlockState(this.pos), world.getBlockState(this.pos), 3); } @Override public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState) { return oldState.getBlock() != newState.getBlock(); }
June 1, 20178 yr 8 hours ago, abused_master said: Ok i have removed the static fields, as for my syncing all i really have is this: You should also override TileEntity#getUpdateTag to return data that should be sent to the client with the chunk (usually the same data as the update packet). Do you ever manually trigger the sending of the update packet with World#notifyBlockUpdate? Are the contents of the fluid tanks ever used for rendering the block, or are they only rendered in the GUI? If they're only rendered in the GUI, you can sync them in the Container rather than the TileEntity's update tag/packet (and avoid re-rendering the chunk whenever you receive the update packet). Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 1, 20178 yr Author 11 hours ago, Choonster said: You should also override TileEntity#getUpdateTag to return data that should be sent to the client with the chunk (usually the same data as the update packet). Do you ever manually trigger the sending of the update packet with World#notifyBlockUpdate? Are the contents of the fluid tanks ever used for rendering the block, or are they only rendered in the GUI? If they're only rendered in the GUI, you can sync them in the Container rather than the TileEntity's update tag/packet (and avoid re-rendering the chunk whenever you receive the update packet). ok i've implemented getUpdateTag, as for notifyBlockUpdate i am not manually triggering or sending it. Soon i plan to have some fluid rendered for the block but this is after i get the gui situation sorted.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.