Skip to content

Commit

Permalink
Mixins cleanup, fixes #1577.
Browse files Browse the repository at this point in the history
Signed-off-by: 秋雨落 <i@rain.cx>
  • Loading branch information
qyl27 committed Dec 3, 2024
1 parent dcb4f39 commit 1e25ff3
Show file tree
Hide file tree
Showing 24 changed files with 277 additions and 272 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.izzel.arclight.common.bridge.core.world.item;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;

public interface BucketItemBridge {
@Nullable Direction arclight$getDirection();
void arclight$setDirection(@Nullable Direction value);

@Nullable BlockPos arclight$getClick();
void arclight$setClick(@Nullable BlockPos value);

@Nullable InteractionHand arclight$getHand();
void arclight$setHand(@Nullable InteractionHand value);

@Nullable ItemStack arclight$getStack();
void arclight$setStack(@Nullable ItemStack value);

@Nullable org.bukkit.inventory.ItemStack arclight$getCaptureItem();
void arclight$setCaptureItem(@Nullable org.bukkit.inventory.ItemStack value);
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(SmallFireball.class)
public abstract class SmallFireballMixin extends FireballMixin {
public abstract class SmallFireballMixin extends AbstractHurtingProjectileMixin {

@Inject(method = "<init>(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/phys/Vec3;)V", at = @At("RETURN"))
private void arclight$init(Level level, LivingEntity livingEntity, Vec3 vec3, CallbackInfo ci) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.izzel.arclight.common.mixin.core.world.item;

import com.llamalad7.mixinextras.sugar.Local;
import io.izzel.arclight.common.bridge.core.entity.player.ServerPlayerEntityBridge;
import io.izzel.arclight.common.bridge.core.world.item.BucketItemBridge;
import io.izzel.arclight.common.mod.util.DistValidate;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand All @@ -20,26 +22,25 @@
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.craftbukkit.v.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v.util.DummyGeneratorAccess;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(BucketItem.class)
public abstract class BucketItemMixin {
public abstract class BucketItemMixin implements BucketItemBridge {

// @formatter:off
@Shadow public abstract boolean emptyContents(@Nullable Player player, Level worldIn, BlockPos posIn, @javax.annotation.Nullable BlockHitResult rayTrace);
// @formatter:on

@Inject(method = "use", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/BucketPickup;pickupBlock(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/item/ItemStack;"))
private void arclight$bucketFill(Level worldIn, Player playerIn, InteractionHand handIn, CallbackInfoReturnable<InteractionResultHolder<ItemStack>> cir, ItemStack stack, BlockHitResult result) {
@Inject(method = "use", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/BucketPickup;pickupBlock(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/item/ItemStack;"))
private void arclight$bucketFill(Level worldIn, Player playerIn, InteractionHand handIn, CallbackInfoReturnable<InteractionResultHolder<ItemStack>> cir, @Local ItemStack stack, @Local BlockHitResult result) {
if (!DistValidate.isValid(worldIn)) return;
BlockPos pos = result.getBlockPos();
BlockState state = worldIn.getBlockState(pos);
Expand All @@ -50,61 +51,109 @@ public abstract class BucketItemMixin {
((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory();
cir.setReturnValue(new InteractionResultHolder<>(InteractionResult.FAIL, stack));
} else {
arclight$captureItem = event.getItemStack();
arclight$setCaptureItem(event.getItemStack());
}
}

@Inject(method = "use", at = @At("RETURN"))
private void arclight$clean(Level worldIn, Player playerIn, InteractionHand handIn, CallbackInfoReturnable<InteractionResultHolder<ItemStack>> cir) {
arclight$captureItem = null;
arclight$direction = null;
arclight$click = null;
arclight$setDirection(null);
arclight$setClick(null);
arclight$setHand(null);
}

private transient org.bukkit.inventory.@Nullable ItemStack arclight$captureItem;

@ModifyArg(method = "use", index = 2, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemUtils;createFilledResult(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/item/ItemStack;"))
private ItemStack arclight$useEventItem(ItemStack itemStack) {
return arclight$captureItem == null ? itemStack : CraftItemStack.asNMSCopy(arclight$captureItem);
}

@Inject(method = "use", require = 0, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/BucketItem;emptyContents(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/phys/BlockHitResult;)Z"))
private void arclight$capture(Level worldIn, Player playerIn, InteractionHand handIn, CallbackInfoReturnable<InteractionResultHolder<ItemStack>> cir, ItemStack stack, BlockHitResult result) {
arclight$direction = result.getDirection();
arclight$click = result.getBlockPos();
arclight$hand = handIn;
return arclight$getCaptureItem() == null ? itemStack : CraftItemStack.asNMSCopy(arclight$getCaptureItem());
}

public boolean emptyContents(Player entity, Level world, BlockPos pos, @Nullable BlockHitResult result, Direction direction, BlockPos clicked, ItemStack itemstack, InteractionHand hand) {
arclight$direction = direction;
arclight$click = clicked;
arclight$hand = hand;
arclight$stack = itemstack;
arclight$setDirection(direction);
arclight$setClick(clicked);
arclight$setHand(hand);
arclight$setStack(itemstack);
try {
return this.emptyContents(entity, world, pos, result);
} finally {
arclight$direction = null;
arclight$click = null;
arclight$hand = null;
arclight$stack = null;
arclight$setDirection(null);
arclight$setClick(null);
arclight$setHand(null);
arclight$setStack(null);
}
}

@Unique
@Nullable
private transient Direction arclight$direction;

@Unique
@Nullable
private transient BlockPos arclight$click;

@Unique
@Nullable
private transient InteractionHand arclight$hand;

@Unique
@Nullable
private transient ItemStack arclight$stack;

@Inject(method = "emptyContents", require = 0, cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/dimension/DimensionType;ultraWarm()Z"))
private void arclight$bucketEmpty(Player player, Level worldIn, BlockPos posIn, BlockHitResult rayTrace, CallbackInfoReturnable<Boolean> cir) {
if (!DistValidate.isValid(worldIn)) return;
if (player != null && arclight$stack != null) {
PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((ServerLevel) worldIn, player, posIn, arclight$click, arclight$direction, arclight$stack, arclight$hand == null ? InteractionHand.MAIN_HAND : arclight$hand);
if (event.isCancelled()) {
((ServerPlayer) player).connection.send(new ClientboundBlockUpdatePacket(worldIn, posIn));
((ServerPlayerEntityBridge) player).bridge$getBukkitEntity().updateInventory();
cir.setReturnValue(false);
}
}
@Unique
@Nullable
private transient org.bukkit.inventory.ItemStack arclight$captureItem;

@Nullable
@Override
public Direction arclight$getDirection() {
return this.arclight$direction;
}

@Override
public void arclight$setDirection(@Nullable Direction value) {
this.arclight$direction = value;
}

@Nullable
@Override
public BlockPos arclight$getClick() {
return this.arclight$click;
}

@Override
public void arclight$setClick(@Nullable BlockPos value) {
this.arclight$click = value;
}

@Nullable
@Override
public InteractionHand arclight$getHand() {
return this.arclight$hand;
}

@Override
public void arclight$setHand(@Nullable InteractionHand value) {
this.arclight$hand = value;
}

@Nullable
@Override
public ItemStack arclight$getStack() {
return this.arclight$stack;
}

@Override
public void arclight$setStack(@Nullable ItemStack value) {
this.arclight$stack = value;
}

@Nullable
@Override
public org.bukkit.inventory.ItemStack arclight$getCaptureItem() {
return this.arclight$captureItem;
}

@Override
public void arclight$setCaptureItem(@Nullable org.bukkit.inventory.ItemStack value) {
this.arclight$captureItem = value;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package io.izzel.arclight.common.mixin.core.world.effect;
package io.izzel.arclight.common.mixin.vanilla.world.effect;

import io.izzel.arclight.api.ArclightPlatform;
import io.izzel.arclight.common.bridge.core.util.DamageSourcesBridge;
import io.izzel.arclight.common.mod.mixins.annotation.OnlyInPlatform;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageSources;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(targets = "net.minecraft.world.effect.PoisonMobEffect")
@OnlyInPlatform(value = {ArclightPlatform.VANILLA, ArclightPlatform.FABRIC, ArclightPlatform.FORGE})
public class PoisonMobEffectMixin_Vanilla {

@Redirect(method = "applyEffectTick", require = 0, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/damagesource/DamageSources;magic()Lnet/minecraft/world/damagesource/DamageSource;"))
Expand Down
Loading

0 comments on commit 1e25ff3

Please sign in to comment.