From 4bfe562f14a1911e1d09ba1797cda2f82bb44481 Mon Sep 17 00:00:00 2001 From: eerussianguy <59940116+eerussianguy@users.noreply.github.com> Date: Tue, 8 Feb 2022 14:55:25 -0500 Subject: [PATCH] Fix #8298 (MobBucketItem) and add test mod (#8313) --- .../world/item/MobBucketItem.java.patch | 53 +++++++++++----- .../resources/coremods/field_to_method.js | 12 ---- .../debug/item/CustomMobBucketTest.java | 57 ++++++++++++++++++ src/test/resources/META-INF/mods.toml | 2 + .../models/item/cow_bucket.json | 6 ++ .../textures/item/cow_bucket.png | Bin 0 -> 6299 bytes 6 files changed, 102 insertions(+), 28 deletions(-) create mode 100644 src/test/java/net/minecraftforge/debug/item/CustomMobBucketTest.java create mode 100644 src/test/resources/assets/custom_mob_bucket_test/models/item/cow_bucket.json create mode 100644 src/test/resources/assets/custom_mob_bucket_test/textures/item/cow_bucket.png diff --git a/patches/minecraft/net/minecraft/world/item/MobBucketItem.java.patch b/patches/minecraft/net/minecraft/world/item/MobBucketItem.java.patch index cbe5f037ce..ffd239d636 100644 --- a/patches/minecraft/net/minecraft/world/item/MobBucketItem.java.patch +++ b/patches/minecraft/net/minecraft/world/item/MobBucketItem.java.patch @@ -1,40 +1,61 @@ --- a/net/minecraft/world/item/MobBucketItem.java +++ b/net/minecraft/world/item/MobBucketItem.java -@@ -25,11 +_,24 @@ +@@ -23,13 +_,18 @@ + import net.minecraft.world.level.material.Fluid; + public class MobBucketItem extends BucketItem { - private final EntityType f_151134_; - private final SoundEvent f_151135_; -+ private final java.util.function.Supplier> fishTypeSupplier; +- private final EntityType f_151134_; +- private final SoundEvent f_151135_; ++ private final java.util.function.Supplier> entityTypeSupplier; + private final java.util.function.Supplier emptySoundSupplier; + @Deprecated public MobBucketItem(EntityType p_151137_, Fluid p_151138_, SoundEvent p_151139_, Item.Properties p_151140_) { - super(p_151138_, p_151140_); - this.f_151134_ = p_151137_; - this.f_151135_ = p_151139_; -+ this.emptySoundSupplier = null; -+ this.fishTypeSupplier = () -> p_151137_; +- super(p_151138_, p_151140_); +- this.f_151134_ = p_151137_; +- this.f_151135_ = p_151139_; ++ this(() -> p_151137_, () -> p_151138_, () -> p_151139_, p_151140_); + } + + public MobBucketItem(java.util.function.Supplier> entitySupplier, java.util.function.Supplier fluidSupplier, java.util.function.Supplier soundSupplier, Item.Properties properties) { + super(fluidSupplier, properties); -+ this.f_151134_ = null; -+ this.f_151135_ = null; + this.emptySoundSupplier = soundSupplier; -+ this.fishTypeSupplier = entitySupplier; ++ this.entityTypeSupplier = entitySupplier; } public void m_142131_(@Nullable Player p_151146_, Level p_151147_, ItemStack p_151148_, BlockPos p_151149_) { -@@ -80,6 +_,14 @@ - p_151157_.add(mutablecomponent); +@@ -41,11 +_,11 @@ + } + + protected void m_7718_(@Nullable Player p_151151_, LevelAccessor p_151152_, BlockPos p_151153_) { +- p_151152_.m_5594_(p_151151_, p_151153_, this.f_151135_, SoundSource.NEUTRAL, 1.0F, 1.0F); ++ p_151152_.m_5594_(p_151151_, p_151153_, getEmptySound(), SoundSource.NEUTRAL, 1.0F, 1.0F); + } + + private void m_151141_(ServerLevel p_151142_, ItemStack p_151143_, BlockPos p_151144_) { +- Entity entity = this.f_151134_.m_20592_(p_151142_, p_151143_, (Player)null, p_151144_, MobSpawnType.BUCKET, true, false); ++ Entity entity = getFishType().m_20592_(p_151142_, p_151143_, (Player)null, p_151144_, MobSpawnType.BUCKET, true, false); + if (entity instanceof Bucketable) { + Bucketable bucketable = (Bucketable)entity; + bucketable.m_142278_(p_151143_.m_41784_()); +@@ -55,7 +_,7 @@ + } + + public void m_7373_(ItemStack p_151155_, @Nullable Level p_151156_, List p_151157_, TooltipFlag p_151158_) { +- if (this.f_151134_ == EntityType.f_20489_) { ++ if (getFishType() == EntityType.f_20489_) { + CompoundTag compoundtag = p_151155_.m_41783_(); + if (compoundtag != null && compoundtag.m_128425_("BucketVariantTag", 3)) { + int i = compoundtag.m_128451_("BucketVariantTag"); +@@ -81,5 +_,14 @@ } } -- + + } + + // Forge Start + protected EntityType getFishType() { -+ return fishTypeSupplier.get(); ++ return entityTypeSupplier.get(); + } + + protected SoundEvent getEmptySound() { diff --git a/src/main/resources/coremods/field_to_method.js b/src/main/resources/coremods/field_to_method.js index 5cfaff866e..dd60c6be30 100644 --- a/src/main/resources/coremods/field_to_method.js +++ b/src/main/resources/coremods/field_to_method.js @@ -53,18 +53,6 @@ function initializeCoreMod() { return classNode; } }, - /* - 'mob_bucket_item': { - 'target': { - 'type': 'CLASS', - 'name': 'net.minecraft.world.item.MobBucketItem' - }, - 'transformer': function(classNode) { - ASMAPI.redirectFieldToMethod(classNode, ASMAPI.mapField('f_41262_'), ASMAPI.mapMethod('getFishType')) // type - Not implemented - return classNode; - } - }, - */ 'itemstack': { 'target': { 'type': 'CLASS', diff --git a/src/test/java/net/minecraftforge/debug/item/CustomMobBucketTest.java b/src/test/java/net/minecraftforge/debug/item/CustomMobBucketTest.java new file mode 100644 index 0000000000..f20a51e9bc --- /dev/null +++ b/src/test/java/net/minecraftforge/debug/item/CustomMobBucketTest.java @@ -0,0 +1,57 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2021. + * + * 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.debug.item; + +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.MobBucketItem; +import net.minecraft.world.level.material.Fluids; +import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.minecraftforge.registries.DeferredRegister; +import net.minecraftforge.registries.ForgeRegistries; +import net.minecraftforge.registries.RegistryObject; + +@Mod(CustomMobBucketTest.MODID) +public class CustomMobBucketTest +{ + public static final String MODID = "custom_mob_bucket_test"; + public static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID); + + public static final boolean ENABLED = true; + + public static final RegistryObject COW_BUCKET = ITEMS.register("cow_bucket", () -> new MobBucketItem( + () -> EntityType.COW, + () -> Fluids.WATER, + () -> SoundEvents.BUCKET_EMPTY_FISH, + (new Item.Properties()).stacksTo(1).tab(CreativeModeTab.TAB_MISC))); + + public CustomMobBucketTest() + { + if (ENABLED) + { + IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); + ITEMS.register(modEventBus); + } + } +} diff --git a/src/test/resources/META-INF/mods.toml b/src/test/resources/META-INF/mods.toml index 851825ee31..ab9f7887f8 100644 --- a/src/test/resources/META-INF/mods.toml +++ b/src/test/resources/META-INF/mods.toml @@ -174,6 +174,8 @@ license="LGPL v2.1" modId="part_entity_test" [[mods]] modId="capabilities_test" +[[mods]] + modId="custom_mob_bucket_test" [[mods]] modId="custom_armor_model_test" [[mods]] diff --git a/src/test/resources/assets/custom_mob_bucket_test/models/item/cow_bucket.json b/src/test/resources/assets/custom_mob_bucket_test/models/item/cow_bucket.json new file mode 100644 index 0000000000..2bf7677b5d --- /dev/null +++ b/src/test/resources/assets/custom_mob_bucket_test/models/item/cow_bucket.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "custom_mob_bucket_test:item/cow_bucket" + } +} diff --git a/src/test/resources/assets/custom_mob_bucket_test/textures/item/cow_bucket.png b/src/test/resources/assets/custom_mob_bucket_test/textures/item/cow_bucket.png new file mode 100644 index 0000000000000000000000000000000000000000..3f741c0fd48274bbe2565a23cbdd505be0f4325c GIT binary patch literal 6299 zcmeHLdpML^+aH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