Finished off the custom Potion Effect for Spring Water, just needs an Icon now

This commit is contained in:
Adubbz 2013-05-25 18:57:21 +10:00
parent 76c6aa27ec
commit 167c9cb52c
10 changed files with 185 additions and 4 deletions

View file

@ -17,10 +17,12 @@ import biomesoplenty.configuration.BOPCrafting;
import biomesoplenty.configuration.BOPEntities; import biomesoplenty.configuration.BOPEntities;
import biomesoplenty.configuration.BOPItems; import biomesoplenty.configuration.BOPItems;
import biomesoplenty.configuration.BOPLiquids; import biomesoplenty.configuration.BOPLiquids;
import biomesoplenty.configuration.BOPPotions;
import biomesoplenty.configuration.BOPReflection;
import biomesoplenty.configuration.BOPVanillaCompat; import biomesoplenty.configuration.BOPVanillaCompat;
import biomesoplenty.helpers.AchievementHelper; import biomesoplenty.helpers.AchievementHelper;
import biomesoplenty.helpers.BOPBucketHelper;
import biomesoplenty.helpers.BOPCraft; import biomesoplenty.helpers.BOPCraft;
import biomesoplenty.helpers.BOPLiquidHelper;
import biomesoplenty.helpers.BonemealUse; import biomesoplenty.helpers.BonemealUse;
import biomesoplenty.helpers.CreativeTabsBOP; import biomesoplenty.helpers.CreativeTabsBOP;
import biomesoplenty.helpers.EntitiesHelper; import biomesoplenty.helpers.EntitiesHelper;
@ -95,6 +97,10 @@ public class BiomesOPlenty
tabBiomesOPlenty = new CreativeTabsBOP(CreativeTabs.getNextID(),"tabBiomesOPlenty"); tabBiomesOPlenty = new CreativeTabsBOP(CreativeTabs.getNextID(),"tabBiomesOPlenty");
BOPReflection.init();
BOPPotions.init();
BOPBlocks.init(); BOPBlocks.init();
BOPItems.init(); BOPItems.init();
@ -129,7 +135,7 @@ public class BiomesOPlenty
MinecraftForge.EVENT_BUS.register(new AchievementHelper()); MinecraftForge.EVENT_BUS.register(new AchievementHelper());
MinecraftForge.EVENT_BUS.register(new BonemealUse()); MinecraftForge.EVENT_BUS.register(new BonemealUse());
MinecraftForge.EVENT_BUS.register(new EntitiesHelper()); MinecraftForge.EVENT_BUS.register(new EntitiesHelper());
MinecraftForge.EVENT_BUS.register(new BOPBucketHelper()); MinecraftForge.EVENT_BUS.register(new BOPLiquidHelper());
proxy.registerRenderers(); proxy.registerRenderers();

View file

@ -1,9 +1,11 @@
package biomesoplenty.configuration; package biomesoplenty.configuration;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; 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.LiquidContainerData;
import net.minecraftforge.liquids.LiquidContainerRegistry; import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidDictionary; import net.minecraftforge.liquids.LiquidDictionary;
@ -13,6 +15,8 @@ import biomesoplenty.liquids.BlockSpringWaterFlowing;
import biomesoplenty.liquids.BlockSpringWaterStill; import biomesoplenty.liquids.BlockSpringWaterStill;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry; import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BOPLiquids public class BOPLiquids
{ {

View file

@ -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");
}
}

View file

@ -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);
}
}
}
}

View file

@ -1,15 +1,26 @@
package biomesoplenty.helpers; package biomesoplenty.helpers;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import biomesoplenty.configuration.BOPLiquids; import biomesoplenty.configuration.BOPLiquids;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.event.Event.Result; import net.minecraftforge.event.Event.Result;
import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.player.FillBucketEvent; 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 @ForgeSubscribe
public void onBucketFill(FillBucketEvent event) public void onBucketFill(FillBucketEvent event)
{ {

View file

@ -5,11 +5,14 @@ import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.potion.Potion; import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect; import net.minecraft.potion.PotionEffect;
import net.minecraft.util.Icon; import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import biomesoplenty.BiomesOPlenty; import biomesoplenty.BiomesOPlenty;
import biomesoplenty.configuration.BOPPotions;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@ -23,6 +26,12 @@ public class BlockSpringWaterFlowing extends BlockFlowing
this.setLightOpacity(0); this.setLightOpacity(0);
} }
@Override
public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
{
return 16777215;
}
@Override @Override
public void onEntityCollidedWithBlock(World par1World, int x, int y, int z, Entity par5Entity) 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) if (par5Entity instanceof EntityLiving)
((EntityLiving)par5Entity).addPotionEffect(new PotionEffect(Potion.regeneration.id, 1)); ((EntityLiving)par5Entity).addPotionEffect(new PotionEffect(Potion.regeneration.id, 1));
if (par5Entity instanceof EntityPlayer)
((EntityPlayer)par5Entity).addPotionEffect(new PotionEffect(BOPPotions.nourishment.id, 1));
} }
@Override @Override

View file

@ -7,12 +7,15 @@ import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.potion.Potion; import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect; import net.minecraft.potion.PotionEffect;
import net.minecraft.util.Icon; import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import biomesoplenty.BiomesOPlenty; import biomesoplenty.BiomesOPlenty;
import biomesoplenty.configuration.BOPPotions;
public class BlockSpringWaterStill extends BlockStationary public class BlockSpringWaterStill extends BlockStationary
{ {
@ -25,6 +28,12 @@ public class BlockSpringWaterStill extends BlockStationary
this.disableStats(); this.disableStats();
} }
@Override
public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
{
return 16777215;
}
@Override @Override
public void onBlockAdded(World par1World, int x, int y, int z) public void onBlockAdded(World par1World, int x, int y, int z)
{ {
@ -46,6 +55,9 @@ public class BlockSpringWaterStill extends BlockStationary
if (par5Entity instanceof EntityLiving) if (par5Entity instanceof EntityLiving)
((EntityLiving)par5Entity).addPotionEffect(new PotionEffect(Potion.regeneration.id, 1)); ((EntityLiving)par5Entity).addPotionEffect(new PotionEffect(Potion.regeneration.id, 1));
if (par5Entity instanceof EntityPlayer)
((EntityPlayer)par5Entity).addPotionEffect(new PotionEffect(BOPPotions.nourishment.id, 1));
} }
@Override @Override

View file

@ -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;
}
}
}
}

View file

@ -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;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB