From e2a01600883bbac000feba31ce97ec6f1f6eda5e Mon Sep 17 00:00:00 2001 From: Adubbz Date: Sat, 25 May 2013 14:08:06 +1000 Subject: [PATCH] Added Spring Water Buckets and tweaked Spring Water --- .../biomesoplenty/BiomesOPlenty.java | 2 + .../configuration/BOPConfiguration.java | 4 ++ .../configuration/BOPLiquids.java | 48 ++++++++++++------ .../helpers/BOPBucketHelper.java | 42 +++++++++++++++ .../biomesoplenty/items/ItemBOPBucket.java | 25 +++++++++ .../liquids/BlockSpringWaterFlowing.java | 2 +- .../liquids/BlockSpringWaterStill.java | 16 +++++- ...FreshWater.png => spring_water_bucket.png} | Bin 8 files changed, 122 insertions(+), 17 deletions(-) create mode 100644 src/minecraft/biomesoplenty/helpers/BOPBucketHelper.java create mode 100644 src/minecraft/biomesoplenty/items/ItemBOPBucket.java rename src/minecraft/mods/BiomesOPlenty/textures/items/{bucketFreshWater.png => spring_water_bucket.png} (100%) diff --git a/src/minecraft/biomesoplenty/BiomesOPlenty.java b/src/minecraft/biomesoplenty/BiomesOPlenty.java index d5ca0e639..0dbec1ed4 100644 --- a/src/minecraft/biomesoplenty/BiomesOPlenty.java +++ b/src/minecraft/biomesoplenty/BiomesOPlenty.java @@ -19,6 +19,7 @@ import biomesoplenty.configuration.BOPItems; import biomesoplenty.configuration.BOPLiquids; import biomesoplenty.configuration.BOPVanillaCompat; import biomesoplenty.helpers.AchievementHelper; +import biomesoplenty.helpers.BOPBucketHelper; import biomesoplenty.helpers.BOPCraft; import biomesoplenty.helpers.BonemealUse; import biomesoplenty.helpers.CreativeTabsBOP; @@ -128,6 +129,7 @@ public class BiomesOPlenty MinecraftForge.EVENT_BUS.register(new AchievementHelper()); MinecraftForge.EVENT_BUS.register(new BonemealUse()); MinecraftForge.EVENT_BUS.register(new EntitiesHelper()); + MinecraftForge.EVENT_BUS.register(new BOPBucketHelper()); proxy.registerRenderers(); diff --git a/src/minecraft/biomesoplenty/configuration/BOPConfiguration.java b/src/minecraft/biomesoplenty/configuration/BOPConfiguration.java index 2b5e8910d..f5250cf39 100644 --- a/src/minecraft/biomesoplenty/configuration/BOPConfiguration.java +++ b/src/minecraft/biomesoplenty/configuration/BOPConfiguration.java @@ -205,6 +205,8 @@ public class BOPConfiguration { public static int dartBlowerID; public static int dartID; + public static int springWaterBucketID; + public static int swordMudID; public static int shovelMudID; public static int pickaxeMudID; @@ -750,6 +752,8 @@ public class BOPConfiguration { flowerBandID = config.getItem("Flower Band ID", 21078, null).getInt(); + springWaterBucketID = config.getItem("Spring Water Bucket ID", 21079, null).getInt(); + //Liquid Ids springWaterStillID = config.get("Liquid IDs", "Spring Water Still ID (ID before this must be free!)", 1971, null).getInt(); diff --git a/src/minecraft/biomesoplenty/configuration/BOPLiquids.java b/src/minecraft/biomesoplenty/configuration/BOPLiquids.java index 1ed10110b..614cf5ee4 100644 --- a/src/minecraft/biomesoplenty/configuration/BOPLiquids.java +++ b/src/minecraft/biomesoplenty/configuration/BOPLiquids.java @@ -1,48 +1,66 @@ package biomesoplenty.configuration; import net.minecraft.block.Block; -import net.minecraft.block.material.Material; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.liquids.LiquidContainerData; +import net.minecraftforge.liquids.LiquidContainerRegistry; +import net.minecraftforge.liquids.LiquidDictionary; import net.minecraftforge.liquids.LiquidStack; -import biomesoplenty.api.Blocks; -import biomesoplenty.items.ItemBOPMud; +import biomesoplenty.items.ItemBOPBucket; import biomesoplenty.liquids.BlockSpringWaterFlowing; import biomesoplenty.liquids.BlockSpringWaterStill; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; -public class BOPLiquids { - +public class BOPLiquids +{ public static Block springWaterFlowing; public static Block springWaterStill; public static Item bucketSpringWater; public static LiquidStack springWaterLiquid; - + public static void init() { initializeLiquids(); + initializeContainers(); registerLiquids(); - registerNames(); + registerContainerNames(); + registerLiquidNames(); } - + private static void initializeLiquids() { springWaterFlowing = (new BlockSpringWaterFlowing(BOPConfiguration.springWaterStillID - 1).setUnlocalizedName("springWaterFlowing")); springWaterStill = (new BlockSpringWaterStill(BOPConfiguration.springWaterStillID).setUnlocalizedName("springWaterStill")); + + springWaterLiquid = LiquidDictionary.getOrCreateLiquid("Spring Water", new LiquidStack(springWaterStill, 1)); } - + + private static void initializeContainers() + { + bucketSpringWater = (new ItemBOPBucket(BOPConfiguration.springWaterBucketID, springWaterStill.blockID)).setMaxStackSize(1).setUnlocalizedName("bucketSpringWater").setContainerItem(Item.bucketEmpty); + + LiquidContainerRegistry.registerLiquid(new LiquidContainerData(LiquidDictionary.getLiquid("Spring Water", LiquidContainerRegistry.BUCKET_VOLUME), new ItemStack(bucketSpringWater), new ItemStack(Item.bucketEmpty))); + } + private static void registerLiquids() { - GameRegistry.registerBlock(springWaterFlowing, "springWaterFlowing"); - GameRegistry.registerBlock(springWaterStill, "springWaterStill"); + GameRegistry.registerBlock(springWaterFlowing, "springWaterFlowing"); + GameRegistry.registerBlock(springWaterStill, "springWaterStill"); } - - private static void registerNames() + + private static void registerContainerNames() { - LanguageRegistry.addName(springWaterFlowing, "Spring Water"); - LanguageRegistry.addName(springWaterStill, "Spring Water"); + LanguageRegistry.addName(bucketSpringWater, "Spring Water Bucket"); + } + + private static void registerLiquidNames() + { + LanguageRegistry.addName(springWaterFlowing, "Spring Water"); + LanguageRegistry.addName(springWaterStill, "Spring Water"); } } diff --git a/src/minecraft/biomesoplenty/helpers/BOPBucketHelper.java b/src/minecraft/biomesoplenty/helpers/BOPBucketHelper.java new file mode 100644 index 000000000..bde741fc5 --- /dev/null +++ b/src/minecraft/biomesoplenty/helpers/BOPBucketHelper.java @@ -0,0 +1,42 @@ +package biomesoplenty.helpers; + +import biomesoplenty.configuration.BOPLiquids; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import net.minecraftforge.event.Event.Result; +import net.minecraftforge.event.ForgeSubscribe; +import net.minecraftforge.event.entity.player.FillBucketEvent; + +public class BOPBucketHelper +{ + @ForgeSubscribe + public void onBucketFill(FillBucketEvent event) + { + ItemStack result = fillCustomBucket(event.world, event.target); + + if (result == null) + { + return; + } + + event.result = result; + event.setResult(Result.ALLOW); + } + + public ItemStack fillCustomBucket(World world, MovingObjectPosition pos) + { + int blockID = world.getBlockId(pos.blockX, pos.blockY, pos.blockZ); + + if ((blockID == BOPLiquids.springWaterStill.blockID || blockID == BOPLiquids.springWaterFlowing.blockID) && world.getBlockMetadata(pos.blockX, pos.blockY, pos.blockZ) == 0) + { + world.setBlock(pos.blockX, pos.blockY, pos.blockZ, 0); + + return new ItemStack(BOPLiquids.bucketSpringWater); + } + else + { + return null; + } + } +} diff --git a/src/minecraft/biomesoplenty/items/ItemBOPBucket.java b/src/minecraft/biomesoplenty/items/ItemBOPBucket.java new file mode 100644 index 000000000..223af9972 --- /dev/null +++ b/src/minecraft/biomesoplenty/items/ItemBOPBucket.java @@ -0,0 +1,25 @@ +package biomesoplenty.items; + +import biomesoplenty.BiomesOPlenty; +import net.minecraft.client.renderer.texture.IconRegister; +import net.minecraft.item.ItemBucket; +import net.minecraft.item.ItemStack; +import net.minecraft.util.StringUtils; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class ItemBOPBucket extends ItemBucket +{ + public ItemBOPBucket(int i, int liquidID) + { + super(i, liquidID); + this.setCreativeTab(BiomesOPlenty.tabBiomesOPlenty); + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IconRegister par1IconRegister) + { + this.itemIcon = par1IconRegister.registerIcon("BiomesOPlenty:spring_water_bucket"); + } +} diff --git a/src/minecraft/biomesoplenty/liquids/BlockSpringWaterFlowing.java b/src/minecraft/biomesoplenty/liquids/BlockSpringWaterFlowing.java index be765b70d..d0c822a62 100644 --- a/src/minecraft/biomesoplenty/liquids/BlockSpringWaterFlowing.java +++ b/src/minecraft/biomesoplenty/liquids/BlockSpringWaterFlowing.java @@ -20,7 +20,7 @@ public class BlockSpringWaterFlowing extends BlockFlowing super(id, Material.water); this.blockHardness = 100F; - this.setLightOpacity(3); + this.setLightOpacity(0); this.setCreativeTab(BiomesOPlenty.tabBiomesOPlenty); } diff --git a/src/minecraft/biomesoplenty/liquids/BlockSpringWaterStill.java b/src/minecraft/biomesoplenty/liquids/BlockSpringWaterStill.java index 7f563e7a0..40e4c446a 100644 --- a/src/minecraft/biomesoplenty/liquids/BlockSpringWaterStill.java +++ b/src/minecraft/biomesoplenty/liquids/BlockSpringWaterStill.java @@ -21,11 +21,25 @@ public class BlockSpringWaterStill extends BlockStationary super(id, Material.water); this.blockHardness = 100F; - this.setLightOpacity(3); + this.setLightOpacity(0); this.setCreativeTab(BiomesOPlenty.tabBiomesOPlenty); this.disableStats(); } + @Override + public void onBlockAdded(World par1World, int x, int y, int z) + { + this.setSpringWaterNotStationary(par1World, x, y, z);; + } + + public void setSpringWaterNotStationary(World par1World, int par2, int par3, int par4) + { + int l = par1World.getBlockMetadata(par2, par3, par4); + par1World.setBlock(par2, par3, par4, this.blockID - 1, l, 2); + par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID - 1, this.tickRate(par1World)); + } + + @Override public void onEntityCollidedWithBlock(World par1World, int x, int y, int z, Entity par5Entity) { diff --git a/src/minecraft/mods/BiomesOPlenty/textures/items/bucketFreshWater.png b/src/minecraft/mods/BiomesOPlenty/textures/items/spring_water_bucket.png similarity index 100% rename from src/minecraft/mods/BiomesOPlenty/textures/items/bucketFreshWater.png rename to src/minecraft/mods/BiomesOPlenty/textures/items/spring_water_bucket.png