Skip to content

Commit

Permalink
Prevent block tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
Protonull committed Sep 10, 2024
1 parent 122313e commit b42cfe4
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<ClientBlockSource> getLastBlockSource() {
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
@@ -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<AfterPlayerDestroyBlock> ctt$redirect$preventRegistration() {
return VoidEvents.AFTER_PLAYER_DESTROY_BLOCK;
}
}
Original file line number Diff line number Diff line change
@@ -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<AfterPlayerPlaceBlock> ctt$redirect$preventRegistration() {
return VoidEvents.AFTER_PLAYER_PLACE_BLOCK;
}
}
Original file line number Diff line number Diff line change
@@ -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<UseBlockCallback> ctt$redirect$preventRegistration() {
return VoidEvents.USE_BLOCK_CALLBACK;
}
}
Original file line number Diff line number Diff line change
@@ -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<UseBlockCallback> USE_BLOCK_CALLBACK = new Event<>() {
@Override
public void register(final UseBlockCallback listener) {
// Do nothing
}
};

public static final Event<AfterPlayerPlaceBlock> AFTER_PLAYER_PLACE_BLOCK = new Event<>() {
@Override
public void register(final AfterPlayerPlaceBlock listener) {
// Do nothing
}
};

public static final Event<AfterPlayerDestroyBlock> AFTER_PLAYER_DESTROY_BLOCK = new Event<>() {
@Override
public void register(final AfterPlayerDestroyBlock listener) {
// Do nothing
}
};
}
5 changes: 4 additions & 1 deletion src/main/resources/civchesttracker.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"compatibilityLevel": "JAVA_21",
"mixins": [],
"client": [

"illegal.AlwaysReturnNoBlockSourceMixin",
"illegal.DoNotRegisterBlockBreakListenerMixin",
"illegal.DoNotRegisterBlockPlaceListenerMixin",
"illegal.DoNotRegisterUseBlockListenerMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit b42cfe4

Please sign in to comment.