Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silverfish Infestation Logging #284

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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