Skip to content

Commit

Permalink
Removed title being set by default, and made Positive more data-based
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubyboat1207 committed Jan 17, 2023
1 parent 637514a commit 25e90ae
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/main/java/rubyboat/ghost/Main.java
Original file line number Diff line number Diff line change
@@ -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);
});
}
}
12 changes: 11 additions & 1 deletion src/main/java/rubyboat/ghost/client/GhostClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -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();
}
}
2 changes: 1 addition & 1 deletion src/main/java/rubyboat/ghost/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/rubyboat/ghost/mixin/DebugHudMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ Object[] DisableYNegativesOnBlock(Object[] args) {
}
return args;
}

int getAddition() {
return Math.abs(MinecraftClient.getInstance().player.getWorld().getDimension().minY()) ;
}
}
28 changes: 28 additions & 0 deletions src/main/java/rubyboat/ghost/server/NetworkHandler.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 25e90ae

Please sign in to comment.