Skip to content

Commit

Permalink
Added InteractionUtils.java, GenericScreen.java, TridentHelper.java n…
Browse files Browse the repository at this point in the history
…ad changed some stuff in Placer
  • Loading branch information
The2019 committed Nov 28, 2023
1 parent 099e072 commit 0419097
Show file tree
Hide file tree
Showing 14 changed files with 174 additions and 33 deletions.
18 changes: 13 additions & 5 deletions src/client/java/net/The2019/NewBase/NewBaseClient.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package net.The2019.NewBase;

import net.The2019.NewBase.config.ModuleConfig;
import net.The2019.NewBase.features.ChunkRender;
import net.The2019.NewBase.features.generic.ChunkRender;
import net.The2019.NewBase.features.generic.Placer;
import net.The2019.NewBase.features.generic.TridentHelper;
import net.The2019.NewBase.features.render.BeeHiveHelper;
import net.The2019.NewBase.render.HudRender;
import net.The2019.NewBase.utils.InitKeyBindings;
Expand All @@ -14,14 +16,20 @@ public class NewBaseClient implements ClientModInitializer {

@Override
public void onInitializeClient() {
//Utils
PermissionLevel.initAllowedPlayers();
ModuleConfig.init();
InitKeyBindings.initKeys();

//Hud
HudRender.registerHudRendering();

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

InitKeyBindings.initKeys();

ModuleConfig.init();
//generic
ChunkRender.renderChunkOutline();
Placer.place();
TridentHelper.tridentHelper();
}
}
2 changes: 2 additions & 0 deletions src/client/java/net/The2019/NewBase/config/ModuleConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ private static void writeDefaultValues() {
json.addProperty(fpsDisplay, true);
json.addProperty(beehiveRender, false);
json.addProperty(fullBrightRender, true);
json.addProperty(placer, false);
json.addProperty(tridentHelper, true);

try (FileWriter writer = new FileWriter(configFile)) {
gson.toJson(json, writer);
Expand Down
6 changes: 6 additions & 0 deletions src/client/java/net/The2019/NewBase/config/ModuleStates.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package net.The2019.NewBase.config;

public class ModuleStates {
//Hud
public static String coordinateDisplay = "coordinatedisplay";
public static String biomeDisplay = "biomedisplay";
public static String fpsDisplay = "fpsdisplay";

//Render
public static String beehiveRender = "beehiverender";
public static String fullBrightRender = "fullbrightrender";

//Generic
public static String placer = "placer";
public static String tridentHelper = "trident";
}
19 changes: 0 additions & 19 deletions src/client/java/net/The2019/NewBase/features/Placer.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.The2019.NewBase.features;
package net.The2019.NewBase.features.generic;

import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
import net.minecraft.client.MinecraftClient;
Expand Down
27 changes: 27 additions & 0 deletions src/client/java/net/The2019/NewBase/features/generic/Placer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package net.The2019.NewBase.features.generic;

import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;

import static net.The2019.NewBase.config.ModuleConfig.readModule;
import static net.The2019.NewBase.config.ModuleStates.placer;
import static net.The2019.NewBase.utils.InteractionUtils.placeBlock;

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

public static void place() {
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if(readModule(placer)){
if (mc.player != null && mc.interactionManager != null) {
BlockPos pos = mc.player.getBlockPos().add(0, -1, 0);

placeBlock(Hand.OFF_HAND, pos, Direction.UP, false);
}
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.The2019.NewBase.features.generic;

import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.item.Items;

import static net.The2019.NewBase.config.ModuleConfig.readModule;
import static net.The2019.NewBase.config.ModuleStates.tridentHelper;

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

public static void tridentHelper() {
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (readModule(tridentHelper)){
if (mc.player != null) {
if (mc.player.getActiveItem().getItem() == Items.TRIDENT){
if( mc.player.isTouchingWater()) {
mc.player.setSprinting(true);
}
}
}
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class BeeHiveHelper {

public static void register() {
WorldRenderEvents.END.register(context -> {
if(readModule(beehiveRender)){
if (mc.player != null ){
if(readModule(beehiveRender)) {
if (mc.player != null) {
for (BlockEntity blockEntity : getBlockEntities().collect(Collectors.toCollection(ArrayList::new))) {
if (blockEntity instanceof BeehiveBlockEntity) {
BlockPos blockEntityPos = blockEntity.getPos();
Expand All @@ -32,6 +32,7 @@ public static void register() {
}
}
}

});
}
}
4 changes: 4 additions & 0 deletions src/client/java/net/The2019/NewBase/screens/ConfigScreen.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.The2019.NewBase.screens;

import net.The2019.NewBase.screens.configScreen.GenericScreen;
import net.The2019.NewBase.screens.configScreen.HudScreen;
import net.The2019.NewBase.screens.configScreen.RenderScreen;
import net.minecraft.client.MinecraftClient;
Expand Down Expand Up @@ -36,6 +37,9 @@ protected void init() {
this.addDrawable(new TextWidget(x, y+30, 100, 20, Text.translatable("newbase.configscreen.render"), mc.textRenderer).alignLeft());
this.addDrawableChild(new ButtonWidget.Builder(Text.translatable("newbase.configscreen.renderbutton"), button -> {mc.setScreen(new RenderScreen(mc.currentScreen, mc.options));}).tooltip(Tooltip.of(Text.translatable("newbase.configscreen.rendertooltip"))).dimensions(this.width - 220, y+30, 200, 20).build());

//Generic
this.addDrawable(new TextWidget(x, y+60, 100, 20, Text.translatable("newbase.configscreen.generic"), mc.textRenderer).alignLeft());
this.addDrawableChild(new ButtonWidget.Builder(Text.translatable("newbase.configscreen.genericbutton"), button -> {mc.setScreen(new GenericScreen(mc.currentScreen, mc.options));}).tooltip(Tooltip.of(Text.translatable("newbase.configscreen.rendertooltip"))).dimensions(this.width - 220, y+60, 200, 20).build());

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package net.The2019.NewBase.screens.configScreen;

import net.The2019.NewBase.screens.ConfigScreen;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.tooltip.Tooltip;
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 static net.The2019.NewBase.config.ModuleConfig.readModule;
import static net.The2019.NewBase.config.ModuleConfig.saveModuleState;
import static net.The2019.NewBase.config.ModuleStates.*;

public class GenericScreen extends Screen {
private final Screen parent;
private final GameOptions settings;
private static int x = 20;
private static int y = 50;
private static final MinecraftClient mc = MinecraftClient.getInstance();

public GenericScreen(Screen parent, GameOptions settings) {
super(Text.translatable("newbase.genericscreen.name"));
this.parent = parent;
this.settings = settings;
}

@Override
protected void init() {

this.addDrawableChild(new ButtonWidget.Builder(Text.translatable("newbase.renderscreen.back"), button -> {mc.setScreen(new ConfigScreen(mc.currentScreen, mc.options));}).dimensions(17, 20, 100,20).build());

//Placer
this.addDrawable(new TextWidget(x, y, 500, 20, Text.translatable("newbase.genericscreen.placer"), mc.textRenderer).alignLeft());
this.addDrawableChild(new ButtonWidget.Builder(toggleModule(placer), button -> {
saveModuleState(placer, !readModule(placer));
mc.setScreen(new GenericScreen(mc.currentScreen, mc.options));
}).tooltip(Tooltip.of(Text.translatable("newbase.hudscreen.tooltip"))).dimensions(this.width - 220, y, 200, 20).build());

//Trident Helper
this.addDrawable(new TextWidget(x, y+30, 500, 20, Text.translatable("newbase.genericscreen.tridenthelper"), mc.textRenderer).alignLeft());
this.addDrawableChild(new ButtonWidget.Builder(toggleModule(tridentHelper), button -> {
saveModuleState(tridentHelper, !readModule(tridentHelper));
mc.setScreen(new GenericScreen(mc.currentScreen, mc.options));
}).tooltip(Tooltip.of(Text.translatable("newbase.hudscreen.tooltip"))).dimensions(this.width - 220, y+30, 200, 20).build());
}


private static Text toggleModule(String module){
if(readModule(module)){
return Text.translatable("newbase.renderscreen.enabled");
}else {
return Text.translatable("newbase.renderscreen.disabled");
}
}
}
11 changes: 5 additions & 6 deletions src/client/java/net/The2019/NewBase/utils/ChunkStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,31 @@ public class ChunkStream {

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

public static Stream<BlockEntity> getBlockEntities(){
public static Stream<BlockEntity> getBlockEntities() {
return getLoadedChunks().flatMap(chunk -> chunk.getBlockEntities().values().stream());
}

public static Stream<WorldChunk> getLoadedChunks(){
public static Stream<WorldChunk> getLoadedChunks() {
int radius = Math.max(2, mc.options.getClampedViewDistance()) + 3;
int diameter = radius * 2 + 1;

ChunkPos centerChunk = mc.player.getChunkPos();
ChunkPos min = new ChunkPos(centerChunk.x - radius, centerChunk.z - radius);
ChunkPos max = new ChunkPos(centerChunk.x + radius, centerChunk.z + radius);

Stream<WorldChunk> stream = Stream.<ChunkPos> iterate(min, pos -> {
Stream<WorldChunk> stream = Stream.<ChunkPos>iterate(min, pos -> {
int x = pos.x;
int z = pos.z;
x++;

if(x > max.x)
{
if (x > max.x) {
x = min.x;
z++;
}

return new ChunkPos(x, z);

}).limit(diameter*diameter).filter(c -> mc.world.isChunkLoaded(c.x, c.z)).map(c -> mc.world.getChunk(c.x, c.z)).filter(Objects::nonNull);
}).limit(diameter * diameter).filter(c -> mc.world.isChunkLoaded(c.x, c.z)).map(c -> mc.world.getChunk(c.x, c.z)).filter(Objects::nonNull);

return stream;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import org.lwjgl.glfw.GLFW;

import static net.The2019.NewBase.config.ModuleConfig.readModule;
import static net.The2019.NewBase.config.ModuleConfig.saveModuleState;
import static net.The2019.NewBase.config.ModuleStates.placer;

public class InitKeyBindings {

private static final MinecraftClient mc = MinecraftClient.getInstance();
Expand All @@ -29,6 +36,8 @@ public static void initKeys(){
mc.setScreen(new ChatCoordinatesScreen(mc.currentScreen, mc.options));
}
if(toggleFps.wasPressed()){
MinecraftClient.getInstance().options.forwardKey.setPressed(!readModule(placer));
saveModuleState(placer, !readModule(placer));
}
});
}
Expand Down
15 changes: 15 additions & 0 deletions src/client/java/net/The2019/NewBase/utils/InteractionUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package net.The2019.NewBase.utils;

import net.minecraft.client.MinecraftClient;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;

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

public static void placeBlock(Hand hand, BlockPos blockPos, Direction direction, boolean indsideBlock){
mc.interactionManager.interactBlock(mc.player, hand, new BlockHitResult(mc.player.getPos(), direction, blockPos, indsideBlock));
}
}
6 changes: 6 additions & 0 deletions src/client/resources/assets/newbase/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"newbase.configscreen.hudtooltip": "Opens the config menu for the Hud.",
"newbase.configscreen.render": "Render Configs",
"newbase.configscreen.renderbutton": "Render Configs",
"newbase.configscreen.generic": "Generic Configs",
"newbase.configscreen.genericbutton": "Generic Configs",
"newbase.configscreen.rendertooltip": "Opens the config menu for the Renderings.",
"newbase.configscreen.nametooltip": "Close with ESC.",

Expand All @@ -27,6 +29,10 @@
"newbase.renderscreen.disabled": "§4Disabled",
"newbase.renderscreen.tooltip": "Press to Toggle",

"newbase.genericscreen.name": "Generic Config Screen",
"newbase.genericscreen.placer": "Toggle Placer",
"newbase.genericscreen.tridenthelper": "Toggle Trident Helper",


"newbase.chatcoordinatesscreen.name": "Chat Coordinates Screen",
"newbase.chatcoordinatesscreen.yes": "§aYes",
Expand Down

0 comments on commit 0419097

Please sign in to comment.