Code cleanup

This commit is contained in:
FlorianMichael 2024-08-04 22:08:16 +02:00
parent 4218225967
commit a64de56869
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
2 changed files with 7 additions and 9 deletions

View File

@ -28,7 +28,9 @@ import net.minecraft.util.Hand;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(MobEntity.class) @Mixin(MobEntity.class)
public abstract class MixinMobEntity { public abstract class MixinMobEntity {
@ -36,11 +38,8 @@ public abstract class MixinMobEntity {
@Shadow @Shadow
protected abstract ActionResult interactWithItem(PlayerEntity player, Hand hand); protected abstract ActionResult interactWithItem(PlayerEntity player, Hand hand);
@Shadow
protected abstract ActionResult interactMob(PlayerEntity player, Hand hand);
@Redirect(method = "interact", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/mob/MobEntity;interactWithItem(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;")) @Redirect(method = "interact", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/mob/MobEntity;interactWithItem(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;"))
private ActionResult cancelItemInteractions(MobEntity instance, PlayerEntity player, Hand hand) { private ActionResult moveItemInteractionsAfterLeashing(MobEntity instance, PlayerEntity player, Hand hand) {
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_20_5)) { if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_20_5)) {
return ActionResult.FAIL; return ActionResult.FAIL;
} else { } else {
@ -48,15 +47,14 @@ public abstract class MixinMobEntity {
} }
} }
@Redirect(method = "interact", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/mob/MobEntity;interactMob(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;")) @Inject(method = "interact", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/mob/MobEntity;interactMob(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;", shift = At.Shift.BEFORE), cancellable = true)
private ActionResult moveItemInteractionsAfterLeashing(MobEntity instance, PlayerEntity player, Hand hand) { private void moveItemInteractionsAfterLeashing(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_20_5)) { if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_20_5)) {
final ActionResult result = interactWithItem(player, hand); final ActionResult result = interactWithItem(player, hand);
if (result.isAccepted()) { if (result.isAccepted()) {
return result; cir.setReturnValue(result);
} }
} }
return interactMob(player, hand);
} }
} }

View File

@ -35,7 +35,7 @@ public abstract class MixinBucketItem {
@Redirect(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemUsage;exchangeStack(Lnet/minecraft/item/ItemStack;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;", ordinal = 1)) @Redirect(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemUsage;exchangeStack(Lnet/minecraft/item/ItemStack;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;", ordinal = 1))
private ItemStack dontExchangeStack(ItemStack inputStack, PlayerEntity player, ItemStack outputStack) { private ItemStack dontExchangeStack(ItemStack inputStack, PlayerEntity player, ItemStack outputStack) {
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_20_5)) { if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_20_5)) {
return inputStack; return outputStack;
} else { } else {
return ItemUsage.exchangeStack(inputStack, player, outputStack); return ItemUsage.exchangeStack(inputStack, player, outputStack);
} }