Fix Bogged and Wolf armor not being shearable by custom shears. Closes #10005

This commit is contained in:
LexManos committed 2024-06-13 14:21:30 -07:00
1 parent 2677511da6
commit 1c633b4624
9 files changed
+123 -48

No files matched your search

@@ -1,10 +1,18 @@
--- a/net/minecraft/world/entity/Shearable.java
+++ b/net/minecraft/world/entity/Shearable.java
@@ -2,6 +_,7 @@
@@ -2,8 +_,14 @@
import net.minecraft.sounds.SoundSource;
+/** @deprecated Use {@link net.minecraftforge.common.IForgeShearable} */
public interface Shearable {
-public interface Shearable {
+public interface Shearable extends net.minecraftforge.common.IForgeShearable {
+ /** @deprecated Use {@link net.minecraftforge.common.IForgeShearable#onSheared} */
void shear(SoundSource p_21749_);
+ /** @deprecated Use {@link net.minecraftforge.common.IForgeShearable#isShearable} */
boolean readyForShearing();
+
+ default boolean isShearable(net.minecraft.world.item.ItemStack item, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos) {
+ return readyForShearing();
+ }
}
@@ -1,14 +1,5 @@
--- a/net/minecraft/world/entity/animal/MushroomCow.java
+++ b/net/minecraft/world/entity/animal/MushroomCow.java
@@ -42,7 +_,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;
-public class MushroomCow extends Cow implements Shearable, VariantHolder<MushroomCow.MushroomType> {
+public class MushroomCow extends Cow implements Shearable, VariantHolder<MushroomCow.MushroomType>, net.minecraftforge.common.IForgeShearable {
private static final EntityDataAccessor<String> DATA_TYPE = SynchedEntityData.defineId(MushroomCow.class, EntityDataSerializers.STRING);
private static final int MUTATE_CHANCE = 1024;
private static final String TAG_STEW_EFFECTS = "stew_effects";
@@ -108,7 +_,7 @@
this.playSound(soundevent, 1.0F, 1.0F);
@@ -55,7 +46,7 @@
}
@Override
@@ -255,6 +_,17 @@
@@ -255,6 +_,12 @@
}
return mushroomcow$mushroomtype2;
@@ -65,11 +56,6 @@
+ public java.util.List<ItemStack> onSheared(@org.jetbrains.annotations.Nullable Player player, @org.jetbrains.annotations.NotNull ItemStack item, Level world, BlockPos pos, int fortune) {
+ this.gameEvent(GameEvent.SHEAR, player);
+ return shearInternal(player == null ? SoundSource.BLOCKS : SoundSource.PLAYERS);
+ }
+
+ @Override
+ public boolean isShearable(ItemStack item, Level world, BlockPos pos) {
+ return readyForShearing();
}
public static enum MushroomType implements StringRepresentable {
@@ -1,14 +1,5 @@
--- a/net/minecraft/world/entity/animal/Sheep.java
+++ b/net/minecraft/world/entity/animal/Sheep.java
@@ -61,7 +_,7 @@
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
import net.minecraft.world.level.storage.loot.LootTable;
-public class Sheep extends Animal implements Shearable {
+public class Sheep extends Animal implements Shearable, net.minecraftforge.common.IForgeShearable {
private static final int EAT_ANIMATION_TICKS = 40;
private static final EntityDataAccessor<Byte> DATA_WOOL_ID = SynchedEntityData.defineId(Sheep.class, EntityDataSerializers.BYTE);
private static final Map<DyeColor, ItemLike> ITEM_BY_DYE = Util.make(Maps.newEnumMap(DyeColor.class), p_29841_ -> {
@@ -212,7 +_,7 @@
@Override
public InteractionResult mobInteract(Player p_29853_, InteractionHand p_29854_) {
@@ -44,18 +35,13 @@
if (itementity != null) {
itementity.setDeltaMovement(
itementity.getDeltaMovement()
@@ -366,5 +_,15 @@
@@ -366,5 +_,10 @@
private static CraftingInput makeCraftInput(DyeColor p_344668_, DyeColor p_344678_) {
return CraftingInput.of(2, 1, List.of(new ItemStack(DyeItem.byColor(p_344668_)), new ItemStack(DyeItem.byColor(p_344678_))));
+ }
+
+ @Override
+ public boolean isShearable(@org.jetbrains.annotations.NotNull ItemStack item, Level world, BlockPos pos) {
+ return readyForShearing();
+ }
+
+ @Override
+ public java.util.List<ItemStack> onSheared(@Nullable Player player, ItemStack item, Level world, BlockPos pos, int fortune) {
+ return shearInternal(player == null ? SoundSource.BLOCKS : SoundSource.PLAYERS);
}
@@ -36,16 +36,11 @@
this.shear(SoundSource.PLAYERS);
this.gameEvent(GameEvent.SHEAR, p_29920_);
if (!this.level().isClientSide) {
@@ -189,4 +_,21 @@
@@ -189,4 +_,16 @@
public Vec3 getLeashOffset() {
return new Vec3(0.0, (double)(0.75F * this.getEyeHeight()), (double)(this.getBbWidth() * 0.4F));
}
+
+ @Override
+ public boolean isShearable(@org.jetbrains.annotations.NotNull ItemStack item, Level world, BlockPos pos) {
+ return readyForShearing();
+ }
+
+ @org.jetbrains.annotations.NotNull
+ @Override
+ public java.util.List<ItemStack> onSheared(@Nullable Player player, @org.jetbrains.annotations.NotNull ItemStack item, Level world, BlockPos pos, int fortune) {
@@ -1,5 +1,33 @@
--- a/net/minecraft/world/entity/animal/Wolf.java
+++ b/net/minecraft/world/entity/animal/Wolf.java
@@ -87,7 +_,7 @@
import net.minecraft.world.level.pathfinder.PathType;
import net.minecraft.world.phys.Vec3;
-public class Wolf extends TamableAnimal implements NeutralMob, VariantHolder<Holder<WolfVariant>> {
+public class Wolf extends TamableAnimal implements NeutralMob, VariantHolder<Holder<WolfVariant>>, net.minecraftforge.common.IForgeShearable {
private static final EntityDataAccessor<Boolean> DATA_INTERESTED_ID = SynchedEntityData.defineId(Wolf.class, EntityDataSerializers.BOOLEAN);
private static final EntityDataAccessor<Integer> DATA_COLLAR_COLOR = SynchedEntityData.defineId(Wolf.class, EntityDataSerializers.INT);
private static final EntityDataAccessor<Integer> DATA_REMAINING_ANGER_TIME = SynchedEntityData.defineId(Wolf.class, EntityDataSerializers.INT);
@@ -448,16 +_,11 @@
this.setBodyArmorItem(itemstack.copyWithCount(1));
itemstack.consume(1, p_30412_);
return InteractionResult.SUCCESS;
- } else if (itemstack.is(Items.SHEARS)
+ } else if (itemstack.canPerformAction(net.minecraftforge.common.ToolActions.SHEARS_HARVEST)
&& this.isOwnedBy(p_30412_)
&& this.hasArmor()
&& (!EnchantmentHelper.has(this.getBodyArmorItem(), EnchantmentEffectComponents.PREVENT_ARMOR_CHANGE) || p_30412_.isCreative())) {
- itemstack.hurtAndBreak(1, p_30412_, getSlotForHand(p_30413_));
- this.playSound(SoundEvents.ARMOR_UNEQUIP_WOLF);
- ItemStack itemstack1 = this.getBodyArmorItem();
- this.setBodyArmorItem(ItemStack.EMPTY);
- this.spawnAtLocation(itemstack1);
- return InteractionResult.SUCCESS;
+ return InteractionResult.PASS;
} else if (ArmorMaterials.ARMADILLO.value().repairIngredient().get().test(itemstack)
&& this.isInSittingPose()
&& this.hasArmor()
@@ -496,7 +_,7 @@
}
@@ -9,3 +37,28 @@
this.tame(p_336244_);
this.navigation.stop();
this.setTarget(null);
@@ -648,6 +_,24 @@
return true;
}
+ }
+
+ @Override
+ public boolean isShearable(ItemStack item, Level world, BlockPos pos) {
+ return this.hasArmor();
+ }
+
+ @Override
+ public java.util.List<ItemStack> onSheared(@org.jetbrains.annotations.Nullable Player player, @org.jetbrains.annotations.NotNull ItemStack item, Level world, BlockPos pos, int fortune) {
+ if (!this.hasArmor() || (player != null && !this.isOwnedBy(player)) ||
+ (EnchantmentHelper.has(this.getBodyArmorItem(), EnchantmentEffectComponents.PREVENT_ARMOR_CHANGE) && (player == null || !player.isCreative()))
+ )
+ return java.util.Collections.emptyList();
+
+ this.playSound(SoundEvents.ARMOR_UNEQUIP_WOLF);
+ var armor = this.getBodyArmorItem();
+ this.setBodyArmorItem(ItemStack.EMPTY);
+ return java.util.List.of(armor);
}
@Override
@@ -0,0 +1,49 @@
--- a/net/minecraft/world/entity/monster/Bogged.java
+++ b/net/minecraft/world/entity/monster/Bogged.java
@@ -74,7 +_,7 @@
@Override
protected InteractionResult mobInteract(Player p_335303_, InteractionHand p_335145_) {
ItemStack itemstack = p_335303_.getItemInHand(p_335145_);
- if (itemstack.is(Items.SHEARS) && this.readyForShearing()) {
+ if (false && itemstack.is(Items.SHEARS) && this.readyForShearing()) { // Forge: move to onSheared
this.shear(SoundSource.PLAYERS);
this.gameEvent(GameEvent.SHEAR, p_335303_);
if (!this.level().isClientSide) {
@@ -129,12 +_,20 @@
@Override
public void shear(SoundSource p_332421_) {
- this.level().playSound(null, this, SoundEvents.BOGGED_SHEAR, p_332421_, 1.0F, 1.0F);
- this.spawnShearedMushrooms();
+ shearInternal(p_332421_).stream().forEach(stack -> this.spawnAtLocation(stack, this.getBbHeight()));
+ }
+
+ @Override
+ public java.util.List<ItemStack> onSheared(@org.jetbrains.annotations.Nullable Player player, @org.jetbrains.annotations.NotNull ItemStack item, Level world, net.minecraft.core.BlockPos pos, int fortune) {
+ this.gameEvent(GameEvent.SHEAR, player);
+ return shearInternal(player == null ? SoundSource.BLOCKS : SoundSource.PLAYERS);
+ }
+
+ private java.util.List<ItemStack> shearInternal(SoundSource sound) {
+ this.level().playSound(null, this, SoundEvents.BOGGED_SHEAR, sound, 1.0F, 1.0F);
this.setSheared(true);
- }
- private void spawnShearedMushrooms() {
+ var ret = new java.util.ArrayList<ItemStack>();
if (this.level() instanceof ServerLevel serverlevel) {
LootTable loottable = serverlevel.getServer().reloadableRegistries().getLootTable(BuiltInLootTables.BOGGED_SHEAR);
LootParams lootparams = new LootParams.Builder(serverlevel)
@@ -143,9 +_,11 @@
.create(LootContextParamSets.SHEARING);
for (ItemStack itemstack : loottable.getRandomItems(lootparams)) {
- this.spawnAtLocation(itemstack, this.getBbHeight());
+ ret.add(itemstack);
}
}
+
+ return ret;
}
@Override
@@ -1,6 +1,6 @@
--- a/net/minecraft/world/item/ShearsItem.java
+++ b/net/minecraft/world/item/ShearsItem.java
@@ -79,4 +_,32 @@
@@ -79,4 +_,33 @@
return super.useOn(p_186371_);
}
@@ -21,7 +21,8 @@
+ var ent = entity.spawnAtLocation(d, 1.0F);
+ ent.setDeltaMovement(ent.getDeltaMovement().add((double)((rand.nextFloat() - rand.nextFloat()) * 0.1F), (double)(rand.nextFloat() * 0.05F), (double)((rand.nextFloat() - rand.nextFloat()) * 0.1F)));
+ });
+ stack.hurtAndBreak(1, playerIn, LivingEntity.getSlotForHand(hand));
+ if (!drops.isEmpty())
+ stack.hurtAndBreak(1, playerIn, LivingEntity.getSlotForHand(hand));
+ }
+ return InteractionResult.SUCCESS;
+ }
@@ -23,8 +23,7 @@ import org.jetbrains.annotations.Nullable;
* to support mod-shears as well.
*
*/
public interface IForgeShearable
{
public interface IForgeShearable {
/**
* Checks if the object is currently shearable
* Example: Sheep return false when they have no wool
@@ -34,8 +33,7 @@ public interface IForgeShearable
* @param pos Block's position in level.
* @return If this is shearable, and onSheared should be called.
*/
default boolean isShearable(@NotNull ItemStack item, Level level, BlockPos pos)
{
default boolean isShearable(@NotNull ItemStack item, Level level, BlockPos pos) {
return true;
}
@@ -58,8 +56,7 @@ public interface IForgeShearable
* @return A List containing all items from this shearing. May be empty.
*/
@NotNull
default List<ItemStack> onSheared(@Nullable Player player, @NotNull ItemStack item, Level level, BlockPos pos, int fortune)
{
default List<ItemStack> onSheared(@Nullable Player player, @NotNull ItemStack item, Level level, BlockPos pos, int fortune) {
return Collections.emptyList();
}
}
@@ -67,7 +67,7 @@ public class ToolActions
/**
* Used during player attack to figure out if a sweep attack should be performed
*
*
* @see IForgeItem#getSweepHitBox
*/
public static final ToolAction SWORD_SWEEP = ToolAction.get("sword_sweep");