From 167c9cb52cb751c23c10090cfe524a641713d621 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Sat, 25 May 2013 18:57:21 +1000 Subject: [PATCH] Finished off the custom Potion Effect for Spring Water, just needs an Icon now --- .../biomesoplenty/BiomesOPlenty.java | 10 +++- .../configuration/BOPLiquids.java | 6 ++- .../configuration/BOPPotions.java | 31 ++++++++++++ .../configuration/BOPReflection.java | 45 ++++++++++++++++++ ...BucketHelper.java => BOPLiquidHelper.java} | 13 ++++- .../liquids/BlockSpringWaterFlowing.java | 12 +++++ .../liquids/BlockSpringWaterStill.java | 12 +++++ .../potions/PotionEventHandler.java | 32 +++++++++++++ .../potions/PotionNourishment.java | 28 +++++++++++ .../textures/potions/BOPPotionFX.png | Bin 0 -> 1859 bytes 10 files changed, 185 insertions(+), 4 deletions(-) create mode 100644 src/minecraft/biomesoplenty/configuration/BOPPotions.java create mode 100644 src/minecraft/biomesoplenty/configuration/BOPReflection.java rename src/minecraft/biomesoplenty/helpers/{BOPBucketHelper.java => BOPLiquidHelper.java} (69%) create mode 100644 src/minecraft/biomesoplenty/potions/PotionEventHandler.java create mode 100644 src/minecraft/biomesoplenty/potions/PotionNourishment.java create mode 100644 src/minecraft/mods/BiomesOPlenty/textures/potions/BOPPotionFX.png diff --git a/src/minecraft/biomesoplenty/BiomesOPlenty.java b/src/minecraft/biomesoplenty/BiomesOPlenty.java index 0dbec1ed4..0aff2b45d 100644 --- a/src/minecraft/biomesoplenty/BiomesOPlenty.java +++ b/src/minecraft/biomesoplenty/BiomesOPlenty.java @@ -17,10 +17,12 @@ import biomesoplenty.configuration.BOPCrafting; import biomesoplenty.configuration.BOPEntities; import biomesoplenty.configuration.BOPItems; import biomesoplenty.configuration.BOPLiquids; +import biomesoplenty.configuration.BOPPotions; +import biomesoplenty.configuration.BOPReflection; import biomesoplenty.configuration.BOPVanillaCompat; import biomesoplenty.helpers.AchievementHelper; -import biomesoplenty.helpers.BOPBucketHelper; import biomesoplenty.helpers.BOPCraft; +import biomesoplenty.helpers.BOPLiquidHelper; import biomesoplenty.helpers.BonemealUse; import biomesoplenty.helpers.CreativeTabsBOP; import biomesoplenty.helpers.EntitiesHelper; @@ -94,6 +96,10 @@ public class BiomesOPlenty BOPConfiguration.init(event.getSuggestedConfigurationFile()); tabBiomesOPlenty = new CreativeTabsBOP(CreativeTabs.getNextID(),"tabBiomesOPlenty"); + + BOPReflection.init(); + + BOPPotions.init(); BOPBlocks.init(); @@ -129,7 +135,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()); + MinecraftForge.EVENT_BUS.register(new BOPLiquidHelper()); proxy.registerRenderers(); diff --git a/src/minecraft/biomesoplenty/configuration/BOPLiquids.java b/src/minecraft/biomesoplenty/configuration/BOPLiquids.java index 614cf5ee4..334b88528 100644 --- a/src/minecraft/biomesoplenty/configuration/BOPLiquids.java +++ b/src/minecraft/biomesoplenty/configuration/BOPLiquids.java @@ -1,9 +1,11 @@ package biomesoplenty.configuration; import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.client.event.TextureStitchEvent; +import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.liquids.LiquidContainerData; import net.minecraftforge.liquids.LiquidContainerRegistry; import net.minecraftforge.liquids.LiquidDictionary; @@ -13,6 +15,8 @@ import biomesoplenty.liquids.BlockSpringWaterFlowing; import biomesoplenty.liquids.BlockSpringWaterStill; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; public class BOPLiquids { diff --git a/src/minecraft/biomesoplenty/configuration/BOPPotions.java b/src/minecraft/biomesoplenty/configuration/BOPPotions.java new file mode 100644 index 000000000..0c44654c7 --- /dev/null +++ b/src/minecraft/biomesoplenty/configuration/BOPPotions.java @@ -0,0 +1,31 @@ +package biomesoplenty.configuration; + +import cpw.mods.fml.common.registry.LanguageRegistry; +import biomesoplenty.helpers.BOPLiquidHelper; +import biomesoplenty.potions.PotionEventHandler; +import biomesoplenty.potions.PotionNourishment; +import net.minecraft.potion.Potion; +import net.minecraftforge.common.MinecraftForge; + +public class BOPPotions +{ + public static Potion nourishment; + + public static void init() + { + intializePotions(); + registerPotionNames(); + + MinecraftForge.EVENT_BUS.register(new PotionEventHandler()); + } + + private static void intializePotions() + { + nourishment = (new PotionNourishment(32, false, 0)).setPotionName("potion.nourishment"); + } + + private static void registerPotionNames() + { + LanguageRegistry.instance().addStringLocalization("potion.nourishment", "en_US", "Nourishment"); + } +} diff --git a/src/minecraft/biomesoplenty/configuration/BOPReflection.java b/src/minecraft/biomesoplenty/configuration/BOPReflection.java new file mode 100644 index 000000000..9aef949cd --- /dev/null +++ b/src/minecraft/biomesoplenty/configuration/BOPReflection.java @@ -0,0 +1,45 @@ +package biomesoplenty.configuration; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; + +import net.minecraft.potion.Potion; +import net.minecraftforge.common.MinecraftForge; + +public class BOPReflection +{ + public static void init() + { + potionReflection(); + } + + private static void potionReflection() + { + Potion[] potionTypes = null; + + for (Field f : Potion.class.getDeclaredFields()) + { + f.setAccessible(true); + + try + { + if (f.getName().equals("potionTypes") || f.getName().equals("field_76425_a")) + { + Field modfield = Field.class.getDeclaredField("modifiers"); + modfield.setAccessible(true); + modfield.setInt(f, f.getModifiers() & ~Modifier.FINAL); + + potionTypes = (Potion[])f.get(null); + final Potion[] newPotionTypes = new Potion[256]; + System.arraycopy(potionTypes, 0, newPotionTypes, 0, potionTypes.length); + f.set(null, newPotionTypes); + } + } + catch (Exception e) + { + System.err.println("Severe error, please report this to the mod author:"); + System.err.println(e); + } + } + } +} diff --git a/src/minecraft/biomesoplenty/helpers/BOPBucketHelper.java b/src/minecraft/biomesoplenty/helpers/BOPLiquidHelper.java similarity index 69% rename from src/minecraft/biomesoplenty/helpers/BOPBucketHelper.java rename to src/minecraft/biomesoplenty/helpers/BOPLiquidHelper.java index bde741fc5..8d08f79dc 100644 --- a/src/minecraft/biomesoplenty/helpers/BOPBucketHelper.java +++ b/src/minecraft/biomesoplenty/helpers/BOPLiquidHelper.java @@ -1,15 +1,26 @@ package biomesoplenty.helpers; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import biomesoplenty.configuration.BOPLiquids; import net.minecraft.item.ItemStack; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; +import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.event.Event.Result; import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.entity.player.FillBucketEvent; +import net.minecraftforge.liquids.LiquidDictionary; -public class BOPBucketHelper +public class BOPLiquidHelper { + @ForgeSubscribe + @SideOnly(Side.CLIENT) + public void textureHook(TextureStitchEvent.Post event) + { + LiquidDictionary.getCanonicalLiquid("Spring Water").setRenderingIcon(BOPLiquids.springWaterStill.getBlockTextureFromSide(1)).setTextureSheet("/terrain.png"); + } + @ForgeSubscribe public void onBucketFill(FillBucketEvent event) { diff --git a/src/minecraft/biomesoplenty/liquids/BlockSpringWaterFlowing.java b/src/minecraft/biomesoplenty/liquids/BlockSpringWaterFlowing.java index 27d8f8098..9a2c15c86 100644 --- a/src/minecraft/biomesoplenty/liquids/BlockSpringWaterFlowing.java +++ b/src/minecraft/biomesoplenty/liquids/BlockSpringWaterFlowing.java @@ -5,11 +5,14 @@ import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.Icon; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import biomesoplenty.BiomesOPlenty; +import biomesoplenty.configuration.BOPPotions; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -23,6 +26,12 @@ public class BlockSpringWaterFlowing extends BlockFlowing this.setLightOpacity(0); } + @Override + public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) + { + return 16777215; + } + @Override public void onEntityCollidedWithBlock(World par1World, int x, int y, int z, Entity par5Entity) { @@ -30,6 +39,9 @@ public class BlockSpringWaterFlowing extends BlockFlowing if (par5Entity instanceof EntityLiving) ((EntityLiving)par5Entity).addPotionEffect(new PotionEffect(Potion.regeneration.id, 1)); + + if (par5Entity instanceof EntityPlayer) + ((EntityPlayer)par5Entity).addPotionEffect(new PotionEffect(BOPPotions.nourishment.id, 1)); } @Override diff --git a/src/minecraft/biomesoplenty/liquids/BlockSpringWaterStill.java b/src/minecraft/biomesoplenty/liquids/BlockSpringWaterStill.java index dd128a1c1..767c64cd5 100644 --- a/src/minecraft/biomesoplenty/liquids/BlockSpringWaterStill.java +++ b/src/minecraft/biomesoplenty/liquids/BlockSpringWaterStill.java @@ -7,12 +7,15 @@ import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.Icon; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import biomesoplenty.BiomesOPlenty; +import biomesoplenty.configuration.BOPPotions; public class BlockSpringWaterStill extends BlockStationary { @@ -25,6 +28,12 @@ public class BlockSpringWaterStill extends BlockStationary this.disableStats(); } + @Override + public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) + { + return 16777215; + } + @Override public void onBlockAdded(World par1World, int x, int y, int z) { @@ -46,6 +55,9 @@ public class BlockSpringWaterStill extends BlockStationary if (par5Entity instanceof EntityLiving) ((EntityLiving)par5Entity).addPotionEffect(new PotionEffect(Potion.regeneration.id, 1)); + + if (par5Entity instanceof EntityPlayer) + ((EntityPlayer)par5Entity).addPotionEffect(new PotionEffect(BOPPotions.nourishment.id, 1)); } @Override diff --git a/src/minecraft/biomesoplenty/potions/PotionEventHandler.java b/src/minecraft/biomesoplenty/potions/PotionEventHandler.java new file mode 100644 index 000000000..899a9dc11 --- /dev/null +++ b/src/minecraft/biomesoplenty/potions/PotionEventHandler.java @@ -0,0 +1,32 @@ +package biomesoplenty.potions; + +import biomesoplenty.configuration.BOPPotions; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraftforge.event.ForgeSubscribe; +import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; + +public class PotionEventHandler +{ + @ForgeSubscribe + public void onEntityUpdate(LivingUpdateEvent event) + { + if (event.entityLiving.isPotionActive(BOPPotions.nourishment)) + { + if (event.entityLiving.worldObj.rand.nextInt(350) == 0) + { + if (!event.entityLiving.worldObj.isRemote) + if (event.entityLiving instanceof EntityPlayer) + ((EntityPlayer)event.entityLiving).getFoodStats().addStats(1, 0); + } + + if (event.entityLiving.getActivePotionEffect(BOPPotions.nourishment).getDuration() == 0) + { + event.entityLiving.removePotionEffect(BOPPotions.nourishment.id); + return; + } + } + } +} diff --git a/src/minecraft/biomesoplenty/potions/PotionNourishment.java b/src/minecraft/biomesoplenty/potions/PotionNourishment.java new file mode 100644 index 000000000..d38bacc58 --- /dev/null +++ b/src/minecraft/biomesoplenty/potions/PotionNourishment.java @@ -0,0 +1,28 @@ +package biomesoplenty.potions; + +import net.minecraft.client.Minecraft; +import net.minecraft.potion.Potion; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class PotionNourishment extends Potion +{ + public PotionNourishment(int par1, boolean par2, int par3) + { + super(par1, par2, par3); + this.setIconIndex(0, 0); + } + + @SideOnly(Side.CLIENT) + public int getStatusIconIndex() + { + Minecraft.getMinecraft().renderEngine.bindTexture("/mods/BiomesOPlenty/textures/potions/BOPPotionFX.png"); + return 0; + } + + @Override + public boolean isReady(int par1, int par2) + { + return par1 >= 1; + } +} \ No newline at end of file diff --git a/src/minecraft/mods/BiomesOPlenty/textures/potions/BOPPotionFX.png b/src/minecraft/mods/BiomesOPlenty/textures/potions/BOPPotionFX.png new file mode 100644 index 0000000000000000000000000000000000000000..686c2e74c4647fa4664ea8e534cda9ca788cfcab GIT binary patch literal 1859 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K58911MRQ8&P5Fo{p?&#~tz_78O`%fY(0|PTd zfKP}kP&|&Ia}&dVAY&AahQLS*fisgoNPsd*NswRg|B($Cg1@t?0^^^vz$3Dlfr0M; z2s36~>*NFqN|m@qlmzFem6RtIr7{F0X6BXX`MHKDlo{)p>KPgsd?{MUz`(TJ)5S5Q zBJS;M!z>m@o&%Hq{69b4ErBENIE#uYllixd-Oay$ozP^s7R0b-DMN%epNB#oU7HlB@|IKYS>xh)}yz>c$vhV^bp|H;uD= zZXkmgKfio?d+MRsbdiRmhYufrm^hPk<$sl2em;D7{pew%hwF^F4m^7J@bQNYK099b zFm0%)_+eqABmB;4F@uhroE;zk>6YE+G#I+u+xribqx_d^$EU-G*LPFuWFi9O%XUjp dsyp@kGq+eTE61tb7c@boou{jx%Q~loCIB0$I7$Ej literal 0 HcmV?d00001