diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/world/item/BucketItemBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/world/item/BucketItemBridge.java new file mode 100644 index 000000000..80067b9c9 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/world/item/BucketItemBridge.java @@ -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); +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityMixin_Vanilla.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityMixin_Vanilla.java deleted file mode 100644 index 44649a289..000000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityMixin_Vanilla.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.izzel.arclight.common.mixin.core.world.entity; - -import io.izzel.arclight.api.ArclightPlatform; -import io.izzel.arclight.common.bridge.core.command.ICommandSourceBridge; -import io.izzel.arclight.common.bridge.core.entity.EntityBridge; -import io.izzel.arclight.common.bridge.core.entity.InternalEntityBridge; -import io.izzel.arclight.common.mod.mixins.annotation.OnlyInPlatform; -import io.izzel.arclight.mixin.Decorate; -import io.izzel.arclight.mixin.DecorationOps; -import net.minecraft.core.BlockPos; -import net.minecraft.tags.FluidTags; -import net.minecraft.world.entity.*; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.material.FluidState; -import net.minecraft.world.phys.Vec3; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; - -@Mixin(Entity.class) -@OnlyInPlatform(value = {ArclightPlatform.VANILLA, ArclightPlatform.FABRIC}) -public abstract class EntityMixin_Vanilla implements InternalEntityBridge, EntityBridge, ICommandSourceBridge { - - @Decorate(method = "updateFluidHeightAndDoFluidPushing", require = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/material/FluidState;getFlow(Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/phys/Vec3;")) - private Vec3 arclight$setLava(FluidState fluid, BlockGetter level, BlockPos pos) throws Throwable { - if (fluid.getType().is(FluidTags.LAVA)) { - bridge$setLastLavaContact(pos.immutable()); - } - return (Vec3) DecorationOps.callsite().invoke(fluid, level, pos); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/FireballMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/FireballMixin.java deleted file mode 100644 index deb5d4285..000000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/FireballMixin.java +++ /dev/null @@ -1,9 +0,0 @@ -package io.izzel.arclight.common.mixin.core.world.entity.projectile; - -import net.minecraft.world.entity.projectile.Fireball; -import org.spongepowered.asm.mixin.Mixin; - -@Mixin(Fireball.class) -public abstract class FireballMixin extends AbstractHurtingProjectileMixin { - -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/SmallFireballMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/SmallFireballMixin.java index 6fca27bb4..dbf1cd210 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/SmallFireballMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/SmallFireballMixin.java @@ -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 = "(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) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/BucketItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/BucketItemMixin.java index 716e9e859..18d27cdd2 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/BucketItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/BucketItemMixin.java @@ -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; @@ -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> 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> cir, @Local ItemStack stack, @Local BlockHitResult result) { if (!DistValidate.isValid(worldIn)) return; BlockPos pos = result.getBlockPos(); BlockState state = worldIn.getBlockState(pos); @@ -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> 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> 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 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; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/ItemStackMixin_Vanilla.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/ItemStackMixin_Vanilla.java deleted file mode 100644 index 0988f6c85..000000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/ItemStackMixin_Vanilla.java +++ /dev/null @@ -1,59 +0,0 @@ -package io.izzel.arclight.common.mixin.core.world.item; - -import io.izzel.arclight.api.ArclightPlatform; -import io.izzel.arclight.common.bridge.core.entity.player.ServerPlayerEntityBridge; -import io.izzel.arclight.common.bridge.core.world.item.ItemStackBridge; -import io.izzel.arclight.common.mod.mixins.annotation.OnlyInPlatform; -import io.izzel.arclight.mixin.Decorate; -import io.izzel.arclight.mixin.DecorationOps; -import io.izzel.arclight.mixin.Local; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.craftbukkit.v.inventory.CraftItemStack; -import org.bukkit.event.player.PlayerItemDamageEvent; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.function.Consumer; - -@Mixin(ItemStack.class) -@OnlyInPlatform(value = {ArclightPlatform.VANILLA, ArclightPlatform.FABRIC}) -public abstract class ItemStackMixin_Vanilla implements ItemStackBridge { - - // @formatter:off - @Shadow private int count; - // @formatter:on - - @Decorate(method = "hurtAndBreak(ILnet/minecraft/server/level/ServerLevel;Lnet/minecraft/server/level/ServerPlayer;Ljava/util/function/Consumer;)V", - require = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/enchantment/EnchantmentHelper;processDurabilityChange(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/item/ItemStack;I)I")) - private int arclight$itemDamage(ServerLevel serverLevel, ItemStack itemStack, int i, @Local(ordinal = 0) ServerPlayer damager) throws Throwable { - int result = (int) DecorationOps.callsite().invoke(serverLevel, itemStack, i); - if (damager != null) { - PlayerItemDamageEvent event = new PlayerItemDamageEvent(((ServerPlayerEntityBridge) damager).bridge$getBukkitEntity(), CraftItemStack.asCraftMirror((ItemStack) (Object) this), result); - event.getPlayer().getServer().getPluginManager().callEvent(event); - - if (result != event.getDamage() || event.isCancelled()) { - event.getPlayer().updateInventory(); - } - if (event.isCancelled()) { - return (int) DecorationOps.cancel().invoke(); - } - result = event.getDamage(); - } - return result; - } - - @Inject(method = "hurtAndBreak(ILnet/minecraft/server/level/ServerLevel;Lnet/minecraft/server/level/ServerPlayer;Ljava/util/function/Consumer;)V", require = 0, at = @At(value = "INVOKE", target = "Ljava/util/function/Consumer;accept(Ljava/lang/Object;)V")) - private void arclight$itemBreak(int amount, ServerLevel level, @Nullable ServerPlayer serverPlayer, Consumer onBroken, CallbackInfo ci) { - if (this.count == 1 && serverPlayer != null) { - CraftEventFactory.callPlayerItemBreakEvent(serverPlayer, (ItemStack) (Object) this); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/LevelMixin_Vanilla.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/LevelMixin_Vanilla.java deleted file mode 100644 index 61576f4d2..000000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/LevelMixin_Vanilla.java +++ /dev/null @@ -1,44 +0,0 @@ -package io.izzel.arclight.common.mixin.core.world.level; - -import io.izzel.arclight.api.ArclightPlatform; -import io.izzel.arclight.common.bridge.core.world.WorldBridge; -import io.izzel.arclight.common.mod.mixins.annotation.OnlyInPlatform; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.LevelWriter; -import net.minecraft.world.level.block.state.BlockState; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v.block.CraftBlock; -import org.bukkit.craftbukkit.v.block.data.CraftBlockData; -import org.bukkit.event.block.BlockPhysicsEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(Level.class) -@OnlyInPlatform(value = {ArclightPlatform.VANILLA, ArclightPlatform.FABRIC}) -public abstract class LevelMixin_Vanilla implements WorldBridge, LevelAccessor, LevelWriter { - @Inject(method = "setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;II)Z", require = 0, cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;updateNeighbourShapes(Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;II)V")) - private void arclight$callBlockPhysics(BlockPos pos, BlockState state, int i, int j, CallbackInfoReturnable cir) { - try { - if (this.bridge$getWorld() != null) { - BlockPhysicsEvent event = new BlockPhysicsEvent(CraftBlock.at(this, pos), CraftBlockData.fromData(state)); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) { - cir.setReturnValue(true); - } - } - } catch (StackOverflowError e) { - bridge$setLastPhysicsProblem(pos); - } - } - - @Inject(method = "setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;II)Z", require = 0, cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;onBlockStateChange(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;)V")) - private void arclight$preventPoiUpdate(BlockPos blockPos, BlockState blockState, int i, int j, CallbackInfoReturnable cir) { - if (bridge$preventPoiUpdated()) { - cir.setReturnValue(true); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/effect/PoisonMobEffectMixin_Vanilla.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/effect/PoisonMobEffectMixin_Vanilla.java similarity index 74% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/effect/PoisonMobEffectMixin_Vanilla.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/effect/PoisonMobEffectMixin_Vanilla.java index 2b5a85ed1..e86fc358d 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/effect/PoisonMobEffectMixin_Vanilla.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/effect/PoisonMobEffectMixin_Vanilla.java @@ -1,8 +1,6 @@ -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; @@ -10,7 +8,6 @@ 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;")) diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/entity/EntityMixin_Vanilla.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/entity/EntityMixin_Vanilla.java index 05d59693e..e7f7b05df 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/entity/EntityMixin_Vanilla.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/entity/EntityMixin_Vanilla.java @@ -1,11 +1,18 @@ package io.izzel.arclight.common.mixin.vanilla.world.entity; import io.izzel.arclight.common.bridge.core.entity.EntityBridge; +import io.izzel.arclight.mixin.Decorate; +import io.izzel.arclight.mixin.DecorationOps; +import net.minecraft.core.BlockPos; +import net.minecraft.tags.FluidTags; import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.material.FluidState; import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; @Mixin(Entity.class) public abstract class EntityMixin_Vanilla implements EntityBridge { @@ -17,4 +24,12 @@ public abstract class EntityMixin_Vanilla implements EntityBridge { @Shadow public abstract void discard(); @Shadow public abstract Level level(); // @formatter:on + + @Decorate(method = "updateFluidHeightAndDoFluidPushing", require = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/material/FluidState;getFlow(Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/phys/Vec3;")) + private Vec3 arclight$setLava(FluidState fluid, BlockGetter level, BlockPos pos) throws Throwable { + if (fluid.getType().is(FluidTags.LAVA)) { + bridge$setLastLavaContact(pos.immutable()); + } + return (Vec3) DecorationOps.callsite().invoke(fluid, level, pos); + } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/SnowGolemMixin_Vanilla.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/entity/animal/SnowGolemMixin_Vanilla.java similarity index 83% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/SnowGolemMixin_Vanilla.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/entity/animal/SnowGolemMixin_Vanilla.java index 51cc9d149..061f4f27b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/SnowGolemMixin_Vanilla.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/entity/animal/SnowGolemMixin_Vanilla.java @@ -1,9 +1,7 @@ -package io.izzel.arclight.common.mixin.core.world.entity.animal; +package io.izzel.arclight.common.mixin.vanilla.world.entity.animal; import com.llamalad7.mixinextras.sugar.Local; -import io.izzel.arclight.api.ArclightPlatform; import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; -import io.izzel.arclight.common.mod.mixins.annotation.OnlyInPlatform; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; @@ -17,7 +15,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(SnowGolem.class) -@OnlyInPlatform(value = {ArclightPlatform.VANILLA, ArclightPlatform.FABRIC}) public abstract class SnowGolemMixin_Vanilla extends PathfinderMobMixin { // Forge/NeoForge: ShearsItem#interactLivingEntity diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/BoggedMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/entity/monster/BoggedMixin_Vanilla.java similarity index 86% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/BoggedMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/entity/monster/BoggedMixin_Vanilla.java index 55a059fed..5ecc260d5 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/BoggedMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/entity/monster/BoggedMixin_Vanilla.java @@ -1,6 +1,7 @@ -package io.izzel.arclight.common.mixin.core.world.entity.monster; +package io.izzel.arclight.common.mixin.vanilla.world.entity.monster; import io.izzel.arclight.common.bridge.core.network.datasync.SynchedEntityDataBridge; +import io.izzel.arclight.common.mixin.core.world.entity.monster.AbstractSkeletonMixin; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; @@ -16,7 +17,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(Bogged.class) -public abstract class BoggedMixin extends AbstractSkeletonMixin { +public abstract class BoggedMixin_Vanilla extends AbstractSkeletonMixin { @Shadow @Final private static EntityDataAccessor DATA_SHEARED; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/item/BucketItemMixin_Vanilla.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/item/BucketItemMixin_Vanilla.java new file mode 100644 index 000000000..775c4fc27 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/item/BucketItemMixin_Vanilla.java @@ -0,0 +1,48 @@ +package io.izzel.arclight.common.mixin.vanilla.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.network.protocol.game.ClientboundBlockUpdatePacket; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.BucketItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.BlockHitResult; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(BucketItem.class) +public abstract class BucketItemMixin_Vanilla implements BucketItemBridge { + @Inject(method = "use", require = 0, 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 hand, CallbackInfoReturnable> cir, @Local BlockHitResult result) { + arclight$setDirection(result.getDirection()); + arclight$setClick(result.getBlockPos()); + arclight$setHand(hand); + } + + @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 cir) { + if (!DistValidate.isValid(worldIn)) { + return; + } + if (player != null && arclight$getStack() != null) { + PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((ServerLevel) worldIn, player, posIn, arclight$getClick(), arclight$getDirection(), arclight$getStack(), arclight$getHand() == null ? InteractionHand.MAIN_HAND : arclight$getHand()); + if (event.isCancelled()) { + ((ServerPlayer) player).connection.send(new ClientboundBlockUpdatePacket(worldIn, posIn)); + ((ServerPlayerEntityBridge) player).bridge$getBukkitEntity().updateInventory(); + cir.setReturnValue(false); + } + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/item/ItemStackMixin_Vanilla.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/item/ItemStackMixin_Vanilla.java index 342b12887..b7ffc4645 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/item/ItemStackMixin_Vanilla.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/item/ItemStackMixin_Vanilla.java @@ -18,17 +18,24 @@ import net.minecraft.world.item.SolidBucketItem; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.block.state.pattern.BlockInWorld; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.craftbukkit.v.inventory.CraftItemStack; import org.bukkit.event.player.PlayerItemDamageEvent; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.function.Consumer; @Mixin(ItemStack.class) public abstract class ItemStackMixin_Vanilla { // @formatter:off + @Shadow private int count; @Shadow public abstract boolean canPlaceOnBlockInAdventureMode(BlockInWorld blockInWorld); @Shadow public abstract Item getItem(); @Shadow public abstract ItemStack copy(); @@ -84,4 +91,11 @@ public InteractionResult useOn(UseOnContext useOnContext) { } return result; } + + @Inject(method = "hurtAndBreak(ILnet/minecraft/server/level/ServerLevel;Lnet/minecraft/server/level/ServerPlayer;Ljava/util/function/Consumer;)V", require = 0, at = @At(value = "INVOKE", target = "Ljava/util/function/Consumer;accept(Ljava/lang/Object;)V")) + private void arclight$itemBreak(int amount, ServerLevel level, @Nullable ServerPlayer serverPlayer, Consumer onBroken, CallbackInfo ci) { + if (this.count == 1 && serverPlayer != null) { + CraftEventFactory.callPlayerItemBreakEvent(serverPlayer, (ItemStack) (Object) this); + } + } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/MilkBucketItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/item/MilkBucketItemMixin_Vanilla.java similarity index 89% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/MilkBucketItemMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/item/MilkBucketItemMixin_Vanilla.java index 248166538..e1980d86d 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/MilkBucketItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/item/MilkBucketItemMixin_Vanilla.java @@ -1,4 +1,4 @@ -package io.izzel.arclight.common.mixin.core.world.item; +package io.izzel.arclight.common.mixin.vanilla.world.item; import io.izzel.arclight.common.bridge.core.entity.LivingEntityBridge; import net.minecraft.world.entity.LivingEntity; @@ -12,8 +12,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(MilkBucketItem.class) -public class MilkBucketItemMixin { - +public abstract class MilkBucketItemMixin_Vanilla { @Inject(method = "finishUsingItem", require = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;removeAllEffects()Z")) private void arclight$cureReason(ItemStack stack, Level worldIn, LivingEntity entityLiving, CallbackInfoReturnable cir) { ((LivingEntityBridge) entityLiving).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.MILK); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/level/LevelMixin_Vanilla.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/level/LevelMixin_Vanilla.java index ca0a95a88..83d4dfdcd 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/level/LevelMixin_Vanilla.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/level/LevelMixin_Vanilla.java @@ -9,7 +9,11 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.LevelChunk; +import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.block.CapturedBlockState; +import org.bukkit.craftbukkit.v.block.CraftBlock; +import org.bukkit.craftbukkit.v.block.data.CraftBlockData; +import org.bukkit.event.block.BlockPhysicsEvent; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; @@ -130,4 +134,26 @@ public boolean setBlock(BlockPos blockPos, BlockState blockState, int i, int j) } } } + + @Inject(method = "setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;II)Z", require = 0, cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;updateNeighbourShapes(Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;II)V")) + private void arclight$callBlockPhysics(BlockPos pos, BlockState state, int i, int j, CallbackInfoReturnable cir) { + try { + if (this.bridge$getWorld() != null) { + BlockPhysicsEvent event = new BlockPhysicsEvent(CraftBlock.at(this, pos), CraftBlockData.fromData(state)); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + cir.setReturnValue(true); + } + } + } catch (StackOverflowError e) { + bridge$setLastPhysicsProblem(pos); + } + } + + @Inject(method = "setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;II)Z", require = 0, cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;onBlockStateChange(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;)V")) + private void arclight$preventPoiUpdate(BlockPos blockPos, BlockState blockState, int i, int j, CallbackInfoReturnable cir) { + if (bridge$preventPoiUpdated()) { + cir.setReturnValue(true); + } + } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/level/ServerPlayerMixin_Vanilla.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/level/ServerPlayerMixin_Vanilla.java similarity index 85% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/level/ServerPlayerMixin_Vanilla.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/level/ServerPlayerMixin_Vanilla.java index 773249ba9..35d3e792c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/level/ServerPlayerMixin_Vanilla.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/level/ServerPlayerMixin_Vanilla.java @@ -1,9 +1,7 @@ -package io.izzel.arclight.common.mixin.core.server.level; +package io.izzel.arclight.common.mixin.vanilla.world.level; import com.mojang.datafixers.util.Either; -import io.izzel.arclight.api.ArclightPlatform; import io.izzel.arclight.common.bridge.core.entity.player.ServerPlayerEntityBridge; -import io.izzel.arclight.common.mod.mixins.annotation.OnlyInPlatform; import net.minecraft.core.BlockPos; import net.minecraft.server.level.*; import net.minecraft.util.Unit; @@ -16,7 +14,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(ServerPlayer.class) -@OnlyInPlatform(value = {ArclightPlatform.VANILLA, ArclightPlatform.FABRIC}) public abstract class ServerPlayerMixin_Vanilla implements ServerPlayerEntityBridge { @Inject(method = "startSleepInBed", require = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;setRespawnPosition(Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/core/BlockPos;FZZ)V")) diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CropBlockMixin_Vanilla.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/level/block/CropBlockMixin_Vanilla.java similarity index 90% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CropBlockMixin_Vanilla.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/level/block/CropBlockMixin_Vanilla.java index 23c2fde95..6ce8cb7dc 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CropBlockMixin_Vanilla.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/level/block/CropBlockMixin_Vanilla.java @@ -1,8 +1,7 @@ -package io.izzel.arclight.common.mixin.core.world.level.block; +package io.izzel.arclight.common.mixin.vanilla.world.level.block; -import io.izzel.arclight.api.ArclightPlatform; import io.izzel.arclight.common.bridge.core.world.WorldBridge; -import io.izzel.arclight.common.mod.mixins.annotation.OnlyInPlatform; +import io.izzel.arclight.common.mixin.core.world.level.block.BlockMixin; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.BlockGetter; @@ -19,7 +18,6 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@OnlyInPlatform(value = {ArclightPlatform.FABRIC, ArclightPlatform.VANILLA}) @Mixin(CropBlock.class) public abstract class CropBlockMixin_Vanilla extends BlockMixin { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/TntBlockMixin_Vanilla.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/level/block/TntBlockMixin_Vanilla.java similarity index 92% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/TntBlockMixin_Vanilla.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/level/block/TntBlockMixin_Vanilla.java index ee7ba566f..9886de22c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/TntBlockMixin_Vanilla.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/level/block/TntBlockMixin_Vanilla.java @@ -1,7 +1,6 @@ -package io.izzel.arclight.common.mixin.core.world.level.block; +package io.izzel.arclight.common.mixin.vanilla.world.level.block; -import io.izzel.arclight.api.ArclightPlatform; -import io.izzel.arclight.common.mod.mixins.annotation.OnlyInPlatform; +import io.izzel.arclight.common.mixin.core.world.level.block.BlockMixin; import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; import net.minecraft.world.ItemInteractionResult; @@ -23,7 +22,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(TntBlock.class) -@OnlyInPlatform(value = {ArclightPlatform.VANILLA, ArclightPlatform.FABRIC}) public abstract class TntBlockMixin_Vanilla extends BlockMixin { @Redirect(method = "playerWillDestroy", require = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/TntBlock;explode(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)V")) diff --git a/arclight-common/src/main/resources/mixins.arclight.core.json b/arclight-common/src/main/resources/mixins.arclight.core.json index ad0275c2a..16734e112 100644 --- a/arclight-common/src/main/resources/mixins.arclight.core.json +++ b/arclight-common/src/main/resources/mixins.arclight.core.json @@ -82,7 +82,6 @@ "server.level.ServerLevelMixin", "server.level.ServerPlayer_RespawnPosAngleMixin", "server.level.ServerPlayerMixin", - "server.level.ServerPlayerMixin_Vanilla", "server.level.TicketTypeMixin", "server.management.BanEntryMixin", "server.management.PlayerListMixin", @@ -105,13 +104,11 @@ "world.effect.HealOrHarmMobEffectMixin", "world.effect.HungerMobEffectMixin", "world.effect.MobEffectUtilMixin", - "world.effect.PoisonMobEffectMixin_Vanilla", "world.effect.RegenerationMobEffectMixin", "world.effect.SaturationMobEffectMixin", "world.entity.AgeableMobMixin", "world.entity.AreaEffectCloudEntityMixin", "world.entity.EntityMixin", - "world.entity.EntityMixin_Vanilla", "world.entity.EntityTypeMixin", "world.entity.ExperienceOrbMixin", "world.entity.IAngerableMixin", @@ -181,7 +178,6 @@ "world.entity.animal.ShoulderRidingEntityMixin", "world.entity.animal.SnifferMixin", "world.entity.animal.SnowGolemMixin", - "world.entity.animal.SnowGolemMixin_Vanilla", "world.entity.animal.TameableAnimalMixin", "world.entity.animal.Turtle_LayEggGoalMixin", "world.entity.animal.TurtleMixin", @@ -212,7 +208,6 @@ "world.entity.item.ItemEntityMixin", "world.entity.item.PrimedTntMixin", "world.entity.monster.AbstractSkeletonMixin", - "world.entity.monster.BoggedMixin", "world.entity.monster.CaveSpiderMixin", "world.entity.monster.CreeperMixin", "world.entity.monster.ElderGuardianMixin", @@ -257,7 +252,6 @@ "world.entity.projectile.DragonFireballMixin", "world.entity.projectile.EvokerFangsMixin", "world.entity.projectile.EyeOfEnderMixin", - "world.entity.projectile.FireballMixin", "world.entity.projectile.FireworkRocketEntityMixin", "world.entity.projectile.FishingHookMixin", "world.entity.projectile.LargeFireballMixin", @@ -346,11 +340,9 @@ "world.item.HangingEntityItemMixin", "world.item.ItemMixin", "world.item.ItemStackMixin", - "world.item.ItemStackMixin_Vanilla", "world.item.LeadItemMixin", "world.item.MerchantMixin", "world.item.MerchantOfferMixin", - "world.item.MilkBucketItemMixin", "world.item.MinecartItemMixin", "world.item.PotionItemMixin", "world.item.ProjectileWeaponItemMixin", @@ -381,7 +373,6 @@ "world.level.GameRules_ValueMixin", "world.level.Level_ExplosionInteractionMixin", "world.level.LevelMixin", - "world.level.LevelMixin_Vanilla", "world.level.block.BambooSaplingBlockMixin", "world.level.block.BambooStalkBlockMixin", "world.level.block.BaseFireBlockMixin", @@ -417,7 +408,6 @@ "world.level.block.CoralPlantBlockMixin", "world.level.block.CoralWallFanBlockMixin", "world.level.block.CropBlockMixin", - "world.level.block.CropBlockMixin_Vanilla", "world.level.block.DaylightDetectorBlockMixin", "world.level.block.DecoratedPotBlockMixin", "world.level.block.DetectorRailBlockMixin", @@ -483,7 +473,6 @@ "world.level.block.SugarCaneBlockMixin", "world.level.block.SweetBerryBushBlockMixin", "world.level.block.TntBlockMixin", - "world.level.block.TntBlockMixin_Vanilla", "world.level.block.TrapDoorBlockMixin", "world.level.block.TripWireBlockMixin", "world.level.block.TripWireHookBlockMixin", diff --git a/arclight-common/src/main/resources/mixins.arclight.vanilla.json b/arclight-common/src/main/resources/mixins.arclight.vanilla.json index dbbfe5285..6d1b49641 100644 --- a/arclight-common/src/main/resources/mixins.arclight.vanilla.json +++ b/arclight-common/src/main/resources/mixins.arclight.vanilla.json @@ -20,17 +20,25 @@ "server.dedicated.DedicatedServer_ServerInputThreadMixin_Vanilla", "server.dedicated.DedicatedServerMixin_Vanilla", "server.level.ServerPlayerGameMode_Vanilla", + "world.effect.PoisonMobEffectMixin_Vanilla", "world.entity.EntityMixin_Vanilla", "world.entity.LivingEntityMixin_Vanilla", "world.entity.animal.MushroomCowMixin_Vanilla", + "world.entity.animal.SnowGolemMixin_Vanilla", "world.entity.animal.frog.TadpoleMixin_Vanilla", + "world.entity.monster.BoggedMixin_Vanilla", "world.entity.monster.ZombieMixin_Vanilla", "world.entity.player.PlayerMixin_Vanilla", "world.entity.player.ServerPlayerMixin_Vanilla", + "world.item.BucketItemMixin_Vanilla", "world.item.ItemStackMixin_Vanilla", + "world.item.MilkBucketItemMixin_Vanilla", "world.level.LevelMixin_Vanilla", + "world.level.ServerPlayerMixin_Vanilla", "world.level.block.BlockMixin_Vanilla", + "world.level.block.CropBlockMixin_Vanilla", "world.level.block.RedstoneOreBlockMixin_Vanilla", + "world.level.block.TntBlockMixin_Vanilla", "world.level.block.entity.AbstractFurnaceBlockEntityMixin_Vanilla", "world.level.levelgen.structure.templatesystem.StructureTemplateMixin_Vanilla" ] diff --git a/arclight-forge/src/main/java/io/izzel/arclight/forge/mixin/core/world/effect/PoisonMobEffectMixin_Forge.java b/arclight-forge/src/main/java/io/izzel/arclight/forge/mixin/core/world/effect/PoisonMobEffectMixin_Forge.java new file mode 100644 index 000000000..41d3c8c75 --- /dev/null +++ b/arclight-forge/src/main/java/io/izzel/arclight/forge/mixin/core/world/effect/PoisonMobEffectMixin_Forge.java @@ -0,0 +1,17 @@ +package io.izzel.arclight.forge.mixin.core.world.effect; + +import io.izzel.arclight.common.bridge.core.util.DamageSourcesBridge; +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") +public abstract class PoisonMobEffectMixin_Forge { + + @Redirect(method = "applyEffectTick", require = 0, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/damagesource/DamageSources;magic()Lnet/minecraft/world/damagesource/DamageSource;")) + private DamageSource arclight$redirectPoison(DamageSources instance) { + return ((DamageSourcesBridge) instance).bridge$poison(); + } +} diff --git a/arclight-forge/src/main/java/io/izzel/arclight/forge/mixin/core/world/item/BucketItemMixin_Forge.java b/arclight-forge/src/main/java/io/izzel/arclight/forge/mixin/core/world/item/BucketItemMixin_Forge.java index 24f93a845..17748bfa7 100644 --- a/arclight-forge/src/main/java/io/izzel/arclight/forge/mixin/core/world/item/BucketItemMixin_Forge.java +++ b/arclight-forge/src/main/java/io/izzel/arclight/forge/mixin/core/world/item/BucketItemMixin_Forge.java @@ -1,6 +1,7 @@ package io.izzel.arclight.forge.mixin.core.world.item; 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; @@ -25,40 +26,23 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @Mixin(BucketItem.class) -public abstract class BucketItemMixin_Forge { - - // @formatter:off - @Shadow(remap = false) public abstract boolean emptyContents(@Nullable Player p_150716_, Level p_150717_, BlockPos p_150718_, @Nullable BlockHitResult p_150719_, @Nullable ItemStack container); - // @formatter:on +public abstract class BucketItemMixin_Forge implements BucketItemBridge { @Inject(method = "use", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", remap = false, 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;Lnet/minecraft/world/item/ItemStack;)Z")) - private void arclight$capture(Level worldIn, Player playerIn, InteractionHand handIn, CallbackInfoReturnable> cir, ItemStack stack, BlockHitResult result) { - arclight$direction = result.getDirection(); - arclight$click = result.getBlockPos(); - arclight$hand = handIn; - } - - 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; - try { - return this.emptyContents(entity, world, pos, result, itemstack); - } finally { - arclight$direction = null; - arclight$click = null; - } + private void arclight$capture(Level worldIn, Player playerIn, InteractionHand hand, CallbackInfoReturnable> cir, ItemStack stack, BlockHitResult result) { + arclight$setDirection(result.getDirection()); + arclight$setClick(result.getBlockPos()); + arclight$setHand(hand); + arclight$setStack(stack); } - private transient Direction arclight$direction; - private transient BlockPos arclight$click; - private transient InteractionHand arclight$hand; - @Inject(method = "emptyContents(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/phys/BlockHitResult;Lnet/minecraft/world/item/ItemStack;)Z", 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, ItemStack stack, CallbackInfoReturnable cir) { - if (!DistValidate.isValid(worldIn)) return; + if (!DistValidate.isValid(worldIn)) { + return; + } if (player != null && stack != null) { - PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((ServerLevel) worldIn, player, posIn, arclight$click, arclight$direction, stack, arclight$hand == null ? InteractionHand.MAIN_HAND : arclight$hand); + PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((ServerLevel) worldIn, player, posIn, arclight$getClick(), arclight$getDirection(), stack, arclight$getHand() == null ? InteractionHand.MAIN_HAND : arclight$getHand()); if (event.isCancelled()) { ((ServerPlayer) player).connection.send(new ClientboundBlockUpdatePacket(worldIn, posIn)); ((ServerPlayerEntityBridge) player).bridge$getBukkitEntity().updateInventory(); diff --git a/arclight-forge/src/main/resources/mixins.arclight.forge.json b/arclight-forge/src/main/resources/mixins.arclight.forge.json index 11f00dad3..711f3fca9 100644 --- a/arclight-forge/src/main/resources/mixins.arclight.forge.json +++ b/arclight-forge/src/main/resources/mixins.arclight.forge.json @@ -32,6 +32,7 @@ "core.server.dedicated.DedicatedServerMixin_Forge", "core.server.level.DistanceManagerMixin_Forge", "core.server.management.ServerPlayerGameModeMixin_Forge", + "core.world.effect.PoisonMobEffectMixin_Forge", "core.world.entity.EntityMixin_Forge", "core.world.entity.LivingEntityMixin_Forge", "core.world.entity.MobMixin_Forge", diff --git a/arclight-neoforge/src/main/java/io/izzel/arclight/neoforge/mixin/core/world/item/BucketItemMixin_NeoForge.java b/arclight-neoforge/src/main/java/io/izzel/arclight/neoforge/mixin/core/world/item/BucketItemMixin_NeoForge.java index 95210afa0..cb82bc56b 100644 --- a/arclight-neoforge/src/main/java/io/izzel/arclight/neoforge/mixin/core/world/item/BucketItemMixin_NeoForge.java +++ b/arclight-neoforge/src/main/java/io/izzel/arclight/neoforge/mixin/core/world/item/BucketItemMixin_NeoForge.java @@ -1,6 +1,8 @@ package io.izzel.arclight.neoforge.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; @@ -25,40 +27,23 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @Mixin(BucketItem.class) -public abstract class BucketItemMixin_NeoForge { +public abstract class BucketItemMixin_NeoForge implements BucketItemBridge { - // @formatter:off - @Shadow(remap = false) public abstract boolean emptyContents(@Nullable Player p_150716_, Level p_150717_, BlockPos p_150718_, @Nullable BlockHitResult p_150719_, @Nullable ItemStack container); - // @formatter:on - - @Inject(method = "use", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", remap = false, 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;Lnet/minecraft/world/item/ItemStack;)Z")) - private void arclight$capture(Level worldIn, Player playerIn, InteractionHand handIn, CallbackInfoReturnable> cir, ItemStack stack, BlockHitResult result) { - arclight$direction = result.getDirection(); - arclight$click = result.getBlockPos(); - arclight$hand = handIn; - } - - 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; - try { - return this.emptyContents(entity, world, pos, result, itemstack); - } finally { - arclight$direction = null; - arclight$click = null; - } + @Inject(method = "use", at = @At(value = "INVOKE", remap = false, 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;Lnet/minecraft/world/item/ItemStack;)Z")) + private void arclight$capture(Level worldIn, Player playerIn, InteractionHand hand, CallbackInfoReturnable> cir, @Local BlockHitResult result, @Local ItemStack stack) { + arclight$setDirection(result.getDirection()); + arclight$setClick(result.getBlockPos()); + arclight$setHand(hand); + arclight$setStack(stack); } - private transient Direction arclight$direction; - private transient BlockPos arclight$click; - private transient InteractionHand arclight$hand; - @Inject(method = "emptyContents(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/phys/BlockHitResult;Lnet/minecraft/world/item/ItemStack;)Z", 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, ItemStack stack, CallbackInfoReturnable cir) { - if (!DistValidate.isValid(worldIn)) return; + if (!DistValidate.isValid(worldIn)) { + return; + } if (player != null && stack != null) { - PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((ServerLevel) worldIn, player, posIn, arclight$click, arclight$direction, stack, arclight$hand == null ? InteractionHand.MAIN_HAND : arclight$hand); + PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((ServerLevel) worldIn, player, posIn, arclight$getClick(), arclight$getDirection(), stack, arclight$getHand() == null ? InteractionHand.MAIN_HAND : arclight$getHand()); if (event.isCancelled()) { ((ServerPlayer) player).connection.send(new ClientboundBlockUpdatePacket(worldIn, posIn)); ((ServerPlayerEntityBridge) player).bridge$getBukkitEntity().updateInventory();