diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/silverfish/CallForHelpGoalMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/silverfish/CallForHelpGoalMixin.java new file mode 100644 index 00000000..f1306831 --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/silverfish/CallForHelpGoalMixin.java @@ -0,0 +1,45 @@ +package com.github.quiltservertools.ledger.mixin.entities.silverfish; + +import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import net.minecraft.entity.Entity; +import net.minecraft.registry.Registries; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin( + targets = "net.minecraft.entity.mob.SilverfishEntity$CallForHelpGoal" +) +public class CallForHelpGoalMixin { + + @WrapOperation( + method = "tick", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/World;breakBlock(Lnet/minecraft/util/math/BlockPos;ZLnet/minecraft/entity/Entity;)Z" + ) + ) + private boolean logSilverFishBreakInfestedBlock( + World world, + BlockPos pos, + boolean drop, + Entity entity, + Operation original + ) { + String source = Registries.ENTITY_TYPE.getId(entity.getType()).getPath(); + BlockBreakCallback.EVENT.invoker() + .breakBlock( + world, + pos, + world.getBlockState(pos), + null, + source + ); + + return original.call(world, pos, drop, entity); + } + +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/silverfish/WanderAndInfestGoalMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/silverfish/WanderAndInfestGoalMixin.java new file mode 100644 index 00000000..fcb2590a --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/silverfish/WanderAndInfestGoalMixin.java @@ -0,0 +1,54 @@ +package com.github.quiltservertools.ledger.mixin.entities.silverfish; + +import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import net.minecraft.block.BlockState; +import net.minecraft.entity.ai.goal.WanderAroundGoal; +import net.minecraft.entity.mob.PathAwareEntity; +import net.minecraft.registry.Registries; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.WorldAccess; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin( + targets = "net.minecraft.entity.mob.SilverfishEntity$WanderAndInfestGoal" +) +public abstract class WanderAndInfestGoalMixin extends WanderAroundGoal { + + public WanderAndInfestGoalMixin(PathAwareEntity mob, double speed) { + super(mob, speed); + } + + @WrapOperation( + method = "start", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/WorldAccess;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z" + ) + ) + private boolean logSilverFishInfestBlock( + WorldAccess worldAccess, + BlockPos pos, + BlockState state, + int flags, + Operation original + ) { + BlockState oldState = worldAccess.getBlockState(pos); + String source = Registries.ENTITY_TYPE.getId(this.mob.getType()).getPath(); + + BlockChangeCallback.EVENT.invoker() + .changeBlock( + this.mob.getWorld(), + pos, + oldState, + state, + null, + null, + source + ); + + return original.call(worldAccess, pos, state, flags); + } +} diff --git a/src/main/resources/ledger.mixins.json b/src/main/resources/ledger.mixins.json index c5f6c5e4..3707605d 100644 --- a/src/main/resources/ledger.mixins.json +++ b/src/main/resources/ledger.mixins.json @@ -19,8 +19,8 @@ "HoeItemMixin", "HoneycombItemMixin", "ItemScattererMixin", - "LockableContainerBlockEntityMixin", "JukeboxPlayableComponentMixin", + "LockableContainerBlockEntityMixin", "NetherPortalMixin", "ScreenHandlerMixin", "SetBlockCommandMixin", @@ -90,6 +90,8 @@ "entities.SnowGolemEntityMixin", "entities.VillagerEntityMixin", "entities.WolfEntityMixin", + "entities.silverfish.CallForHelpGoalMixin", + "entities.silverfish.WanderAndInfestGoalMixin", "preview.ChestBlockMixin", "preview.EntityTrackerEntryAccessor", "preview.LockableContainerBlockEntityMixin",