Posted January 20, 20169 yr I tried to create a fluid for my mod but the bucket handler doesn't work correctly and in tanks, the fluid has a lava texture This is my BucketEvent.class: package XFactHD.thermalreactors.common.util; import cpw.mods.fml.common.eventhandler.Event; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; import net.minecraftforge.event.entity.player.FillBucketEvent; import java.util.HashMap; import java.util.Map; public class BucketEvent { public static BucketEvent INSTANCE = new BucketEvent(); public Map<Block, Item> buckets = new HashMap<Block, Item>(); private BucketEvent() {} @SubscribeEvent public void onBucketFill(FillBucketEvent event) { LogHelper.info("I am working"); ItemStack result = fillCustomBucket(event.world, event.target); //LogHelper.info(result==null?"nullResult":result.toString()); if (result == null) return; event.result = result; event.setResult(Event.Result.ALLOW); } public ItemStack fillCustomBucket(World world, MovingObjectPosition pos) { LogHelper.info("I am working too"); Block block = world.getBlock(pos.blockX, pos.blockY, pos.blockZ); Item bucket = buckets.get(block); //LogHelper.info(bucket==null?"nullBucket":bucket.toString()); if (bucket != null && world.getBlockMetadata(pos.blockX, pos.blockY, pos.blockZ) == 0) { world.setBlockToAir(pos.blockX, pos.blockY, pos.blockZ); return new ItemStack(bucket); } else { return null; } } } This is in the preInit phase: The method is called in the main mod class and works correctly public void preInit() { MinecraftForge.EVENT_BUS.register(BucketEvent.INSTANCE); fluidOxygen = new FluidOxygen(); FluidRegistry.registerFluid(fluidOxygen); blockFluidOxygen = new BlockFluidOxygen(); GameRegistry.registerBlock(blockFluidOxygen, "blockFluidOxygen"); itemOxygenBucket = new ItemOxygenBucket(); GameRegistry.registerItem(itemOxygenBucket, "oxygenBucket"); FluidContainerRegistry.registerFluidContainer(fluidOxygen, new ItemStack(itemOxygenBucket), new ItemStack(Items.bucket)); BucketEvent.INSTANCE.buckets.put(blockFluidOxygen, itemOxygenBucket); } The FluidBlock: package XFactHD.thermalreactors.common.fluid; import XFactHD.thermalreactors.common.util.Reference; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.material.MapColor; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fluids.BlockFluidClassic; import net.minecraftforge.fluids.FluidStack; public class BlockFluidOxygen extends BlockFluidClassic { @SideOnly(Side.CLIENT) protected IIcon stillIcon; @SideOnly(Side.CLIENT) protected IIcon flowingIcon; public static final Material materialOxygen = new Material(MapColor.waterColor); public BlockFluidOxygen() { super(new FluidOxygen(), materialOxygen); setBlockName(Reference.MOD_ID + ":" + "blockFluidOxygen"); } @Override public IIcon getIcon(int side, int meta) { return (side == 0 || side == 1)? stillIcon : flowingIcon; } @SideOnly(Side.CLIENT) @Override public void registerBlockIcons(IIconRegister register) { stillIcon = register.registerIcon(Reference.MOD_ID.toLowerCase() + ":blockFluidOxygen" + "." + "still"); flowingIcon = register.registerIcon(Reference.MOD_ID.toLowerCase() + ":blockFluidOxygen" + "." + "flowing"); } @Override public boolean canCollideCheck(int meta, boolean fullHit) { return false; } @Override public FluidStack drain(World world, int x, int y, int z, boolean doDrain) { return null; } @Override public int getMaxRenderHeightMeta() { return 0; } @Override public int getQuantaValue(IBlockAccess world, int x, int y, int z) { return 0; } @Override public boolean canDrain(World world, int x, int y, int z) { return true; } @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); } } The Fluid: package XFactHD.thermalreactors.common.fluid; import net.minecraftforge.fluids.Fluid; public class FluidOxygen extends Fluid { public FluidOxygen() { super("fluidOxygen"); setGaseous(true); setUnlocalizedName("fluidOxygen"); setTemperature(0); setDensity(-1); } } The Bucket: package XFactHD.thermalreactors.common.fluid; import XFactHD.thermalreactors.ThermalReactors; import XFactHD.thermalreactors.common.util.Reference; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.init.Items; import net.minecraft.item.ItemBucket; public class ItemOxygenBucket extends ItemBucket { public ItemOxygenBucket() { super(new BlockFluidOxygen()); setUnlocalizedName(Reference.MOD_ID + ":" + "bucketOxygen"); setMaxStackSize(1); setCreativeTab(ThermalReactors.creativeTab); setContainerItem(Items.bucket); } @Override public void registerIcons(IIconRegister ir) { itemIcon = ir.registerIcon(Reference.MOD_ID + ":" + "bucketOxygen"); } }
January 26, 20169 yr Thanks to another thread, the texture is working now. The BucketHandler is still misbehaving.
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.