Skip to content

Commit

Permalink
Added the ChatCoordinatesScreen with the check feature
Browse files Browse the repository at this point in the history
  • Loading branch information
The2019 committed Nov 16, 2023
1 parent 1b5174f commit 08f32df
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/client/java/net/The2019/NewBase/NewBaseClient.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package net.The2019.NewBase;

import net.The2019.NewBase.features.BeeHiveHelper;
import net.The2019.NewBase.features.ChunkRender;
import net.The2019.NewBase.render.HudRender;
import net.The2019.NewBase.screen.ConfigScreen;
import net.The2019.NewBase.utils.InitKeyBindings;
import net.The2019.NewBase.utils.PermissionLevel;
import net.fabricmc.api.ClientModInitializer;
Expand All @@ -16,10 +16,11 @@ public void onInitializeClient() {
PermissionLevel.initAllowedPlayers();
HudRender.registerHudRendering();

BeeHiveHelper.register();
//BeeHiveHelper.register();
ChunkRender.renderChunkOutline();

InitKeyBindings.initKeys();
ConfigScreen.addDrawables();

}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package net.The2019.NewBase.features;

import net.The2019.NewBase.screen.ChatCoordinatesScreen;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.math.BlockPos;

public class ChatCoordinates {
private static final MinecraftClient mc = MinecraftClient.getInstance();

public static void sendCoordinates(){
if (mc.player != null) {
BlockPos playerPos = mc.player.getBlockPos();
mc.player.networkHandler.sendChatMessage(String.format("X: %s Y: %s Z: %s", playerPos.getX(), playerPos.getY(), playerPos.getZ()));
}
mc.setScreen(new ChatCoordinatesScreen(mc.currentScreen, mc.options));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package net.The2019.NewBase.screen;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TextWidget;
import net.minecraft.client.option.GameOptions;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;

import java.util.ArrayList;

public class ChatCoordinatesScreen extends Screen {
private final Screen parent;
private final GameOptions settings;
private static final MinecraftClient mc = MinecraftClient.getInstance();

public ChatCoordinatesScreen(Screen parent, GameOptions options) {
super(Text.of("Chat Coordinates Screen"));
this.parent = parent;
this.settings = options;
}

@Override
protected void init() {
ButtonWidget yesButton = new ButtonWidget.Builder(Text.literal("§aYes"), button -> {
if (mc.player != null) {
BlockPos playerPos = mc.player.getBlockPos();
mc.player.networkHandler.sendChatMessage(String.format("X: %s Y: %s Z: %s", playerPos.getX(), playerPos.getY(), playerPos.getZ()));
mc.setScreen(null);
}
}).dimensions(this.width / 2 - 90, this.height / 2, 80, 20).build();

ButtonWidget noButton = new ButtonWidget.Builder(Text.literal("§4No"), button -> {
mc.setScreen(null);
}).dimensions(this.width / 2, this.height / 2, 80, 20).build();

this.addDrawable(new TextWidget(this.width / 2 - 250, this.height / 2 - 30, 500, 20, Text.of("Press §aYes §fto send Coordinates in the chat or §4No §fto return back to the game."), textRenderer));
this.addDrawableChild(yesButton);
this.addDrawableChild(noButton);
}
}

20 changes: 16 additions & 4 deletions src/client/java/net/The2019/NewBase/screen/ConfigScreen.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package net.The2019.NewBase.screen;

import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.Drawable;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TextWidget;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.option.GameOptions;
import net.minecraft.text.Text;

import java.util.ArrayList;

public class ConfigScreen extends Screen {
private final Screen parent;
private final GameOptions settings;
private final String name;
private static ArrayList<Drawable> drawables = new ArrayList<>();
private static final MinecraftClient mc = MinecraftClient.getInstance();

public ConfigScreen(Screen parent, GameOptions gameOptions, String name){
super(Text.of("Config Screen"));
Expand All @@ -18,12 +25,17 @@ public ConfigScreen(Screen parent, GameOptions gameOptions, String name){
this.name = name;
}

public static void addDrawables(){
drawables.add(new TextWidget(20, 20, 80, 10, Text.of("1"),mc.textRenderer));
drawables.add(new TextWidget(20, 30, 80, 10, Text.of("2"),mc.textRenderer));
}

@Override
protected void init() {
this.addDrawable(new TextWidget(20, 10, 80, 10, Text.of(this.name), textRenderer));
}

@Override
public void renderInGameBackground(DrawContext context) {
for(Drawable drawable : drawables){
this.addDrawable(drawable);
}
}
}

0 comments on commit 08f32df

Please sign in to comment.