From 4e11c95d0e0f657273bbfcf336ccb405101b0838 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 | 20 ++++++++++--- .../transformers/PotionEffectTransformer.java | 28 +++++++++++++++++++ .../fml/common/launcher/FMLDeobfTweaker.java | 1 + .../debug/mod/RegistryOverrideTest.java | 17 +++++++++++ 4 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 src/main/java/net/minecraftforge/fml/common/asm/transformers/PotionEffectTransformer.java diff --git a/patches/minecraft/net/minecraft/potion/PotionEffect.java.patch b/patches/minecraft/net/minecraft/potion/PotionEffect.java.patch index 346bced079..c97ec352d1 100644 --- a/patches/minecraft/net/minecraft/potion/PotionEffect.java.patch +++ b/patches/minecraft/net/minecraft/potion/PotionEffect.java.patch @@ -17,7 +17,19 @@ } public void func_76452_a(PotionEffect p_76452_1_) -@@ -195,12 +198,13 @@ +@@ -79,6 +82,11 @@ + + public Potion func_188419_a() + { ++ return this.getPotionRaw() == null ? null : this.getPotionRaw().delegate.get(); ++ } ++ ++ private Potion getPotionRaw() ++ { + return this.field_188420_b; + } + +@@ -195,12 +203,13 @@ p_82719_1_.func_74768_a("Duration", this.func_76459_b()); p_82719_1_.func_74757_a("Ambient", this.func_82720_e()); p_82719_1_.func_74757_a("ShowParticles", this.func_188418_e()); @@ -32,7 +44,7 @@ Potion potion = Potion.func_188412_a(i); if (potion == null) -@@ -219,7 +223,7 @@ +@@ -219,7 +228,7 @@ flag1 = p_82722_0_.func_74767_n("ShowParticles"); } @@ -41,7 +53,7 @@ } } -@@ -232,7 +236,7 @@ +@@ -232,7 +241,7 @@ public int compareTo(PotionEffect p_compareTo_1_) { int i = 32147; @@ -50,7 +62,7 @@ } @SideOnly(Side.CLIENT) -@@ -240,4 +244,85 @@ +@@ -240,4 +249,85 @@ { return this.field_100013_f; } diff --git a/src/main/java/net/minecraftforge/fml/common/asm/transformers/PotionEffectTransformer.java b/src/main/java/net/minecraftforge/fml/common/asm/transformers/PotionEffectTransformer.java new file mode 100644 index 0000000000..934fe594d0 --- /dev/null +++ b/src/main/java/net/minecraftforge/fml/common/asm/transformers/PotionEffectTransformer.java @@ -0,0 +1,28 @@ +/* + * 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.fml.common.asm.transformers; + +public class PotionEffectTransformer extends FieldRedirectTransformer +{ + public PotionEffectTransformer() + { + super("net.minecraft.potion.PotionEffect", "Lnet/minecraft/potion/Potion;", "getPotionRaw"); + } +} diff --git a/src/main/java/net/minecraftforge/fml/common/launcher/FMLDeobfTweaker.java b/src/main/java/net/minecraftforge/fml/common/launcher/FMLDeobfTweaker.java index ad6e07035b..4b9917ea37 100644 --- a/src/main/java/net/minecraftforge/fml/common/launcher/FMLDeobfTweaker.java +++ b/src/main/java/net/minecraftforge/fml/common/launcher/FMLDeobfTweaker.java @@ -49,6 +49,7 @@ public class FMLDeobfTweaker implements ITweaker { classLoader.registerTransformer("net.minecraftforge.fml.common.asm.transformers.ItemStackTransformer"); classLoader.registerTransformer("net.minecraftforge.fml.common.asm.transformers.ItemBlockTransformer"); classLoader.registerTransformer("net.minecraftforge.fml.common.asm.transformers.ItemBlockSpecialTransformer"); + classLoader.registerTransformer("net.minecraftforge.fml.common.asm.transformers.PotionEffectTransformer"); try { FMLLog.log.debug("Validating minecraft"); diff --git a/src/test/java/net/minecraftforge/debug/mod/RegistryOverrideTest.java b/src/test/java/net/minecraftforge/debug/mod/RegistryOverrideTest.java index 07727e30e3..28d0b72155 100644 --- a/src/test/java/net/minecraftforge/debug/mod/RegistryOverrideTest.java +++ b/src/test/java/net/minecraftforge/debug/mod/RegistryOverrideTest.java @@ -26,6 +26,7 @@ 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; @@ -76,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);