Jump to content

[1.7.10]All Tile entities affected by changes to others


grand_mind1

Recommended Posts

First off, sorry if that title doesn't make any sense whatsoever I couldn't think of anything. Anyways, hopefully I can explain my problem a bit better. Thanks to the help of these forums, my tile entity has two internal tanks. My problem is these tanks are universal for every tile entity of the same type created in the world. So if I deposit two buckets of water in one, two buckets of water will be deposited into every tile entity. I'm fairly certain that the problem is only with the tanks and not the whole tile entity, however I haven't thought of a way to make sure.

 

My Block class:

 

public class BlockCoffeeMaker extends BlockContainer implements ITileEntityProvider
{
    TileEntityCoffeeMaker instance;

    public BlockCoffeeMaker()
    {
        super(Material.rock);
        this.setCreativeTab(CreativeTabACOJ.ACOJ_TAB);
        this.setBlockName(Names.COFFEE_MAKER);
    }

    @Override
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int meta, float hitX, float hitY, float hitZ)
    {
        if (!world.isRemote && world.getTileEntity(x, y, z) instanceof TileEntityCoffeeMaker)
        {
            entityPlayer.openGui(ACOJ.instance, GUIs.COFFEE_MAKER.ordinal(), world, x, y, z);
            ((TileEntityCoffeeMaker) world.getTileEntity(x,y,z)).fill(ForgeDirection.EAST, new FluidStack(ModFluids.LiquidCoffee, 12000), true);
            //((TileEntityCoffeeMaker) world.getTileEntity(x,y,z)).fill(ForgeDirection.EAST, new FluidStack(FluidRegistry.WATER, 12000), true);
        }
        return true;
    }

    @Override
    public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
    {
        ArrayList<ItemStack> itemStacks = Lists.newArrayList();
        ItemStack itemStack = new ItemStack(ModBlocks.BlockCoffeeMaker, 1, metadata);
        itemStacks.add(itemStack);
        TileEntityCoffeeMaker coffeeMaker = getInstance();
        if (coffeeMaker.getStackInSlot(0) != null) itemStacks.add(coffeeMaker.getStackInSlot(0));
        if (coffeeMaker.getStackInSlot(1) != null) itemStacks.add(coffeeMaker.getStackInSlot(1));
        if (coffeeMaker.getStackInSlot(2) != null) itemStacks.add(coffeeMaker.getStackInSlot(2));
        if (coffeeMaker.getStackInSlot(3) != null) itemStacks.add(coffeeMaker.getStackInSlot(3));
        return itemStacks;
    }

    @Override
    public TileEntity createNewTileEntity(World world, int meta)
    {
        instance = new TileEntityCoffeeMaker();
        return instance;
    }

    @Override
    public boolean hasTileEntity()
    {
        return true;
    }
    public TileEntityCoffeeMaker getInstance()
    {
        return instance;
    }

    @Override
    public String getUnlocalizedName()
    {
        return String.format("tile.%s%s", Reference.MOD_ID.toLowerCase() + ":", getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
    }

    protected String getUnwrappedUnlocalizedName(String unlocalizedName)
    {
        return unlocalizedName.substring(unlocalizedName.indexOf(".") + 1);
    }
}

 

 

My tile entity class:

 

public class TileEntityCoffeeMaker extends TileEntityInventory implements IFluidHandler
{

    public TileEntityCoffeeMaker()
    {
        super();
        this.size = 4;
        this.invName = Names.COFFEE_MAKER;
    }

    public static String getName()
    {
        return Names.TILE_COFFEE_MAKER;
    }

    int ticker = 100;

    @Override
    public void updateEntity()
    {
        if (getStackInSlot(0) != null)
        {
            if (getStackInSlot(0).isItemEqual(new ItemStack(Items.water_bucket)))
            {
                decrStackSize(0, 1);
                setInventorySlotContents(0, new ItemStack(Items.bucket));
                fill(ForgeDirection.EAST, new FluidStack(FluidRegistry.WATER, 1000), true);
            }
        }
        if (getCoffeeTank().getFluidAmount() >= 1000)
        {
            if (getStackInSlot(3) != null)
            {
                if (getStackInSlot(3).isItemEqual(new ItemStack(ModItems.ItemCoffeeMug)))
                {
                    decrStackSize(3, 1);
                    setInventorySlotContents(3, new ItemStack(ModItems.BeverageBlackCoffee));
                    drain(ForgeDirection.EAST, new FluidStack(ModFluids.LiquidCoffee, 1000), true);
                }
                else if (getStackInSlot(3).isItemEqual(new ItemStack(ModItems.ItemLargeCoffeeMug)))
                {
                    decrStackSize(3, 1);
                    setInventorySlotContents(3, new ItemStack(ModItems.BeverageBlackCoffeeLarge, 1));
                    drain(ForgeDirection.EAST, new FluidStack(ModFluids.LiquidCoffee, 1000), true);
                }
            }
        }
    }



    public static FluidTank waterTank = new FluidTank(12000);
    public static FluidTank coffeeTank = new FluidTank(12000);

    public static FluidTank getWaterTank()
    {
        return waterTank;
    }

    public static FluidTank getCoffeeTank()
    {
        return coffeeTank;
    }

    @Override
    public void readFromNBT(NBTTagCompound tag)
    {
        super.readFromNBT(tag);
        waterTank.readFromNBT(tag);
    }

    @Override
    public void writeToNBT(NBTTagCompound tag)
    {
        super.writeToNBT(tag);
        waterTank.writeToNBT(tag);
    }

    @Override
    public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
    {
        if (resource.isFluidEqual(new FluidStack(FluidRegistry.WATER, 1)))
        {
            return waterTank.fill(resource, doFill);
        } else if (resource.isFluidEqual(new FluidStack(ModFluids.LiquidCoffee, 1)))
        {
            return coffeeTank.fill(resource, doFill);
        }
        return 0;
    }

    @Override
    public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
    {
        if (resource == null || !resource.isFluidEqual(waterTank.getFluid()) || !resource.isFluidEqual(coffeeTank.getFluid()))
        {
            return null;
        } else if (resource.isFluidEqual(waterTank.getFluid()))
        {
            return waterTank.drain(resource.amount, doDrain);
        } else if (resource.isFluidEqual(coffeeTank.getFluid()))
        {
            return coffeeTank.drain(resource.amount, doDrain);
        }
        return null;
    }

    @Override
    public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
    {
        if (from.equals(ForgeDirection.EAST))
        {
            return waterTank.drain(maxDrain, doDrain);
        }
        return coffeeTank.drain(maxDrain, doDrain);
    }

    @Override
    public boolean canFill(ForgeDirection from, Fluid fluid)
    {
        if (fluid == FluidRegistry.WATER || fluid == ModFluids.LiquidCoffee)
        {
            return true;
        }
        return false;
    }

    @Override
    public boolean canDrain(ForgeDirection from, Fluid fluid)
    {
        return true;
    }

    @Override
    public FluidTankInfo[] getTankInfo(ForgeDirection from)
    {
        return new FluidTankInfo[]{waterTank.getInfo(), coffeeTank.getInfo()};
    }
}

 

 

If I've forgotten to include any relevant code, please tell me.

Thanks! :D

Link to comment
Share on other sites

Hey, I've been trying to get this to work for a bit now, but I can't seem to get it. For my Gui class to draw the fluid in each tank, it must be passed each of the tanks. To do this, I need to somehow get the instance of the tile entity in the Gui class. Do you have any suggestions?

 

Gui Class:

 

public class GuiCoffeeMaker extends GuiContainer
{
    private int x, y, z;
    private EntityPlayer entityPlayer;
    private World world;
    private int xSize, ySize;
    private ResourceLocation backgroundImage = new ResourceLocation(Reference.MOD_ID.toLowerCase() + ":textures/gui/GuiCoffeeMaker.png");

    public GuiCoffeeMaker(EntityPlayer entityPlayer, World world, int x, int y, int z)
    {
        super(new ContainerCofffeeMaker(entityPlayer, (IInventory) world.getTileEntity(x, y, z), 176, 170));
        this.x = x;
        this.y = y;
        this.z = z;
        this.entityPlayer = entityPlayer;
        this.world = world;
        xSize = 176;
        ySize = 170;
    }

    @Override
    protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_)
    {
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.getTextureManager().bindTexture(backgroundImage);
        int x = (this.width - xSize) / 2;
        int y = (this.height - ySize) / 2;
        drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
        drawFluidTank(TileEntityCoffeeMaker.getWaterTank(), x + 35, y + 17); //Lines that must utilize the instance
        drawFluidTank(TileEntityCoffeeMaker.getCoffeeTank(), x + 126, y + 17); //------
        fontRendererObj.drawString(StatCollector.translateToLocal("acoj.inv.coffeeMaker"), x + 56, y + 4, 0x313131);
        fontRendererObj.drawString(StatCollector.translateToLocal("acoj.inv.Inventory"), x + 9, y + 79, 0x313131);
    }

    @Override
    public boolean doesGuiPauseGame()
    {
        return false;
    }

    public void drawFluidTank(IFluidTank tank, int x, int y) //Method that must be passed the tank
    {
        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);
        }
    }

    private void drawFluid(int x, int y, IIcon icon, int width, int height)
    {
        int i = 0;
        int j = 0;

        int drawHeight = 0;
        int drawWidth = 0;

        for (i = 0; i < width; i += 16)
        {
            for (j = 0; j < height; j += 16)
            {
                drawWidth = Math.min(width - i, 16);
                drawHeight = Math.min(height - j, 16);
                drawRectangleFromIcon(x + i, y + j, icon, drawWidth, drawHeight);
            }
        }
    }

    private void drawRectangleFromIcon(int x, int y, IIcon icon, int width, int height)
    {
        if (icon == null)
        {
            LogHelper.info("Null");
            return;
        }
        double minU = icon.getMinU();
        double maxU = icon.getMaxU();
        double minV = icon.getMinV();
        double maxV = icon.getMaxV();

        Tessellator tessellator = Tessellator.instance;
        tessellator.startDrawingQuads();
        tessellator.addVertexWithUV(x, y + height, 0, minU, minV + (maxV - minV) * height / 16.0D);
        tessellator.addVertexWithUV(x + width, y + height, 0, minU + (maxU - minU) * width / 16.0D, minV + (maxV - minV) * height / 16.0D);
        tessellator.addVertexWithUV(x + width, y, 0, minU + (maxU - minU) * width / 16.0D, minV);
        tessellator.addVertexWithUV(x, y, 10, minU, minV);
        tessellator.draw();
    }
}

 

 

Tile Entity Class:

 

public class TileEntityCoffeeMaker extends TileEntityInventory implements IFluidHandler
{

    public TileEntityCoffeeMaker()
    {
        super();
        this.size = 4;
        this.invName = Names.COFFEE_MAKER;
    }

    public static String getName()
    {
        return Names.TILE_COFFEE_MAKER;
    }

    @Override
    public void updateEntity()
    {
        if (getStackInSlot(0) != null)
        {
            if (getStackInSlot(0).isItemEqual(new ItemStack(Items.water_bucket)))
            {
                decrStackSize(0, 1);
                setInventorySlotContents(0, new ItemStack(Items.bucket));
                fill(ForgeDirection.EAST, new FluidStack(FluidRegistry.WATER, 1000), true);
            }
        }
        if (getCoffeeTank().getFluidAmount() >= 1000)
        {
            if (getStackInSlot(3) != null)
            {
                if (getStackInSlot(3).isItemEqual(new ItemStack(ModItems.ItemCoffeeMug)))
                {
                    decrStackSize(3, 1);
                    setInventorySlotContents(3, new ItemStack(ModItems.BeverageBlackCoffee));
                    drain(ForgeDirection.EAST, new FluidStack(ModFluids.LiquidCoffee, 1000), true);
                }
                else if (getStackInSlot(3).isItemEqual(new ItemStack(ModItems.ItemLargeCoffeeMug)))
                {
                    decrStackSize(3, 1);
                    setInventorySlotContents(3, new ItemStack(ModItems.BeverageBlackCoffeeLarge, 1));
                    drain(ForgeDirection.EAST, new FluidStack(ModFluids.LiquidCoffee, 1000), true);
                }
            }
        }
    }



    public FluidTank waterTank = new FluidTank(12000);
    public FluidTank coffeeTank = new FluidTank(12000);

    public FluidTank getWaterTank()
    {
        return waterTank;
    }

    public FluidTank getCoffeeTank()
    {
        return coffeeTank;
    }

    @Override
    public void readFromNBT(NBTTagCompound tag)
    {
        super.readFromNBT(tag);
        waterTank.readFromNBT(tag);
    }

    @Override
    public void writeToNBT(NBTTagCompound tag)
    {
        super.writeToNBT(tag);
        waterTank.writeToNBT(tag);
    }

    @Override
    public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
    {
        if (resource.isFluidEqual(new FluidStack(FluidRegistry.WATER, 1)))
        {
            return waterTank.fill(resource, doFill);
        } else if (resource.isFluidEqual(new FluidStack(ModFluids.LiquidCoffee, 1)))
        {
            return coffeeTank.fill(resource, doFill);
        }
        return 0;
    }

    @Override
    public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
    {
        if (resource == null || !resource.isFluidEqual(waterTank.getFluid()) || !resource.isFluidEqual(coffeeTank.getFluid()))
        {
            return null;
        } else if (resource.isFluidEqual(waterTank.getFluid()))
        {
            return waterTank.drain(resource.amount, doDrain);
        } else if (resource.isFluidEqual(coffeeTank.getFluid()))
        {
            return coffeeTank.drain(resource.amount, doDrain);
        }
        return null;
    }

    @Override
    public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
    {
        if (from.equals(ForgeDirection.EAST))
        {
            return waterTank.drain(maxDrain, doDrain);
        }
        return coffeeTank.drain(maxDrain, doDrain);
    }

    @Override
    public boolean canFill(ForgeDirection from, Fluid fluid)
    {
        if (fluid == FluidRegistry.WATER || fluid == ModFluids.LiquidCoffee)
        {
            return true;
        }
        return false;
    }

    @Override
    public boolean canDrain(ForgeDirection from, Fluid fluid)
    {
        return true;
    }

    @Override
    public FluidTankInfo[] getTankInfo(ForgeDirection from)
    {
        return new FluidTankInfo[]{waterTank.getInfo(), coffeeTank.getInfo()};
    }
}

 

Link to comment
Share on other sites

By the way, you also have this in your block class:

 

TileEntityCoffeeMaker instance;

 

That's a no-no, as the Block class is a singleton and you want to have more than one TileEntity instance.  That's why world.getTileEntity(x,y,z) exists.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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

    • Doesn't work https://mclo.gs/XaTwdOZ
    • Another Update: Updating the Forge MDL version worked. My conjecture to this weird bug or issue of sorts is that the plugin was downloading mappings and MDK from the latest forge minecraft version instead of the set forge minecraft version. This could be the only possible case of explanation, because clearing gradle cache does not work for me. I have tried this for over hours and just upgrading the MDK worked for me. Build and compile gradlew commands also works now, which further proves my guess. This is probably a bug on the plugin's side somehow, but it just doesn't make sense since at start trying the 40.2.18 MDL works fine and then deleting the cache breaks it.
    • Update: It seems like the forge version I was using was broken entirely, somehow... I am now using the Forge MDL 1.18.2-40.2.21 (previous used 40.2.18) version and now everything is working sort-of fine.... adding extra dependencies seems to break it again. It is so weird... Did anyone have similar issues with this before? I'm also using the Minecraft Development plugin for IntelliJ IDEA
    • Hello! I'm currently having issues while building a jar file for my Minecraft 1.18.2 Forge mod. I've attached a link to imgur below that holds two screenshots of the errors. I'm using Jetbrains IntelliJ IDEA 2024.1 and Gradle 8.4. This is my repo: Mod Repo When I was modding, I needed to build the mod in order to test the mod, which didn't work, as the first screenshot gives. It throws errors for each classes in the forge registry class (or whatever the hell that mess is) and is just generally confusing. Now I have deleted everything in my project folder and re-pulled the repo from github, which now gives the errors in the second image where all forge classes are not imported somehow. When I try to build it now, it just repeats the same errors in the first image. https://imgur.com/a/DYwSKqJ Please I need help desparately
    • [main/WARN] [net.minecraft.server.Main/]: Failed to load datapacks, can't proceed with server load. You can either fix your datapacks or reset to vanilla with --safeMode 8400java.util.concurrent.ExecutionException: com.google.gson.JsonParseException: Error loading registry data: No key name in MapLike[{"elements":[{"element":{"element_type":"minecraft:legacy_single_pool_element","location":"duneons:towns/village_creeperforest/town_center_01","processors":{"processors":[]},"projection":"rigid"},"weight":1}],"fallback":"minecraft:empty","forge:registry_name":"duneons:towns/village_creeperforest/town_centers"}] 8401at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396) ~[?:?] 8402at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2073) ~[?:?] 8403at net.minecraft.server.Main.main(Main.java:182) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8404at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] 8405at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] 8406at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] 8407at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] 8408at net.minecraftforge.fml.loading.targets.CommonServerLaunchHandler.lambda$launchService$0(CommonServerLaunchHandler.java:29) ~[fmlloader-1.19.2-43.3.13.jar%2367!/:?] 8409at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) [modlauncher-10.0.8.jar%2354!/:?] 8410at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-10.0.8.jar%2354!/:?] 8411at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-10.0.8.jar%2354!/:?] 8412at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-10.0.8.jar%2354!/:?] 8413at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-10.0.8.jar%2354!/:?] 8414at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-10.0.8.jar%2354!/:?] 8415at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-10.0.8.jar%2354!/:?] 8416at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) [bootstraplauncher-1.1.2.jar:?] 8417Caused by: com.google.gson.JsonParseException: Error loading registry data: No key name in MapLike[{"elements":[{"element":{"element_type":"minecraft:legacy_single_pool_element","location":"duneons:towns/village_creeperforest/town_center_01","processors":{"processors":[]},"projection":"rigid"},"weight":1}],"fallback":"minecraft:empty","forge:registry_name":"duneons:towns/village_creeperforest/town_centers"}] 8418at net.minecraft.core.RegistryAccess.m_206152_(RegistryAccess.java:211) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8419at java.util.Optional.ifPresent(Optional.java:178) ~[?:?] 8420at net.minecraft.core.RegistryAccess.m_206159_(RegistryAccess.java:210) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8421at net.minecraft.core.RegistryAccess.m_206171_(RegistryAccess.java:203) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8422at net.minecraft.resources.RegistryOps.m_206817_(RegistryOps.java:32) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8423at net.minecraft.resources.RegistryOps.m_206813_(RegistryOps.java:25) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8424at net.minecraft.server.Main.lambda$main$2(Main.java:160) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8425at net.minecraft.server.WorldLoader.m_214362_(WorldLoader.java:24) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8426at net.minecraft.server.WorldStem.m_214415_(WorldStem.java:18) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8427at net.minecraft.server.Main.lambda$main$3(Main.java:158) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8428at net.minecraft.Util.m_214652_(Util.java:775) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8429at net.minecraft.Util.m_214679_(Util.java:770) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8430at net.minecraft.server.Main.main(Main.java:157) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8431... 13 more 8432  
  • Topics

×
×
  • Create New...

Important Information

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