Jump to content

Homletmoo

Members
  • Posts

    6
  • Joined

  • Last visited

Everything posted by Homletmoo

  1. Note: I don't think the system I described for setting the Fluid textures in that post is how it's intended to be done. I simply can't find any other solution, and the documentation for that area is quite poor. This new Fluid system is very convenient, but I don't think it's finished.
  2. Before I get onto the bucket code, I almost forgot - register your BlockFluidClassic instance in your proxy like you would for any other block. For the ItemBucket class, the only difference from a normal Item is that you pass the super constructor a second value: the id of your BlockFluidClassic class, which will be automatically placed when you right click. Then, somewhere in initialisation, use the FluidContainerRegistry to register this item as a container holding one bucket's worth of that fluid: FluidContainerRegistry.registerFluidContainer( new FluidContainerData( FluidRegistry.getFluidStack( ModExample.fluidExample.getName(), FluidContainerRegistry.BUCKET_VOLUME ), new ItemStack( ModExample.bucketExample ), new ItemStack( Item.bucketEmpty ) ) ); Finally, we need to tell minecraft to fill a bucket with this fluid whenever it is right clicked on with a bucket in hand. Fortunately, Forge provides an event listener that fires when you right click with a bucket. @ForgeSubscribe public void onBucketFill( FillBucketEvent event ) { ItemStack result = attemptFill( event.world, event.target ); if ( result != null ) { event.result = result; event.setResult( Result.ALLOW ); } } where attemptFill( World, MovingObjectPosition ) is a function that checks what the picked block is, and returns an ItemStack of the relevant filled container if applicable: private ItemStack attemptFill( World world, MovingObjectPosition p ) { int id = world.getBlockId( p.blockX, p.blockY, p.blockZ ); if ( id == ModExample.blockFluidExample.blockID ) { if ( world.getBlockMetadata( p.blockX, p.blockY, p.blockZ ) == 0 ) // Check that it is a source block { world.setBlock( p.blockX, p.blockY, p.blockZ, 0 ); // Remove the fluid block return new ItemStack( ModExample.bucketExample ); } } return null; } Phew. I think that's all, though. If it doesn't work, I'll check to see if I've missed anything.
  3. Going through the same process, and I think I just about have it working. What you need: Class extending Fluid for the registry Class extending BlockFluidClassic (flowing and still are rolled into one) for the in-world block Class extending ItemBucket if you want a custom container @ForgeSubscribe'd FillBucketEvent handler function (can have its own class if you use MinecraftForge.EVENT_BUS.register()) The Fluid class is very simple. All you need is a constructor to set a couple of values. You can even register it within its constructor: public FluidExample( int id ) { super( "example" ); setDensity( 8 ); // used by the block to work out how much it slows entities setViscosity( 4000 ); // used by the block to work out how fast it flows FluidRegistry.registerFluid( this ); } The BlockFluidClassic class is more similar to the old LiquidFlowing and Liquid Still classes. The main difference is that you give it a reference to the fluid, and it draws some information from that. Also, the textures are slightly different. Define private still and flowing icons in the class, and register them in your override of registerIcons( IconRegister ) . Also, pass them to getFluid().setIcons( Icon, Icon ) , since it's impossible to get a reference to the IconRegister elsewhere. Then, in your getIcon override, put this: @Override @SideOnly(Side.CLIENT) public Icon getIcon( int side, int meta ) { if ( side <= 1 ) return iconStill; else return iconFlowing; } This is getting quite long, so I'll put the bucket code in another comment.
  4. Calling initgui() doesn't re-create the object, so all the old buttons are still in the buttonList. In this case, I would call buttonList.clear() at the start of initgui(). EDIT: Ninja'd, ha. Re-initialising the object will work too.
  5. I have a solution for the second bug, but I'm stuck on the first myself. The bug is caused because the fuel value of the last item burnt isn't written to NBT, and is read by looking at the item in the slot when the tile entity is loaded. All's well and good if that item is the same as before, but if the stack ran out then it defaults to 200 to avoid zero division. Adding a new tag in the writeToNBT() and readFromNBT() methods seemed to solve it: public void writeToNBT( NBTTagCompound tagCompound ) { super.writeToNBT( tagCompound ); tagCompound.setShort( "BurnTime", (short) furnaceBurnTime ); tagCompound.setShort( "CookTime", (short) furnaceCookTime ); tagCompound.setShort( "ItemBurnTime", (short) currentItemBurnTime ); // <- this // add inventory and shizzle } public void readFromNBT( NBTTagCompound tagCompound ) { super.readFromNBT( tagCompound ); // read inventory and shizzle furnaceBurnTime = tagCompound.getShort( "BurnTime" ); furnaceCookTime = tagCompound.getShort( "CookTime" ); currentItemBurnTime = tagCompound.getShort( "ItemBurnTime" ); // <- and this } ... or something along those lines.
×
×
  • Create New...

Important Information

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