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 0000000000..3f741c0fd4 Binary files /dev/null and b/src/test/resources/assets/custom_mob_bucket_test/textures/item/cow_bucket.png differ