Jump to content

[1.11.2] Fluid Storage


abused_master

Recommended Posts

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();
    }

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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();
    }

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Done, it still crashed. New log https://paste.ee/p/kYv6e
    • I am migrating a mod from 1.16.5 to 1.20.2 The version for 1.16.5 can be found here https://github.com/beothorn/automataCraft For the block called automata_start, it uses TileEntities and has blockstates, model/block and textures on json files. This is currently working fine on 1.16.5 https://github.com/beothorn/automataCraft/tree/master/src/main/resources/assets/automata For 1.20.2 I migrated the logic from TileEntities to BlockEntity. The mod is working fine. All blocks and Items are working with the correct textures except for the textures for each state of the automata_start block. No changes where made to the json files. This is the branch I am working on (there were some refactorings, but all is basically the same): https://github.com/beothorn/automataCraft/tree/1_20/src/main/resources/assets/automata The only difference I can think that may be related is that i had to implement createBlockStateDefinition on the BaseEntityBlock: https://github.com/beothorn/automataCraft/blob/1_20/src/main/java/br/com/isageek/automata/automata/AutomataStartBlock.java#L43 This is driving me crazy. I know the jsons are being loaded as I put a breakpoint at `net.minecraft.client.resources.model.ModelBakery#loadModel` and I can see BlockModelDefinition.fromJsonElement being called with automata_start. I also printed the state from the arguments of the tick function call and they look correct (https://github.com/beothorn/automataCraft/blob/1_20/src/main/java/br/com/isageek/automata/automata/Ticker.java#L32 ): blockState Block{automata:automata_start}[state=loadreplaceables] In game, all I see is the no textures. I think it is weird it is not the "missing texture" texture so I think it may be related to the material, but I had no success tweaking it (https://github.com/beothorn/automataCraft/blob/1_20/src/main/java/br/com/isageek/automata/automata/AutomataStartBlock.java#L37).   public static final Property<AutomataStartState> state = EnumProperty.create("state", AutomataStartState.class); private final AtomicReference<RegistryObject<BlockEntityType<?>>> blockEntityType; private final Map<String, RegistryObject<Block>> registeredBlocks; public AutomataStartBlock( final AtomicReference<RegistryObject<BlockEntityType<?>>> blockEntityType, final Map<String, RegistryObject<Block>> registeredBlocks ) { super(BlockBehaviour.Properties.of().mapColor(MapColor.STONE).strength(1.5F, 6.0F)); this.blockEntityType = blockEntityType; this.registeredBlocks = registeredBlocks; this.registerDefaultState(this.getStateDefinition().any().setValue(state, AutomataStartState.LOAD_REPLACEABLES)); } @Override protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateBuilder) { stateBuilder.add(state); }     So my cry for help is, anyone has any ideas? Is there a way to easily debug this, for example somewhere where I can list the textures for a given state, or make sure this is loaded?   Thanks in advance for the hints
    • FAILURE: Build failed with an exception. * What went wrong: A problem occurred configuring root project 'forge-1.8.9-11.15.1.2318-1.8.9-mdk'. > Could not resolve all dependencies for configuration ':classpath'. > Could not resolve net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT. Required by: :forge-1.8.9-11.15.1.2318-1.8.9-mdk:unspecified > Could not resolve net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT. > Unable to load Maven meta-data from https://jcenter.bintray.com/net/minecraftforge/gradle/ForgeGradle/2.1-SNAPSHOT/maven-metadata.xml. > Could not GET 'https://jcenter.bintray.com/net/minecraftforge/gradle/ForgeGradle/2.1-SNAPSHOT/maven-metadata.xml'. > peer not authenticated > Could not resolve net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT. > Unable to load Maven meta-data from http://files.minecraftforge.net/maven/net/minecraftforge/gradle/ForgeGradle/2.1-SNAPSHOT/maven-metadata.xml. > Could not GET 'http://files.minecraftforge.net/maven/net/minecraftforge/gradle/ForgeGradle/2.1-SNAPSHOT/maven-metadata.xml'. > peer not authenticated * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 2.78 secs This is the error I got. Any help would be appreciated!
    • Greetings, ladies and gentlemen. I know firsthand how distressing it can be to lose Bitcoin (BTC) to a phony online trading site. Thank God, when I became a victim of internet scammers, I came across genuine reviews of Captain WebGenesis. The Experts reviews on google were generally positive and reliable. Captain WebGenesis, a licensed cryptocurrency expert, helps persons who have fallen prey to investment scams recover their stolen funds. Captain WebGenesis miraculously recovered my wallet and all of my Bitcoins in roughly 48 hours. Captain WebGenesis is tried, trusted, and accessible to all victims of Bitcoin fraud. The service charge was pricey, but it was well worth it. If you need his help, get in touch with the Expert. SMS / Call; +1 (701)314-2729 Email; (captainwebgenesis(@)hackermail.com) Homepage; captainwebgenesis.com Salutations, Captain WebGenesis.
    • The mod causing the problem was (supplementaries-1.20-2.8.10). The solution I found is deleting it.
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.