From 6683e9e660696e8fbef4d3860846dd267d53d704 Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Sat, 8 Jan 2022 16:20:09 -0500 Subject: [PATCH] Provide access to the blockstate in BucketPickup#getPickupSound for multiply-logged blocks (#8357) --- .../world/item/BucketItem.java.patch | 9 ++++ .../world/level/block/BucketPickup.java.patch | 13 +++++ .../common/extensions/IForgeBucketPickup.java | 48 +++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 patches/minecraft/net/minecraft/world/level/block/BucketPickup.java.patch create mode 100644 src/main/java/net/minecraftforge/common/extensions/IForgeBucketPickup.java diff --git a/patches/minecraft/net/minecraft/world/item/BucketItem.java.patch b/patches/minecraft/net/minecraft/world/item/BucketItem.java.patch index 81fccaa062..5cef1a5a0d 100644 --- a/patches/minecraft/net/minecraft/world/item/BucketItem.java.patch +++ b/patches/minecraft/net/minecraft/world/item/BucketItem.java.patch @@ -29,6 +29,15 @@ if (blockhitresult.m_6662_() == HitResult.Type.MISS) { return InteractionResultHolder.m_19098_(itemstack); } else if (blockhitresult.m_6662_() != HitResult.Type.BLOCK) { +@@ -56,7 +_,7 @@ + ItemStack itemstack1 = bucketpickup.m_142598_(p_40703_, blockpos, blockstate1); + if (!itemstack1.m_41619_()) { + p_40704_.m_36246_(Stats.f_12982_.m_12902_(this)); +- bucketpickup.m_142298_().ifPresent((p_150709_) -> { ++ bucketpickup.getPickupSound(blockstate1).ifPresent((p_150709_) -> { + p_40704_.m_5496_(p_150709_, 1.0F, 1.0F); + }); + p_40703_.m_142346_(p_40704_, GameEvent.f_157816_, blockpos); @@ -72,7 +_,7 @@ return InteractionResultHolder.m_19100_(itemstack); } else { diff --git a/patches/minecraft/net/minecraft/world/level/block/BucketPickup.java.patch b/patches/minecraft/net/minecraft/world/level/block/BucketPickup.java.patch new file mode 100644 index 0000000000..0ba83dd22d --- /dev/null +++ b/patches/minecraft/net/minecraft/world/level/block/BucketPickup.java.patch @@ -0,0 +1,13 @@ +--- a/net/minecraft/world/level/block/BucketPickup.java ++++ b/net/minecraft/world/level/block/BucketPickup.java +@@ -7,8 +_,9 @@ + import net.minecraft.world.level.LevelAccessor; + import net.minecraft.world.level.block.state.BlockState; + +-public interface BucketPickup { ++public interface BucketPickup extends net.minecraftforge.common.extensions.IForgeBucketPickup { + ItemStack m_142598_(LevelAccessor p_152719_, BlockPos p_152720_, BlockState p_152721_); + ++ @Deprecated//Forge: Use state sensitive variant instead + Optional m_142298_(); + } diff --git a/src/main/java/net/minecraftforge/common/extensions/IForgeBucketPickup.java b/src/main/java/net/minecraftforge/common/extensions/IForgeBucketPickup.java new file mode 100644 index 0000000000..3df242ae5d --- /dev/null +++ b/src/main/java/net/minecraftforge/common/extensions/IForgeBucketPickup.java @@ -0,0 +1,48 @@ +/* + * 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.common.extensions; + +import java.util.Optional; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.world.level.block.BucketPickup; +import net.minecraft.world.level.block.state.BlockState; + +public interface IForgeBucketPickup +{ + + private BucketPickup self() + { + return (BucketPickup) this; + } + + /** + * State sensitive variant of {@link BucketPickup#getPickupSound()}. + * + * Override to change the pickup sound based on the {@link BlockState} of the object being picked up. + * + * @param state State + * + * @return Sound event for pickup sound or empty if there isn't a pickup sound. + */ + default Optional getPickupSound(BlockState state) + { + return self().getPickupSound(); + } +} \ No newline at end of file