2323
2424import net .minecraftforge .common .IShearable ;
2525import 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
2830import net .minecraft .block .DispenserBlock ;
2931import net .minecraft .block .dispenser .FallibleItemDispenserBehavior ;
3032import net .minecraft .entity .Entity ;
33+ import net .minecraft .entity .EntityType ;
3134import net .minecraft .item .ItemStack ;
3235import net .minecraft .util .math .BlockPointer ;
3336import net .minecraft .util .math .BlockPos ;
4447 */
4548@ Mixin (targets = "net/minecraft/block/dispenser/DispenserBehavior$13" )
4649public 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