From f19fed085316bcd840468e87f452b4165c573642 Mon Sep 17 00:00:00 2001 From: Ben Staddon Date: Fri, 4 Jan 2019 04:02:11 +0000 Subject: [PATCH] Add redirects to PotionEffect to respect registry replacement (#5213) --- .../minecraft/potion/PotionEffect.java.patch | 17 +++++++++-- .../common/asm/FieldRedirectTransformer.java | 1 + .../common/asm/PotionEffectTransformer.java | 29 +++++++++++++++++++ ...odlauncher.serviceapi.ILaunchPluginService | 1 + .../debug/mod/RegistryOverrideTest.java | 18 ++++++++++++ 5 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 src/fmllauncher/java/net/minecraftforge/common/asm/PotionEffectTransformer.java diff --git a/patches/minecraft/net/minecraft/potion/PotionEffect.java.patch b/patches/minecraft/net/minecraft/potion/PotionEffect.java.patch index 5a7f26048c..9a39cf0095 100644 --- a/patches/minecraft/net/minecraft/potion/PotionEffect.java.patch +++ b/patches/minecraft/net/minecraft/potion/PotionEffect.java.patch @@ -17,7 +17,18 @@ } public boolean func_199308_a(PotionEffect p_199308_1_) { -@@ -188,11 +191,12 @@ +@@ -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()); @@ -31,7 +42,7 @@ Potion potion = Potion.func_188412_a(i); if (potion == null) { return null; -@@ -210,7 +214,7 @@ +@@ -210,7 +218,7 @@ flag2 = p_82722_0_.func_74767_n("ShowIcon"); } @@ -40,7 +51,7 @@ } } -@@ -226,6 +230,67 @@ +@@ -226,6 +234,67 @@ public int compareTo(PotionEffect p_compareTo_1_) { int i = 32147; diff --git a/src/fmllauncher/java/net/minecraftforge/common/asm/FieldRedirectTransformer.java b/src/fmllauncher/java/net/minecraftforge/common/asm/FieldRedirectTransformer.java index 27724e2ee3..d1c03669b5 100644 --- a/src/fmllauncher/java/net/minecraftforge/common/asm/FieldRedirectTransformer.java +++ b/src/fmllauncher/java/net/minecraftforge/common/asm/FieldRedirectTransformer.java @@ -33,6 +33,7 @@ import org.objectweb.asm.tree.MethodNode; import cpw.mods.modlauncher.serviceapi.ILaunchPluginService; +@Deprecated // TODO as this only targets a single class, it can be moved to a JS coremod public abstract class FieldRedirectTransformer implements ILaunchPluginService { private final String clsName; diff --git a/src/fmllauncher/java/net/minecraftforge/common/asm/PotionEffectTransformer.java b/src/fmllauncher/java/net/minecraftforge/common/asm/PotionEffectTransformer.java new file mode 100644 index 0000000000..7a37fb03b6 --- /dev/null +++ b/src/fmllauncher/java/net/minecraftforge/common/asm/PotionEffectTransformer.java @@ -0,0 +1,29 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2018. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.common.asm; + +@Deprecated +public class PotionEffectTransformer extends FieldRedirectTransformer +{ + public PotionEffectTransformer() + { + super("net.minecraft.potion.PotionEffect", "Lnet/minecraft/potion/Potion;", "getPotionRaw"); + } +} diff --git a/src/fmllauncher/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ILaunchPluginService b/src/fmllauncher/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ILaunchPluginService index 502278a9a3..7bfa2bf82f 100644 --- a/src/fmllauncher/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ILaunchPluginService +++ b/src/fmllauncher/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ILaunchPluginService @@ -2,3 +2,4 @@ net.minecraftforge.fml.loading.RuntimeDistCleaner net.minecraftforge.common.asm.RuntimeEnumExtender net.minecraftforge.common.asm.ObjectHolderDefinalize net.minecraftforge.common.asm.CapabilityInjectDefinalize +net.minecraftforge.common.asm.PotionEffectTransformer diff --git a/src/test/java/net/minecraftforge/debug/mod/RegistryOverrideTest.java b/src/test/java/net/minecraftforge/debug/mod/RegistryOverrideTest.java index b4dd2ae082..204f9d0408 100644 --- a/src/test/java/net/minecraftforge/debug/mod/RegistryOverrideTest.java +++ b/src/test/java/net/minecraftforge/debug/mod/RegistryOverrideTest.java @@ -26,6 +26,8 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionType; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.AxisAlignedBB; @@ -75,6 +77,22 @@ public class RegistryOverrideTest } } + @SubscribeEvent + public static void registerPotions(RegistryEvent.Register event) + { + if (ENABLED) + { + event.getRegistry().register(new Potion(true, 0x00ffff) + { + { + setPotionName("effect.poison"); + setIconIndex(6, 0); + setEffectiveness(0.25D); + } + }.setRegistryName("minecraft:poison")); + } + } + private static class BlockReplacement extends Block { AxisAlignedBB BB = FULL_BLOCK_AABB.contract(0.1, 0, 0.1);