diff --git a/common/src/main/java/dev/ryanhcode/sable/mixin/stop_lightning/ServerLevelMixin.java b/common/src/main/java/dev/ryanhcode/sable/mixin/stop_lightning/ServerLevelMixin.java new file mode 100644 index 00000000..2b4e176c --- /dev/null +++ b/common/src/main/java/dev/ryanhcode/sable/mixin/stop_lightning/ServerLevelMixin.java @@ -0,0 +1,29 @@ +package dev.ryanhcode.sable.mixin.stop_lightning; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; +import dev.ryanhcode.sable.api.sublevel.SubLevelContainer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.chunk.LevelChunk; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +/** + * Prevents lightning or skeleton traps from spawning inside plots to avoid inflating spawn rates + */ +@Mixin(ServerLevel.class) +public class ServerLevelMixin { + + @WrapOperation(method="tickChunk", at=@At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;isThundering()Z")) + private boolean sable$preventLightningInPlot(final ServerLevel instance, final Operation original, @Local(argsOnly = true) final LevelChunk chunk) { + final SubLevelContainer plotContainer = SubLevelContainer.getContainer((ServerLevel) (Object) this); + assert plotContainer != null; + + if (plotContainer.getPlot(chunk.getPos()) != null) { + return false; + } + return original.call(instance); + } + +} \ No newline at end of file diff --git a/common/src/main/resources/sable.mixins.json b/common/src/main/resources/sable.mixins.json index faf5ee1b..33dcb788 100644 --- a/common/src/main/resources/sable.mixins.json +++ b/common/src/main/resources/sable.mixins.json @@ -208,6 +208,7 @@ "sculk_vibrations.VibrationSystemListenerMixin", "sculk_vibrations.VibrationSystemTickerMixin", "sign_interaction.SignBlockEntityMixin", + "stop_lightning.ServerLevelMixin", "tracking_points.EntityMixin", "tracking_points.ServerPlayerMixin", "udp.ConnectionMixin",