diff --git a/src/main/java/rubyboat/ghost/Main.java b/src/main/java/rubyboat/ghost/Main.java new file mode 100644 index 0000000..2a73465 --- /dev/null +++ b/src/main/java/rubyboat/ghost/Main.java @@ -0,0 +1,18 @@ +package rubyboat.ghost; + +import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; +import rubyboat.ghost.server.NetworkHandler; + +public class Main implements ModInitializer { + public static final String MOD_ID = "ghost"; + + @Override + public void onInitialize() { + System.out.println("test"); + ServerPlayConnectionEvents.JOIN.register((handler, sender, client) -> { + System.out.println("sent allow midair blocks"); + NetworkHandler.sendAllowMidAirBlocks(handler.player, true); + }); + } +} diff --git a/src/main/java/rubyboat/ghost/client/GhostClient.java b/src/main/java/rubyboat/ghost/client/GhostClient.java index 26a707a..4e04113 100644 --- a/src/main/java/rubyboat/ghost/client/GhostClient.java +++ b/src/main/java/rubyboat/ghost/client/GhostClient.java @@ -4,7 +4,10 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; +import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.minecraft.block.AbstractBlock; import net.minecraft.block.Block; @@ -17,17 +20,20 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.lwjgl.glfw.GLFW; +import rubyboat.ghost.server.NetworkHandler; @Environment(EnvType.CLIENT) public class GhostClient implements ClientModInitializer { public static KeyBinding keyBinding; public static KeyBinding keyBinding2; - public static KeyBinding zoom; private static final Logger LOGGER = LogManager.getLogger(); public static float roundTo(float number, int decimalPoints) { return (float) (Math.floor(number * Math.pow(10, decimalPoints)) * Math.pow(10, -decimalPoints)); } + + public static boolean AllowMidAirGhostBlocks = false; + @Override public void onInitializeClient() { LOGGER.log(Level.INFO, AbstractBlock.class.getName()); @@ -43,5 +49,9 @@ public void onInitializeClient() { GLFW.GLFW_KEY_RIGHT_SHIFT, // The keycode of the key "category.ghost.general" // The translation key of the keybinding's category. )); + ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> { + AllowMidAirGhostBlocks = false; + }); + NetworkHandler.registerS2CPackets(); } } diff --git a/src/main/java/rubyboat/ghost/config/Config.java b/src/main/java/rubyboat/ghost/config/Config.java index 9c18e31..19e7698 100644 --- a/src/main/java/rubyboat/ghost/config/Config.java +++ b/src/main/java/rubyboat/ghost/config/Config.java @@ -53,7 +53,7 @@ public class Config { static boolean antfarm = false; static String inPowderSnowEffect = "none"; static Integer fog = 000000; - static String title = "Minecraft"; + static String title = ""; static Integer color = 0; static Integer time = -1; static Integer leaf = 0; diff --git a/src/main/java/rubyboat/ghost/mixin/DebugHudMixin.java b/src/main/java/rubyboat/ghost/mixin/DebugHudMixin.java index 2cb5e9d..18f8047 100644 --- a/src/main/java/rubyboat/ghost/mixin/DebugHudMixin.java +++ b/src/main/java/rubyboat/ghost/mixin/DebugHudMixin.java @@ -57,4 +57,8 @@ Object[] DisableYNegativesOnBlock(Object[] args) { } return args; } + + int getAddition() { + return Math.abs(MinecraftClient.getInstance().player.getWorld().getDimension().minY()) ; + } } diff --git a/src/main/java/rubyboat/ghost/server/NetworkHandler.java b/src/main/java/rubyboat/ghost/server/NetworkHandler.java new file mode 100644 index 0000000..adb94de --- /dev/null +++ b/src/main/java/rubyboat/ghost/server/NetworkHandler.java @@ -0,0 +1,28 @@ +package rubyboat.ghost.server; + +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Identifier; +import rubyboat.ghost.Main; +import rubyboat.ghost.client.GhostClient; + +public class NetworkHandler { + public static final Identifier ALLOW_MIDAIR_BLOCKS = new Identifier(Main.MOD_ID, "allow_midair_blocks"); + + + public static void registerS2CPackets() { + ClientPlayNetworking.registerGlobalReceiver(ALLOW_MIDAIR_BLOCKS, (client, handler, buf, responseSender) -> { + GhostClient.AllowMidAirGhostBlocks = buf.readBoolean(); + System.out.println("allow midair blocks: " + GhostClient.AllowMidAirGhostBlocks); + }); + } + + public static void sendAllowMidAirBlocks(ServerPlayerEntity player, boolean allow) { + PacketByteBuf buf = PacketByteBufs.create(); + buf.writeBoolean(allow); + ServerPlayNetworking.send(player, ALLOW_MIDAIR_BLOCKS, buf); + } +}