This repository has been archived by the owner on Jun 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathAntiGhost.java
64 lines (59 loc) · 2.57 KB
/
AntiGhost.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package de.guntram.mcmod.antighost;
import de.guntram.mcmod.crowdintranslate.CrowdinTranslate;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.options.KeyBinding;
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_G;
public class AntiGhost implements ClientModInitializer
{
static final String MODID="antighost";
static KeyBinding requestBlocks;
@Override
public void onInitializeClient()
{
final String category="key.categories.antighost";
requestBlocks = new KeyBinding("key.antighost.reveal", GLFW_KEY_G, category);
CrowdinTranslate.downloadTranslations(MODID);
KeyBindingHelper.registerKeyBinding(requestBlocks);
ClientTickEvents.END_CLIENT_TICK.register(e->keyPressed());
ClientCommandManager.DISPATCHER.register(
ClientCommandManager.literal("ghost").executes(c -> {
this.execute();
return 1;
})
);
}
public void keyPressed() {
ClientPlayerEntity player = MinecraftClient.getInstance().player;
if (requestBlocks.wasPressed()) {
this.execute();
player.sendMessage(new TranslatableText("msg.request"), false);
}
}
public void execute() {
MinecraftClient mc=MinecraftClient.getInstance();
ClientPlayNetworkHandler conn = mc.getNetworkHandler();
if (conn==null)
return;
BlockPos pos=mc.player.getBlockPos();
for (int dx=-4; dx<=4; dx++)
for (int dy=-4; dy<=4; dy++)
for (int dz=-4; dz<=4; dz++) {
PlayerActionC2SPacket packet=new PlayerActionC2SPacket(
PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK,
new BlockPos(pos.getX()+dx, pos.getY()+dy, pos.getZ()+dz),
Direction.UP // with ABORT_DESTROY_BLOCK, this value is unused
);
conn.sendPacket(packet);
}
}
}