From b42cfe4f8e5a9a13f870c918e38f294f132a1ba3 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 10 Sep 2024 00:10:59 +0100 Subject: [PATCH] Prevent block tracking --- .../AlwaysReturnNoBlockSourceMixin.java | 20 +++++++++++++ .../DoNotRegisterBlockBreakListenerMixin.java | 25 ++++++++++++++++ .../DoNotRegisterBlockPlaceListenerMixin.java | 25 ++++++++++++++++ .../DoNotRegisterUseBlockListenerMixin.java | 24 +++++++++++++++ .../chesttracker/utilities/VoidEvents.java | 30 +++++++++++++++++++ .../resources/civchesttracker.mixins.json | 5 +++- 6 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 src/main/java/uk/protonull/civ/chesttracker/mixins/illegal/AlwaysReturnNoBlockSourceMixin.java create mode 100644 src/main/java/uk/protonull/civ/chesttracker/mixins/illegal/DoNotRegisterBlockBreakListenerMixin.java create mode 100644 src/main/java/uk/protonull/civ/chesttracker/mixins/illegal/DoNotRegisterBlockPlaceListenerMixin.java create mode 100644 src/main/java/uk/protonull/civ/chesttracker/mixins/illegal/DoNotRegisterUseBlockListenerMixin.java create mode 100644 src/main/java/uk/protonull/civ/chesttracker/utilities/VoidEvents.java diff --git a/src/main/java/uk/protonull/civ/chesttracker/mixins/illegal/AlwaysReturnNoBlockSourceMixin.java b/src/main/java/uk/protonull/civ/chesttracker/mixins/illegal/AlwaysReturnNoBlockSourceMixin.java new file mode 100644 index 0000000..2e085e9 --- /dev/null +++ b/src/main/java/uk/protonull/civ/chesttracker/mixins/illegal/AlwaysReturnNoBlockSourceMixin.java @@ -0,0 +1,20 @@ +package uk.protonull.civ.chesttracker.mixins.illegal; + +import java.util.Optional; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import red.jackf.chesttracker.api.ClientBlockSource; +import red.jackf.chesttracker.impl.providers.InteractionTrackerImpl; + +@SuppressWarnings("UnstableApiUsage") +@Mixin(InteractionTrackerImpl.class) +public abstract class AlwaysReturnNoBlockSourceMixin { + /** + * @author Protonull + * @reason Always return an empty optional. + */ + @Overwrite(remap = false) + public Optional getLastBlockSource() { + return Optional.empty(); + } +} diff --git a/src/main/java/uk/protonull/civ/chesttracker/mixins/illegal/DoNotRegisterBlockBreakListenerMixin.java b/src/main/java/uk/protonull/civ/chesttracker/mixins/illegal/DoNotRegisterBlockBreakListenerMixin.java new file mode 100644 index 0000000..2281be9 --- /dev/null +++ b/src/main/java/uk/protonull/civ/chesttracker/mixins/illegal/DoNotRegisterBlockBreakListenerMixin.java @@ -0,0 +1,25 @@ +package uk.protonull.civ.chesttracker.mixins.illegal; + +import net.fabricmc.fabric.api.event.Event; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; +import red.jackf.chesttracker.impl.events.AfterPlayerDestroyBlock; +import red.jackf.chesttracker.impl.memory.MemoryIntegrity; +import uk.protonull.civ.chesttracker.utilities.VoidEvents; + +@SuppressWarnings({"UnstableApiUsage"}) +@Mixin(MemoryIntegrity.class) +public abstract class DoNotRegisterBlockBreakListenerMixin { + @Redirect( + method = "setup", + at = @At( + value = "FIELD", + target = "Lred/jackf/chesttracker/impl/events/AfterPlayerDestroyBlock;EVENT:Lnet/fabricmc/fabric/api/event/Event;" + ), + remap = false + ) + private static Event ctt$redirect$preventRegistration() { + return VoidEvents.AFTER_PLAYER_DESTROY_BLOCK; + } +} diff --git a/src/main/java/uk/protonull/civ/chesttracker/mixins/illegal/DoNotRegisterBlockPlaceListenerMixin.java b/src/main/java/uk/protonull/civ/chesttracker/mixins/illegal/DoNotRegisterBlockPlaceListenerMixin.java new file mode 100644 index 0000000..888d077 --- /dev/null +++ b/src/main/java/uk/protonull/civ/chesttracker/mixins/illegal/DoNotRegisterBlockPlaceListenerMixin.java @@ -0,0 +1,25 @@ +package uk.protonull.civ.chesttracker.mixins.illegal; + +import net.fabricmc.fabric.api.event.Event; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; +import red.jackf.chesttracker.impl.events.AfterPlayerPlaceBlock; +import red.jackf.chesttracker.impl.providers.ProviderHandler; +import uk.protonull.civ.chesttracker.utilities.VoidEvents; + +@SuppressWarnings({"UnstableApiUsage"}) +@Mixin(ProviderHandler.class) +public abstract class DoNotRegisterBlockPlaceListenerMixin { + @Redirect( + method = "setupEvents", + at = @At( + value = "FIELD", + target = "Lred/jackf/chesttracker/impl/events/AfterPlayerPlaceBlock;EVENT:Lnet/fabricmc/fabric/api/event/Event;" + ), + remap = false + ) + protected Event ctt$redirect$preventRegistration() { + return VoidEvents.AFTER_PLAYER_PLACE_BLOCK; + } +} diff --git a/src/main/java/uk/protonull/civ/chesttracker/mixins/illegal/DoNotRegisterUseBlockListenerMixin.java b/src/main/java/uk/protonull/civ/chesttracker/mixins/illegal/DoNotRegisterUseBlockListenerMixin.java new file mode 100644 index 0000000..9d21528 --- /dev/null +++ b/src/main/java/uk/protonull/civ/chesttracker/mixins/illegal/DoNotRegisterUseBlockListenerMixin.java @@ -0,0 +1,24 @@ +package uk.protonull.civ.chesttracker.mixins.illegal; + +import net.fabricmc.fabric.api.event.Event; +import net.fabricmc.fabric.api.event.player.UseBlockCallback; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; +import red.jackf.chesttracker.impl.providers.InteractionTrackerImpl; +import uk.protonull.civ.chesttracker.utilities.VoidEvents; + +@Mixin(InteractionTrackerImpl.class) +public abstract class DoNotRegisterUseBlockListenerMixin { + @Redirect( + method = "setup", + at = @At( + value = "FIELD", + target = "Lnet/fabricmc/fabric/api/event/player/UseBlockCallback;EVENT:Lnet/fabricmc/fabric/api/event/Event;" + ), + remap = false + ) + private static Event ctt$redirect$preventRegistration() { + return VoidEvents.USE_BLOCK_CALLBACK; + } +} diff --git a/src/main/java/uk/protonull/civ/chesttracker/utilities/VoidEvents.java b/src/main/java/uk/protonull/civ/chesttracker/utilities/VoidEvents.java new file mode 100644 index 0000000..21032e1 --- /dev/null +++ b/src/main/java/uk/protonull/civ/chesttracker/utilities/VoidEvents.java @@ -0,0 +1,30 @@ +package uk.protonull.civ.chesttracker.utilities; + +import net.fabricmc.fabric.api.event.Event; +import net.fabricmc.fabric.api.event.player.UseBlockCallback; +import red.jackf.chesttracker.impl.events.AfterPlayerDestroyBlock; +import red.jackf.chesttracker.impl.events.AfterPlayerPlaceBlock; + +@SuppressWarnings({"UnstableApiUsage", "NonExtendableApiUsage"}) +public final class VoidEvents { + public static final Event USE_BLOCK_CALLBACK = new Event<>() { + @Override + public void register(final UseBlockCallback listener) { + // Do nothing + } + }; + + public static final Event AFTER_PLAYER_PLACE_BLOCK = new Event<>() { + @Override + public void register(final AfterPlayerPlaceBlock listener) { + // Do nothing + } + }; + + public static final Event AFTER_PLAYER_DESTROY_BLOCK = new Event<>() { + @Override + public void register(final AfterPlayerDestroyBlock listener) { + // Do nothing + } + }; +} diff --git a/src/main/resources/civchesttracker.mixins.json b/src/main/resources/civchesttracker.mixins.json index 017c74b..343f5fe 100644 --- a/src/main/resources/civchesttracker.mixins.json +++ b/src/main/resources/civchesttracker.mixins.json @@ -5,7 +5,10 @@ "compatibilityLevel": "JAVA_21", "mixins": [], "client": [ - + "illegal.AlwaysReturnNoBlockSourceMixin", + "illegal.DoNotRegisterBlockBreakListenerMixin", + "illegal.DoNotRegisterBlockPlaceListenerMixin", + "illegal.DoNotRegisterUseBlockListenerMixin" ], "injectors": { "defaultRequire": 1