Skip to content

Commit

Permalink
Changes to how PotionEffects are removed, now each PotionEffect can s…
Browse files Browse the repository at this point in the history
…pecify which ItemStacks can remove it's effect
  • Loading branch information
pahimar committed Sep 15, 2012
1 parent bb2ac4c commit 294b9fa
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 12 deletions.
57 changes: 45 additions & 12 deletions patches/common/net/minecraft/src/EntityLiving.java.patch
@@ -1,8 +1,10 @@
--- ../src_base/common/net/minecraft/src/EntityLiving.java
+++ ../src_work/common/net/minecraft/src/EntityLiving.java
@@ -7,6 +7,10 @@
@@ -6,7 +6,12 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map.Entry;
import java.util.Random;
+import net.minecraftforge.common.ForgeHooks;
+import net.minecraftforge.common.MinecraftForge;
Expand All @@ -11,23 +13,23 @@

public abstract class EntityLiving extends Entity
{
@@ -314,6 +318,7 @@
@@ -314,6 +319,7 @@
public void setAttackTarget(EntityLiving par1EntityLiving)
{
this.attackTarget = par1EntityLiving;
+ ForgeHooks.onLivingSetAttackTarget(this, par1EntityLiving);
}

public boolean isExplosiveMob(Class par1Class)
@@ -370,6 +375,7 @@
@@ -370,6 +376,7 @@
{
this.entityLivingToAttack = par1EntityLiving;
this.revengeTimer = this.entityLivingToAttack != null ? 60 : 0;
+ ForgeHooks.onLivingSetAttackTarget(this, par1EntityLiving);
}

protected void entityInit()
@@ -656,6 +662,11 @@
@@ -656,6 +663,11 @@
*/
public void onUpdate()
{
Expand All @@ -39,7 +41,7 @@
super.onUpdate();

if (this.arrowHitTempCounter > 0)
@@ -823,6 +834,11 @@
@@ -823,6 +835,11 @@
*/
public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
{
Expand All @@ -51,7 +53,7 @@
if (this.worldObj.isRemote)
{
return false;
@@ -1007,6 +1023,12 @@
@@ -1007,6 +1024,12 @@
*/
protected void damageEntity(DamageSource par1DamageSource, int par2)
{
Expand All @@ -64,7 +66,7 @@
par2 = this.applyArmorCalculations(par1DamageSource, par2);
par2 = this.applyPotionDamageCalculations(par1DamageSource, par2);
this.health -= par2;
@@ -1070,6 +1092,11 @@
@@ -1070,6 +1093,11 @@
*/
public void onDeath(DamageSource par1DamageSource)
{
Expand All @@ -76,7 +78,7 @@
Entity var2 = par1DamageSource.getEntity();

if (this.scoreValue >= 0 && var2 != null)
@@ -1093,13 +1120,17 @@
@@ -1093,13 +1121,17 @@
var3 = EnchantmentHelper.getLootingModifier(((EntityPlayer)var2).inventory);
}

Expand All @@ -95,7 +97,7 @@

if (var4 < 5)
{
@@ -1107,6 +1138,16 @@
@@ -1107,6 +1139,16 @@
}
}
}
Expand All @@ -112,7 +114,7 @@
}

this.worldObj.setEntityState(this, (byte)3);
@@ -1150,6 +1191,12 @@
@@ -1150,6 +1192,12 @@
*/
protected void fall(float par1)
{
Expand All @@ -125,7 +127,7 @@
super.fall(par1);
int var2 = MathHelper.ceiling_float_int(par1 - 3.0F);

@@ -1337,7 +1384,7 @@
@@ -1337,7 +1385,7 @@
int var2 = MathHelper.floor_double(this.boundingBox.minY);
int var3 = MathHelper.floor_double(this.posZ);
int var4 = this.worldObj.getBlockId(var1, var2, var3);
Expand All @@ -134,11 +136,42 @@
}

/**
@@ -1600,6 +1647,7 @@
@@ -1600,6 +1648,7 @@
}

this.isAirBorne = true;
+ ForgeHooks.onLivingJump(this);
}

/**
@@ -2175,4 +2224,30 @@
this.worldObj.spawnParticle("iconcrack_" + par1ItemStack.getItem().shiftedIndex, var4.xCoord, var4.yCoord, var4.zCoord, var3.xCoord, var3.yCoord + 0.05D, var3.zCoord);
}
}
+
+ /***
+ * Removes all potion effects that have curativeItem as a curative item for its effect
+ * @param curativeItem The itemstack we are using to cure potion effects
+ */
+ public void curePotionEffects(ItemStack curativeItem)
+ {
+ Iterator<Integer> potionKey = activePotionsMap.keySet().iterator();
+
+ if (!worldObj.isRemote)
+ {
+ return;
+ }
+
+ while (potionKey.hasNext())
+ {
+ Integer key = potionKey.next();
+ PotionEffect effect = (PotionEffect)activePotionsMap.get(key);
+
+ if (effect.isCurativeItem(curativeItem))
+ {
+ potionKey.remove();
+ onFinishedPotionEffect(effect);
+ }
+ }
+ }
}
18 changes: 18 additions & 0 deletions patches/common/net/minecraft/src/ItemBucketMilk.java.patch
@@ -0,0 +1,18 @@
--- ../src_base/common/net/minecraft/src/ItemBucketMilk.java
+++ ../src_work/common/net/minecraft/src/ItemBucketMilk.java
@@ -1,4 +1,6 @@
package net.minecraft.src;
+
+import java.util.HashMap;

public class ItemBucketMilk extends Item
{
@@ -18,7 +20,7 @@

if (!par2World.isRemote)
{
- par3EntityPlayer.clearActivePotions();
+ par3EntityPlayer.curePotionEffects(par1ItemStack);
}

return par1ItemStack.stackSize <= 0 ? new ItemStack(Item.bucketEmpty) : par1ItemStack;
100 changes: 100 additions & 0 deletions patches/common/net/minecraft/src/PotionEffect.java.patch
@@ -0,0 +1,100 @@
--- ../src_base/common/net/minecraft/src/PotionEffect.java
+++ ../src_work/common/net/minecraft/src/PotionEffect.java
@@ -1,4 +1,7 @@
package net.minecraft.src;
+
+import java.util.ArrayList;
+import java.util.List;

public class PotionEffect
{
@@ -10,12 +13,17 @@

/** The amplifier of the potion effect */
private int amplifier;
+
+ /** List of ItemStack that can cure the potion effect **/
+ private List<ItemStack> curativeItems;

public PotionEffect(int par1, int par2, int par3)
{
this.potionID = par1;
this.duration = par2;
this.amplifier = par3;
+ this.curativeItems = new ArrayList<ItemStack>();
+ this.curativeItems.add(new ItemStack(Item.bucketMilk));
}

public PotionEffect(PotionEffect par1PotionEffect)
@@ -23,6 +31,7 @@
this.potionID = par1PotionEffect.potionID;
this.duration = par1PotionEffect.duration;
this.amplifier = par1PotionEffect.amplifier;
+ this.curativeItems = par1PotionEffect.getCurativeItems();
}

/**
@@ -63,6 +72,63 @@
public int getAmplifier()
{
return this.amplifier;
+ }
+
+ /***
+ * Returns a list of curative items for the potion effect
+ * @return The list (ItemStack) of curative items for the potion effect
+ */
+ public List<ItemStack> getCurativeItems()
+ {
+ return this.curativeItems;
+ }
+
+ /***
+ * Checks the given ItemStack to see if it is in the list of curative items for the potion effect
+ * @param stack The ItemStack being checked against the list of curative items for the potion effect
+ * @return true if the given ItemStack is in the list of curative items for the potion effect, false otherwise
+ */
+ public boolean isCurativeItem(ItemStack stack)
+ {
+ boolean found = false;
+ for (ItemStack curativeItem : this.curativeItems)
+ {
+ if (curativeItem.isItemEqual(stack))
+ {
+ found = true;
+ }
+ }
+
+ return found;
+ }
+
+ /***
+ * Sets the array of curative items for the potion effect
+ * @param curativeItems The list of ItemStacks being set to the potion effect
+ */
+ public void setCurativeItems(List<ItemStack> curativeItems)
+ {
+ this.curativeItems = curativeItems;
+ }
+
+ /***
+ * Adds the given stack to list of curative items for the potion effect
+ * @param stack The ItemStack being added to the curative item list
+ */
+ public void addCurativeItem(ItemStack stack)
+ {
+ boolean found = false;
+ for (ItemStack curativeItem : this.curativeItems)
+ {
+ if (curativeItem.isItemEqual(stack))
+ {
+ found = true;
+ }
+ }
+ if (!found)
+ {
+ this.curativeItems.add(stack);
+ }
}

public boolean onUpdate(EntityLiving par1EntityLiving)

0 comments on commit 294b9fa

Please sign in to comment.