Jump to content

grand_mind1

Members
  • Posts

    122
  • Joined

  • Last visited

Posts posted by grand_mind1

  1. Ah, interesting point. Yes, I am going completely off the GUI. Would you say that the problem is related to the GUI and not the actual tile entity?

    This is the GUI class:

     

    public class GuiCoffeeMaker extends GuiContainer
    {
        private int x, y, z;
        private EntityPlayer entityPlayer;
        private World world;
        private int xSize, ySize;
        private TileEntityCoffeeMaker instance;
        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;
            this.instance = (TileEntityCoffeeMaker)world.getTileEntity(x, y, z);
            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(instance.getWaterTank(), x + 35, y + 17);
            drawFluidTank(instance.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)
        {
            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, 0, minU, minV);
            tessellator.draw();
        }
    }
    

     

  2. Hey, I'm trying to get my tile entity to save its data so it doesn't reset when the world is reloaded. I'm having a lot of trouble understand NBT, so it isn't going too well. I thought this read and write code would work, however it doesn't seem to do anything at all. If someone could explain this to me, it would be greatly appreciated.

    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;
        }
    
        @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 (getStackInSlot(3) != null)
            {
                if (getStackInSlot(3).isItemEqual(new ItemStack(ModItems.ItemCoffeeMug)))
                {
                    if (getCoffeeTank().getFluidAmount() >= 1000)
                    {
                        decrStackSize(3, 1);
                        setInventorySlotContents(3, new ItemStack(ModItems.BeverageBlackCoffee));
                        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);
            if (tag.hasKey("WaterTank"))
                waterTank = waterTank.readFromNBT(tag.getCompoundTag("WaterTank"));
            if (tag.hasKey("CoffeeTank"))
                coffeeTank = coffeeTank.readFromNBT(tag.getCompoundTag("CoffeeTank"));
        }
    
        @Override
        public void writeToNBT(NBTTagCompound tag)
        {
            super.writeToNBT(tag);
            NBTTagCompound waterTankNBT = new NBTTagCompound();
            waterTank.writeToNBT(waterTankNBT);
            NBTTagCompound coffeeTankNBT = new NBTTagCompound();
            coffeeTank.writeToNBT(coffeeTankNBT);
            tag.setTag("WaterTank", waterTankNBT);
            tag.setTag("CoffeeTank", coffeeTankNBT);
            tag.setString("A_Warning", "Don't let looks fool you, that panda eating bamboo over there is crazy");
        }
    
        @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()};
        }
    }
    

     

    I'm pretty sure you only need the read and write from NBT methods, but I've included the whole class just in case. If you need anything else, please tell me.

    Thanks! :D

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

     

  4. 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

  5. Thank you for your reply. I have tried to follow your instructions, however I think I have done something incorrectly. At the moment, I don't think my tile entity is accepting water.

     

    This is my Block class:

     

    public class BlockCoffeeMaker extends BlockACOJ implements ITileEntityProvider
    {
        public BlockCoffeeMaker()
        {
            super(Material.rock);
            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);
            }
            return true;
        }
    
        @Override
        public TileEntity createNewTileEntity(World world, int meta)
        {
            return new TileEntityCoffeeMaker();
        }
    
        @Override
        public boolean hasTileEntity()
        {
            return true;
        }
    }
    

     

    My tileentity class:

     

    public class TileEntityCoffeeMaker extends TileEntity implements IFluidHandler
    {
        public static String getName()
        {
            return Names.TILE_COFFEE_MAKER;
        }
    
        protected FluidTank waterTank = new FluidTank(10000);
    
        @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.equals(FluidRegistry.WATER))
            {
                return waterTank.fill(resource, doFill);
            }
            return 0;
        }
    
        @Override
        public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
        {
            if (resource == null || !resource.isFluidEqual(waterTank.getFluid()))
            {
                return null;
            }
            return waterTank.drain(resource.amount, doDrain);
        }
    
        @Override
        public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
        {
            return waterTank.drain(maxDrain, doDrain);
        }
    
        @Override
        public boolean canFill(ForgeDirection from, Fluid fluid)
        {
            if (fluid == FluidRegistry.WATER)
            {
                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() };
        }
    }
    

     

    And my Gui class:

     

    public class GuiCoffeeMaker extends GuiScreen
    {
        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)
        {
            this.x = x;
            this.y = y;
            this.z = z;
            this.entityPlayer = entityPlayer;
            this.world = world;
            xSize = 176;
            ySize = 166;
        }
    
        @Override
        public void drawScreen(int mouseX, int mouseY, float renderPartialTicks)
        {
            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);
            fontRendererObj.drawString(StatCollector.translateToLocal("acoj.inv.coffeeMaker"), x+60, y+4, 0x313131);
            fontRendererObj.drawString(StatCollector.translateToLocal("acoj.inv.Inventory"), x+9, y+74, 0x313131);
    
        }
    
        @Override
        public boolean doesGuiPauseGame()
        {
            return false;
        }
    
        public static 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);
            }
        }
    
        private static 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 static void drawRectangleFromIcon(int x, int y, IIcon icon, int width, int height)
        {
            if (icon == 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 + 0, 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, 0, minU + (maxU - minU) * width / 16.0D, minV);
            tessellator.addVertexWithUV(x + 0, y + 0, 0, minU, minV);
            tessellator.draw();
        }
    }
    

     

    If I am missing any relevant code, please tell me. I know for sure that I have made a mistake or do not understand something. If you could please point out what I may have done wrong, please tell me.

    Thanks! :D

  6. Ah, derp. Completely missed that. I have one more question if you don't mind. Do you know if mods that add fluid pipes such as Ender IO automatically accommodate for tile entities that implement the FluidHandler, or would I have to somehow build interaction for that myself?

    Edit: Also, how would I go about changing the GUI texture to represent the amount of fluid in a tank?

  7. Thank you for your reply. I've taken a look at the TileFluidHandler example and edited my TileEntity accordingly. From reading the documentation in IFluidHandler, I think I know what each of them do. My next question is how would I now utilize these new methods. For example, I want the left tank in the GUI to be able to hold water. How would I go about allowing water in the tank?

  8. Hi, I'm trying to create a tile entity machine which can store fluids and items. I think the best way to explain what I am trying to do is to show a picture of the GUI I want to try to use.

    http://puu.sh/d3f3U/ea21cb1e3f.png

    At the moment, I am just focussing on getting the ability to store liquids and make the correct amount show up in the GUI. I'm wondering what classes to implement or extend in my block class.

    Thanks!

     

  9. Hi, title says it all, I'm trying to prevent players from sleeping. After doing a bit of research, I think I should be using the PlayerSleepInBedEvent which is fired when a player interacts with a bed. Since this event is not cancellable, I'm wondering if there is any other way to disallow the player from sleeping in the bed that they have interacted with.

    Thanks! :D

  10. I've been programming for about 3 years now, albeit rather sporadically across that time frame. I'm quite a slow learner and I take time build a great understanding like you have. I guess for someone like me, this:

     

    public void affectEntity(EntityLivingBase p_76402_1_, EntityLivingBase p_76402_2_, int p_76402_3_, double p_76402_4_)
        {
            int j;
    
            if ((this.id != heal.id || p_76402_2_.isEntityUndead()) && (this.id != harm.id || !p_76402_2_.isEntityUndead()))
            {
                if (this.id == harm.id && !p_76402_2_.isEntityUndead() || this.id == heal.id && p_76402_2_.isEntityUndead())
                {
                    j = (int)(p_76402_4_ * (double)(6 << p_76402_3_) + 0.5D);
    
                    if (p_76402_1_ == null)
                    {
                        p_76402_2_.attackEntityFrom(DamageSource.magic, (float)j);
                    }
                    else
                    {
                        p_76402_2_.attackEntityFrom(DamageSource.causeIndirectMagicDamage(p_76402_2_, p_76402_1_), (float)j);
                    }
                }
            }
            else
            {
                j = (int)(p_76402_4_ * (double)(4 << p_76402_3_) + 0.5D);
                p_76402_2_.heal((float)j);
            }
        }
    

     

    is a bit hard to read at a quick glance. :P

  11. Thank you very much, I will take a look at this. As you probably get tired of hearing, I am new to modding. You are very obviously not new to any of this. What may be completely obvious and self-explanatory to you, is a very new and complicated world for me.

  12. Right... I had gotten that far, however I somehow doubt that

    public class PotionTest extends Potion
    {
        public PotionTest(int par1, boolean par2, int par3)
        {
            super(par1, par2, par3);
        }
    
        public Potion setIconIndex(int par1, int par2)
        {
            super.setIconIndex(par1, par2);
            return this;
        }
    }
    

    is all I need. How would I go about actually using the effect?

  13. Hi, I'm trying to create a custom potion effect. I've looked at several tutorials, however all of the ones that I have found are outdated and/or don't make sense to me. I was hoping someone could provide me with a link to an updated tutorial or quickly run down how to do it.

    Thanks!  :D

  14. Thank you for your reply. I've done so with the ModBlocks class now looking like this:

     

    public class ModBlocks
    {
        public static final Fluid LiquidCoffee = new LiquidCoffee();
        public static final BlockFluidClassic BlockLiquidCoffee = new BlockLiquidCoffee(LiquidCoffee, Material.water);
    
        public static void init()
        {
            FluidRegistry.registerFluid(LiquidCoffee);
            GameRegistry.registerBlock(BlockLiquidCoffee, Names.LIQUID_COFFEE_BLOCK);
        }
    }
    

     

     

    However, the problem still persists. The error is identical.

  15. Hello, I'm trying to create a custom coffee liquid. I semi-followed(I know the "semi-" part is where I went wrong, I just can't find what I didn't do/changed that would affect it in this way) the tutorial on the wiki here: http://www.minecraftforge.net/wiki/Create_a_Fluid however, when I try to run the game, I get the following error:

     

     

    Caused by: java.lang.NullPointerException
    at net.minecraftforge.fluids.FluidRegistry.getFluidID(FluidRegistry.java:119)
    at net.minecraftforge.fluids.Fluid.getID(Fluid.java:177)
    at net.minecraftforge.fluids.FluidStack.<init>(FluidStack.java:27)
    at net.minecraftforge.fluids.BlockFluidClassic.<init>(BlockFluidClassic.java:28)
    at com.darichey.ACOJ.block.BlockLiquidCoffee.<init>(BlockLiquidCoffee.java:27)
    at com.darichey.ACOJ.init.ModBlocks.<clinit>(ModBlocks.java:22)
    ... 47 more
    

     

     

     

    The init() method from the following class is called from my preInit() method in my main class:

     

    public class ModBlocks
    {
        public static final Fluid LiquidCoffee = new LiquidCoffee();
        public static final BlockFluidClassic BlockLiquidCoffee = new BlockLiquidCoffee(LiquidCoffee, Material.water);
    
        public static void init()
        {
            GameRegistry.registerBlock(BlockLiquidCoffee, Names.LIQUID_COFFEE_BLOCK);
            FluidRegistry.registerFluid(LiquidCoffee);
        }
    }
    

     

     

    The LiquidCoffee class:

     

    public class LiquidCoffee extends Fluid
    {
        public LiquidCoffee()
        {
            super(Names.LIQUID_COFFEE);
            this.setUnlocalizedName(Names.LIQUID_COFFEE);
            this.setViscosity(2000);
        }
    }
    

     

     

    The BlockLiquidCoffee class:

     

    public class BlockLiquidCoffee extends BlockFluidClassic
    {
        @SideOnly(Side.CLIENT)
        protected IIcon stillIcon;
    
        @SideOnly(Side.CLIENT)
        protected IIcon flowingIcon;
    
        public BlockLiquidCoffee(Fluid fluid, Material material)
        {
            super(fluid, material);
            this.setCreativeTab(CreativeTabACOJ.ACOJ_TAB);
            this.setBlockName(Names.LIQUID_COFFEE_BLOCK);
        }
    
        @Override
        public IIcon getIcon(int side, int meta)
        {
            return (side == 0 || side == 1)? stillIcon : flowingIcon;
        }
    
        @SideOnly(Side.CLIENT)
        @Override
        public void registerBlockIcons(IIconRegister iconRegister)
        {
            stillIcon = iconRegister.registerIcon(Reference.MOD_ID + ":LiquidCoffeeStill");
            flowingIcon = iconRegister.registerIcon(Reference.MOD_ID + ":LiquidCoffeeFlowing");
        }
    
        @Override
        public boolean canDisplace(IBlockAccess world, int x, int y, int z)
        {
            if (world.getBlock(x, y, z).getMaterial().isLiquid()) return false;
            return super.canDisplace(world, x, y, z);
        }
    
        @Override
        public boolean displaceIfPossible(World world, int x, int y, int z)
        {
            if (world.getBlock(x, y, z).getMaterial().isLiquid()) return false;
            return super.displaceIfPossible(world, x, y, z);
        }
    }
    

     

     

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

    Thanks!  :D

×
×
  • Create New...

Important Information

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