Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit bcc1fe6

Browse files
committed
Smarter dispense behavior mixin, removes the remaining @overwrite... Also check that this is indeed the shear action
1 parent 4e97d15 commit bcc1fe6

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

patchwork-extensions-shearing/src/main/java/com/patchworkmc/mixin/extensions/shearing/MixinDispenserBehavior.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323

2424
import net.minecraftforge.common.IShearable;
2525
import org.spongepowered.asm.mixin.Mixin;
26-
import org.spongepowered.asm.mixin.Overwrite;
26+
import org.spongepowered.asm.mixin.injection.At;
27+
import org.spongepowered.asm.mixin.injection.Inject;
28+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
2729

2830
import net.minecraft.block.DispenserBlock;
2931
import net.minecraft.block.dispenser.FallibleItemDispenserBehavior;
3032
import net.minecraft.entity.Entity;
33+
import net.minecraft.entity.EntityType;
3134
import net.minecraft.item.ItemStack;
3235
import net.minecraft.util.math.BlockPointer;
3336
import net.minecraft.util.math.BlockPos;
@@ -44,20 +47,21 @@
4447
*/
4548
@Mixin(targets = "net/minecraft/block/dispenser/DispenserBehavior$13")
4649
public class MixinDispenserBehavior extends FallibleItemDispenserBehavior {
50+
private static final String DISPENSE_SILENTLY = "net/minecraft/block/dispenser/ItemDispenserBehavior.dispenseSilently(Lnet/minecraft/util/math/BlockPointer;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;";
51+
4752
/**
48-
* @reason Patch this class to drop stacks for any shearable entity. An overwrite was required here as the mixin was
49-
* too complicated to write without one.
53+
* Shears non-sheep entities that implement {@link IShearable}. The vanilla code will handle sheep entities.
54+
*
5055
* @author SuperCoder79
5156
*/
52-
@Overwrite
53-
public ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
57+
@Inject(method = DISPENSE_SILENTLY, at = @At("RETURN"))
58+
private void onDispenseSilently(BlockPointer pointer, ItemStack stack, CallbackInfoReturnable<ItemStack> callback) {
5459
World world = pointer.getWorld();
5560

5661
if (!world.isClient()) {
57-
this.success = false;
5862
BlockPos pos = pointer.getBlockPos().offset(pointer.getBlockState().get(DispenserBlock.FACING));
5963
List<Entity> entities = world.getEntities(Entity.class, new Box(pos),
60-
entity -> !entity.isSpectator() && entity instanceof IShearable
64+
entity -> !entity.isSpectator() && entity instanceof IShearable && entity.getType() != EntityType.SHEEP
6165
);
6266

6367
for (Entity entity : entities) {
@@ -72,7 +76,10 @@ public ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
7276
this.success = true;
7377
}
7478
}
79+
}
7580

76-
return stack;
81+
@Inject(method = DISPENSE_SILENTLY, at = @At(value = "INVOKE", target = "net/minecraft/entity/passive/SheepEntity.dropItems()V"))
82+
private void assertThatThisIsTheShearingDispenserAction(BlockPointer pointer, ItemStack stack, CallbackInfoReturnable<ItemStack> callback) {
83+
// Make sure that the anonymous class numbers didn't move around by checking for a SheepEntity reference.
7784
}
7885
}

0 commit comments

Comments
 (0)