Skip to content

Commit

Permalink
Implemented new Hud rendering system and added permission levels
Browse files Browse the repository at this point in the history
  • Loading branch information
The2019 committed Oct 31, 2023
1 parent 4343fb6 commit b100857
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 17 deletions.
7 changes: 7 additions & 0 deletions src/client/java/net/The2019/NewBase/NewBaseClient.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package net.The2019.NewBase;

import net.The2019.NewBase.features.AutoCrystal;
import net.The2019.NewBase.features.BiomDisplay;
import net.The2019.NewBase.features.CoordinatesDisplay;
import net.The2019.NewBase.features.Placer;
import net.The2019.NewBase.render.HudRender;
import net.The2019.NewBase.utils.PermsionLevel;
import net.fabricmc.api.ClientModInitializer;

public class NewBaseClient implements ClientModInitializer {
Expand All @@ -12,9 +14,14 @@ public class NewBaseClient implements ClientModInitializer {

@Override
public void onInitializeClient() {

PermsionLevel.init();
PermsionLevel.isPlayerAllowed();

HudRender.hudRendering();
Placer.place();
BiomDisplay.biomDisplay();
CoordinatesDisplay.coordinates();
AutoCrystal.autoCrystal();
}
}
28 changes: 28 additions & 0 deletions src/client/java/net/The2019/NewBase/features/AutoCrystal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package net.The2019.NewBase.features;

import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.decoration.EndCrystalEntity;

import static net.The2019.NewBase.utils.PermsionLevel.isPlayerAllowed;

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

public static void autoCrystal(){
if(isPlayerAllowed){
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (mc.world != null) {
for(Entity entity : mc.world.getEntities()){
if(entity instanceof EndCrystalEntity){
if (mc.interactionManager != null) {
mc.interactionManager.attackEntity(mc.player, entity);
}
}
}
}
});
}
}
}
9 changes: 9 additions & 0 deletions src/client/java/net/The2019/NewBase/features/FpsDisplay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.The2019.NewBase.features;

import net.minecraft.client.MinecraftClient;

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

public static String fps = mc.fpsDebugString.toString();
}
21 changes: 12 additions & 9 deletions src/client/java/net/The2019/NewBase/features/Placer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@
import net.minecraft.util.hit.BlockHitResult;
import org.lwjgl.glfw.GLFW;

import static net.The2019.NewBase.utils.PermsionLevel.isPlayerAllowed;
import static net.The2019.NewBase.utils.SendPacket.sendPackets;

public class Placer {

private static final MinecraftClient mc = MinecraftClient.getInstance();

public static void place(){
KeyBinding placer = KeyBindingHelper.registerKeyBinding(new KeyBinding("Place", GLFW.GLFW_KEY_B, "New Base"));
if(isPlayerAllowed){
KeyBinding placer = KeyBindingHelper.registerKeyBinding(new KeyBinding("Place", GLFW.GLFW_KEY_B, "New Base"));

ClientTickEvents.END_CLIENT_TICK.register(client -> {
if(placer.wasPressed()){
BlockHitResult blockHitResult = ((BlockHitResult) mc.crosshairTarget);
mc.player.swingHand(mc.player.getActiveHand());
sendPackets(new PlayerInteractBlockC2SPacket(Hand.MAIN_HAND, blockHitResult, 1));
}
});
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if(placer.wasPressed()) {
BlockHitResult blockHitResult = ((BlockHitResult) mc.crosshairTarget);
mc.player.swingHand(mc.player.getActiveHand());
sendPackets(new PlayerInteractBlockC2SPacket(Hand.MAIN_HAND, blockHitResult, 1));
}
});
}
}
}
34 changes: 26 additions & 8 deletions src/client/java/net/The2019/NewBase/render/HudRender.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
package net.The2019.NewBase.render;

import net.The2019.NewBase.features.CoordinatesDisplay;
import net.The2019.NewBase.features.BiomDisplay;
import net.The2019.NewBase.features.CoordinatesDisplay;
import net.The2019.NewBase.features.FpsDisplay;
import net.The2019.NewBase.utils.DisplayElements;
import net.The2019.NewBase.utils.DisplayTextSupplier;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;

public class HudRender {
private static final MinecraftClient mc = MinecraftClient.getInstance();
private static final List<DisplayElements> displayElements = new ArrayList<>();

public static void hudRendering() {
// Add your display elements to the list
displayElements.add(new DisplayElements("Coordinates", Color.GREEN.getRGB(), () -> "X: " + CoordinatesDisplay.x + " Y: " + CoordinatesDisplay.y + " Z: " + CoordinatesDisplay.z));
displayElements.add(new DisplayElements("Biom", Color.GREEN.getRGB(), () -> "Biom: " + BiomDisplay.biom));
displayElements.add(new DisplayElements("Fps", Color.GREEN.getRGB(), () -> "FPS: " + FpsDisplay.fps));

HudRenderCallback.EVENT.register((drawContext, tickDelta) -> {
TextRenderer renderer = mc.textRenderer;
int yOffset = 10;

public static void hudRendering(){
HudRenderCallback.EVENT.register((drawContext, tickDelta) -> {
TextRenderer renderer = mc.textRenderer;
drawContext.drawText(renderer,"X: " + CoordinatesDisplay.x + " " + "Y: " + CoordinatesDisplay.y + " " + "Z: " + CoordinatesDisplay.z, 10, 10, Color.GREEN.getRGB(), false);
drawContext.drawText(renderer, "Biom: " + BiomDisplay.biom, 10, 20, Color.GREEN.getRGB(), false);
});
// Render each active display element
for (DisplayElements element : displayElements) {
if (element.isActive()) {
drawContext.drawText(renderer, element.getText(), 10, yOffset, element.getColor(), false);
yOffset += 10; // Adjust the Y position for the next element
}
}
});
}
}
}
36 changes: 36 additions & 0 deletions src/client/java/net/The2019/NewBase/utils/DisplayElements.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package net.The2019.NewBase.utils;

public class DisplayElements {
private final String name;
private final int color;
private final DisplayTextSupplier textSupplier;
private boolean active;

public DisplayElements(String name, int color, DisplayTextSupplier textSupplier) {
this.name = name;
this.color = color;
this.textSupplier = textSupplier;
this.active = true; // Elements are active by default
}

public String getText() {
return textSupplier.getDisplayText();
}

public boolean isActive() {
return active;
}

public void setActive(boolean active) {
this.active = active;
}

public String getName() {
return name;
}

public int getColor() {
return color;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.The2019.NewBase.utils;

@FunctionalInterface
public interface DisplayTextSupplier {
String getDisplayText();
}
29 changes: 29 additions & 0 deletions src/client/java/net/The2019/NewBase/utils/PermsionLevel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.The2019.NewBase.utils;

import net.minecraft.client.MinecraftClient;

import java.util.ArrayList;

public class PermsionLevel {
private static final ArrayList<String> allowedPlayers = new ArrayList<>();
private static final MinecraftClient mc = MinecraftClient.getInstance();
public static Boolean isPlayerAllowed = false;

public static void init(){
addPlayers("The2019");
addPlayers("TheChrisgamer18");
}

public static void isPlayerAllowed(){
if (mc.player != null) {
String playername = mc.player.getName().toString();
if(allowedPlayers.contains(playername)){
isPlayerAllowed = true;
}
}
}

private static void addPlayers(String players){
allowedPlayers.add(players);
}
}

0 comments on commit b100857

Please sign in to comment.