Skip to content

Commit

Permalink
Silverfish Infestation Logging (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDeathlyCow authored Aug 15, 2024
1 parent 6ba5b10 commit 974d718
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<Boolean> 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);
}

}
Original file line number Diff line number Diff line change
@@ -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<Boolean> 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);
}
}
4 changes: 3 additions & 1 deletion src/main/resources/ledger.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"HoeItemMixin",
"HoneycombItemMixin",
"ItemScattererMixin",
"LockableContainerBlockEntityMixin",
"JukeboxPlayableComponentMixin",
"LockableContainerBlockEntityMixin",
"NetherPortalMixin",
"ScreenHandlerMixin",
"SetBlockCommandMixin",
Expand Down Expand Up @@ -90,6 +90,8 @@
"entities.SnowGolemEntityMixin",
"entities.VillagerEntityMixin",
"entities.WolfEntityMixin",
"entities.silverfish.CallForHelpGoalMixin",
"entities.silverfish.WanderAndInfestGoalMixin",
"preview.ChestBlockMixin",
"preview.EntityTrackerEntryAccessor",
"preview.LockableContainerBlockEntityMixin",
Expand Down

0 comments on commit 974d718

Please sign in to comment.