-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Silverfish Infestation Logging (#284)
- Loading branch information
1 parent
6ba5b10
commit 974d718
Showing
3 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...va/com/github/quiltservertools/ledger/mixin/entities/silverfish/CallForHelpGoalMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
...om/github/quiltservertools/ledger/mixin/entities/silverfish/WanderAndInfestGoalMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters