ForgePatch/patches/minecraft/net/minecraft/potion/PotionEffect.java.patch

123 lines
5.9 KiB
Diff
Raw Normal View History

--- a/net/minecraft/potion/PotionEffect.java
+++ b/net/minecraft/potion/PotionEffect.java
@@ -19,6 +19,8 @@
private boolean field_100013_f;
private boolean field_188421_h;
private boolean field_205349_i;
+ /** List of ItemStack that can cure the potion effect **/
+ private java.util.List<net.minecraft.item.ItemStack> curativeItems;
public PotionEffect(Potion p_i46811_1_) {
this(p_i46811_1_, 0, 0);
@@ -52,6 +54,7 @@
this.field_82724_e = p_i1577_1_.field_82724_e;
this.field_188421_h = p_i1577_1_.field_188421_h;
this.field_205349_i = p_i1577_1_.field_205349_i;
+ this.curativeItems = p_i1577_1_.curativeItems == null ? null : new java.util.ArrayList<net.minecraft.item.ItemStack>(p_i1577_1_.curativeItems);
}
public boolean func_199308_a(PotionEffect p_199308_1_) {
@@ -88,6 +91,10 @@
}
public Potion func_188419_a() {
+ return this.getPotionRaw() == null ? null : this.getPotionRaw().delegate.get();
+ }
+
+ private Potion getPotionRaw() {
return this.field_188420_b;
}
@@ -188,11 +195,12 @@
p_82719_1_.func_74757_a("Ambient", this.func_82720_e());
p_82719_1_.func_74757_a("ShowParticles", this.func_188418_e());
p_82719_1_.func_74757_a("ShowIcon", this.func_205348_f());
+ writeCurativeItems(p_82719_1_);
return p_82719_1_;
}
public static PotionEffect func_82722_b(NBTTagCompound p_82722_0_) {
- int i = p_82722_0_.func_74771_c("Id");
+ int i = p_82722_0_.func_74771_c("Id") & 0xFF;
Potion potion = Potion.func_188412_a(i);
if (potion == null) {
return null;
@@ -210,7 +218,7 @@
flag2 = p_82722_0_.func_74767_n("ShowIcon");
}
- return new PotionEffect(potion, k, j < 0 ? 0 : j, flag, flag1, flag2);
+ return readCurativeItems(new PotionEffect(potion, k, j < 0 ? 0 : j, flag, flag1, flag2), p_82722_0_);
}
}
@@ -226,6 +234,67 @@
public int compareTo(PotionEffect p_compareTo_1_) {
int i = 32147;
- return (this.func_76459_b() <= 32147 || p_compareTo_1_.func_76459_b() <= 32147) && (!this.func_82720_e() || !p_compareTo_1_.func_82720_e()) ? ComparisonChain.start().compare(this.func_82720_e(), p_compareTo_1_.func_82720_e()).compare(this.func_76459_b(), p_compareTo_1_.func_76459_b()).compare(this.func_188419_a().func_76401_j(), p_compareTo_1_.func_188419_a().func_76401_j()).result() : ComparisonChain.start().compare(this.func_82720_e(), p_compareTo_1_.func_82720_e()).compare(this.func_188419_a().func_76401_j(), p_compareTo_1_.func_188419_a().func_76401_j()).result();
+ return (this.func_76459_b() <= 32147 || p_compareTo_1_.func_76459_b() <= 32147) && (!this.func_82720_e() || !p_compareTo_1_.func_82720_e()) ? ComparisonChain.start().compare(this.func_82720_e(), p_compareTo_1_.func_82720_e()).compare(this.func_76459_b(), p_compareTo_1_.func_76459_b()).compare(this.func_188419_a().getGuiSortColor(this), p_compareTo_1_.func_188419_a().getGuiSortColor(this)).result() : ComparisonChain.start().compare(this.func_82720_e(), p_compareTo_1_.func_82720_e()).compare(this.func_188419_a().getGuiSortColor(this), p_compareTo_1_.func_188419_a().getGuiSortColor(this)).result();
}
+
+ /***
+ * Returns a list of curative items for the potion effect
+ * By default, this list is initialized using {@link Potion#getCurativeItems}
+ *
+ * @return The list (ItemStack) of curative items for the potion effect
+ */
+ public java.util.List<net.minecraft.item.ItemStack> getCurativeItems() {
+ if (this.curativeItems == null) { //Lazy load this so that we don't create a circular dep on Items.
+ this.curativeItems = func_188419_a().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 this PotionEffect
+ * @return true if the given ItemStack is in the list of curative items for this PotionEffect, false otherwise
+ */
+ public boolean isCurativeItem(net.minecraft.item.ItemStack stack) {
+ return this.getCurativeItems().stream().anyMatch(e -> e.func_77969_a(stack));
+ }
+
+ /***
+ * Sets the list of curative items for this potion effect, overwriting any already present
+ * @param curativeItems The list of ItemStacks being set to the potion effect
+ */
+ public void setCurativeItems(java.util.List<net.minecraft.item.ItemStack> curativeItems) {
+ this.curativeItems = curativeItems;
+ }
+
+ /***
+ * Adds the given stack to the list of curative items for this PotionEffect
+ * @param stack The ItemStack being added to the curative item list
+ */
+ public void addCurativeItem(net.minecraft.item.ItemStack stack) {
+ if (!this.isCurativeItem(stack)) {
+ this.getCurativeItems().add(stack);
+ }
+ }
+
+ private void writeCurativeItems(NBTTagCompound nbt) {
+ net.minecraft.nbt.NBTTagList list = new net.minecraft.nbt.NBTTagList();
+ for (net.minecraft.item.ItemStack stack : getCurativeItems()) {
+ list.add(stack.func_77955_b(new NBTTagCompound()));
+ }
+ nbt.func_74782_a("CurativeItems", list);
+ }
+
+ private static PotionEffect readCurativeItems(PotionEffect effect, NBTTagCompound nbt) {
+ if (nbt.func_150297_b("CurativeItems", net.minecraftforge.common.util.Constants.NBT.TAG_LIST)) {
+ java.util.List<net.minecraft.item.ItemStack> items = new java.util.ArrayList<net.minecraft.item.ItemStack>();
+ net.minecraft.nbt.NBTTagList list = nbt.func_150295_c("CurativeItems", net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND);
+ for (int i = 0; i < list.size(); i++) {
+ items.add(net.minecraft.item.ItemStack.func_199557_a(list.func_150305_b(i)));
+ }
+ effect.setCurativeItems(items);
+ }
+
+ return effect;
+ }
}