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

    • Instale el mod en mi servidor y este se queda iniciando por horas, en la consola me habla de algo de permisos y trate de seguir la ruta que me da pero no existe.   [13:05:32 INFO]: CustomNPC Permissions available: [13:05:32 INFO]: customnpcs.edit.blocks [13:05:32 INFO]: customnpcs.edit.villager [13:05:32 INFO]: customnpcs.global.bank [13:05:32 INFO]: customnpcs.global.dialog [13:05:32 INFO]: customnpcs.global.faction [13:05:32 INFO]: customnpcs.global.linked [13:05:32 INFO]: customnpcs.global.naturalspawn [13:05:32 INFO]: customnpcs.global.playerdata [13:05:32 INFO]: customnpcs.global.quest [13:05:32 INFO]: customnpcs.global.recipe [13:05:32 INFO]: customnpcs.global.transport [13:05:32 INFO]: customnpcs.npc.advanced [13:05:32 INFO]: customnpcs.npc.ai [13:05:32 INFO]: customnpcs.npc.clone [13:05:32 INFO]: customnpcs.npc.create [13:05:32 INFO]: customnpcs.npc.delete [13:05:32 INFO]: customnpcs.npc.display [13:05:32 INFO]: customnpcs.npc.freeze [13:05:32 INFO]: customnpcs.npc.gui [13:05:32 INFO]: customnpcs.npc.inventory [13:05:32 INFO]: customnpcs.npc.reset [13:05:32 INFO]: customnpcs.npc.stats [13:05:32 INFO]: customnpcs.scenes [13:05:32 INFO]: customnpcs.soulstone.all [13:05:32 INFO]: customnpcs.spawner.create [13:05:32 INFO]: customnpcs.spawner.mob [13:05:32 INFO]: customnpcs.tool.mounter [13:05:32 INFO]: customnpcs.tool.nbtbook [13:05:32 INFO]: customnpcs.tool.pather [13:05:32 INFO]: customnpcs.tool.scripter
    • I have created a very simple mod that is just supposed to send a message to a player when they join. Upon adding it to a server (that has other mods on it), the following crash message appears: [12:13:01] [main/ERROR] [minecraft/Main]: Failed to start the minecraft server net.minecraftforge.fml.LoadingFailedException: Loading errors encountered: [         Epic Mod (epicmod) has failed to load correctly §7java.lang.NoSuchMethodException: net.ed.epicmod.EpicMod.<init>() ]         at net.minecraftforge.fml.ModLoader.waitForTransition(ModLoader.java:243) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at net.minecraftforge.fml.ModLoader.lambda$dispatchAndHandleError$24(ModLoader.java:208) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at java.util.Optional.ifPresent(Optional.java:178) ~[?:?] {re:mixin}         at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:208) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at net.minecraftforge.fml.ModLoader.lambda$gatherAndInitializeMods$14(ModLoader.java:185) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?] {re:mixin,re:computing_frames}         at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:185) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at net.minecraftforge.server.loading.ServerModLoader.load(ServerModLoader.java:32) ~[forge-1.19.2-43.2.14-universal.jar%23552!/:?] {re:classloading}         at net.minecraft.server.Main.main(Main.java:113) ~[server-1.19.2-20220805.130853-srg.jar%23547!/:?] {re:classloading,re:mixin,pl:mixin:A}         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}         at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}         at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}         at net.minecraftforge.fml.loading.targets.CommonServerLaunchHandler.lambda$launchService$0(CommonServerLaunchHandler.java:29) ~[fmlloader-1.19.2-43.2.14.jar%2367!/:?] {}         at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) [bootstraplauncher-1.1.2.jar:?] {} Why could this be? I have tried using the mod on another forge server with only this mod installed and it works there. Is my mod somehow interfering with other mods? MC version is 1.19.2
    • how to make animated doors?, maybe geckolib, but i don't know how to code it?
    • For crash 1, set max-tick-time to -1 in your server.properties Crash 2 shows a conflict or incompatibility between LuckPerms and the mod boh-0.0.6.1-forge-1.20.1_2.jar
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
  • Topics

×
×
  • Create New...

Important Information

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