mirror of
https://github.com/ayabusa/Modern-Chunk-Detector.git
synced 2025-07-02 02:09:20 +00:00
Init commit
This commit is contained in:
33
src/client/java/modern_chunk_detector/ChunkScanner.java
Normal file
33
src/client/java/modern_chunk_detector/ChunkScanner.java
Normal file
@ -0,0 +1,33 @@
|
||||
package modern_chunk_detector;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.chunk.WorldChunk;
|
||||
|
||||
public class ChunkScanner extends Thread{
|
||||
WorldChunk chunk;
|
||||
public ChunkScanner(WorldChunk c){
|
||||
chunk = c;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
ChunkPos chunk_position = chunk.getPos();
|
||||
int start_x = chunk_position.getStartX();
|
||||
int start_z = chunk_position.getStartZ();
|
||||
|
||||
for(int x = 0; x <= 15; x++) {
|
||||
for (int y = 8; y <= 63; y++) {
|
||||
for (int z = 0; z <= 15; z++) {
|
||||
BlockState block_state = chunk.getBlockState(new BlockPos(start_x+x, y, start_z+z));
|
||||
String block_name = block_state.getBlock().getName().toString();
|
||||
if(block_name.contains("block.minecraft.copper_ore") || block_name.contains("block.minecraft.ancient_debris")){
|
||||
System.out.println("[Modern Chunk Detector] Found modern chunk at: "+chunk_position);
|
||||
ModernChunkDetectorClient.chunk_to_render.add(chunk_position);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,194 @@
|
||||
package modern_chunk_detector;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientChunkEvents;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
|
||||
import net.fabricmc.fabric.api.renderer.v1.Renderer;
|
||||
import net.fabricmc.fabric.api.renderer.v1.RendererAccess;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
import net.minecraft.client.render.*;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.math.ColorHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.chunk.WorldChunk;
|
||||
import org.joml.Matrix4f;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class ModernChunkDetectorClient implements ClientModInitializer {
|
||||
|
||||
public static CopyOnWriteArrayList<ChunkPos> chunk_to_render = new CopyOnWriteArrayList<ChunkPos>();
|
||||
private static KeyBinding toogle_key;
|
||||
private static boolean is_mod_enabled = true;
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
|
||||
System.out.println("[Modern Chunk Detector] Mod Initialized!");
|
||||
|
||||
toogle_key = KeyBindingHelper.registerKeyBinding(new KeyBinding(
|
||||
"toogle_key.modern_chunk_detector", // The translation key of the keybinding's name
|
||||
InputUtil.Type.KEYSYM, // The type of the keybinding, KEYSYM for keyboard, MOUSE for mouse.
|
||||
GLFW.GLFW_KEY_O, // The keycode of the key
|
||||
"modern_chunk_detector.ayabusa" // The translation key of the keybinding's category.
|
||||
));
|
||||
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
while (toogle_key.wasPressed()) {
|
||||
if(is_mod_enabled){
|
||||
client.player.sendMessage(Text.literal("§b[§dModern chunk detector§b] §fChunk detection is §cOFF"), false);
|
||||
is_mod_enabled=false;
|
||||
}else {
|
||||
client.player.sendMessage(Text.literal("§b[§dModern chunk detector§b] §fChunk detection is §aON"), false);
|
||||
is_mod_enabled=true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ClientChunkEvents.CHUNK_LOAD.register((ClientWorld world, WorldChunk chunk)->{
|
||||
/*ChunkPos chunk_position = chunk.getPos();
|
||||
int start_x = chunk_position.getStartX();
|
||||
int start_z = chunk_position.getStartZ();*/
|
||||
/*BlockState block_state = chunk.getBlockState(new BlockPos(start_x, 99, start_z));
|
||||
String block_name = block_state.getBlock().getName().toString();
|
||||
if(block_name.contains("block.minecraft.copper_ore")){
|
||||
System.out.println("[Modern Chunk Detector] Copper ore detected");
|
||||
}*/
|
||||
/*for(int x = 0; x <= 15; x++) {
|
||||
for (int y = 8; y <= 63; y++) {
|
||||
for (int z = 0; z <= 15; z++) {
|
||||
BlockState block_state = chunk.getBlockState(new BlockPos(start_x+x, y, start_z+z));
|
||||
String block_name = block_state.getBlock().getName().toString();
|
||||
if(block_name.contains("block.minecraft.copper_ore") || block_name.contains("block.minecraft.ancient_debris")){
|
||||
System.out.println("[Modern Chunk Detector] Found modern chunk at: "+chunk_position);
|
||||
chunk_to_render.add(chunk_position);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
ChunkScanner scanner = new ChunkScanner(chunk);
|
||||
scanner.start();
|
||||
});
|
||||
|
||||
ClientChunkEvents.CHUNK_UNLOAD.register((ClientWorld world, WorldChunk chunk)->{
|
||||
chunk_to_render.remove(chunk.getPos());
|
||||
});
|
||||
|
||||
WorldRenderEvents.BEFORE_DEBUG_RENDER.register((WorldRenderContext context)->{
|
||||
if(is_mod_enabled) {
|
||||
MatrixStack matrices = context.matrixStack();
|
||||
VertexConsumerProvider vertexConsumers = context.consumers();
|
||||
double cameraX = context.camera().getPos().x;
|
||||
double cameraY = context.camera().getPos().y;
|
||||
double cameraZ = context.camera().getPos().z;
|
||||
|
||||
for (Object i : chunk_to_render) {
|
||||
render(matrices, vertexConsumers, cameraX, cameraY, cameraZ, (ChunkPos) i);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private final MinecraftClient client = MinecraftClient.getInstance();
|
||||
private static final int DARK_CYAN = ColorHelper.Argb.getArgb(255, 0, 155, 155);
|
||||
private static final int YELLOW = ColorHelper.Argb.getArgb(255, 255, 255, 0);
|
||||
|
||||
public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, double cameraX, double cameraY, double cameraZ, ChunkPos chunkPos) {
|
||||
Entity entity = this.client.gameRenderer.getCamera().getFocusedEntity();
|
||||
float f = (float)((double)this.client.world.getBottomY() - cameraY);
|
||||
float g = (float)((double)this.client.world.getTopY() - cameraY);
|
||||
|
||||
float h = (float)((double)chunkPos.getStartX() - cameraX);
|
||||
float i = (float)((double)chunkPos.getStartZ() - cameraZ);
|
||||
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(RenderLayer.getDebugLineStrip(1.0));
|
||||
Matrix4f matrix4f = matrices.peek().getPositionMatrix();
|
||||
|
||||
int j;
|
||||
int k;
|
||||
for(j = -16; j <= 32; j += 16) {
|
||||
for(k = -16; k <= 32; k += 16) {
|
||||
/*vertexConsumer.vertex(matrix4f, h + (float)j, f, i + (float)k).color(1.0F, 0.0F, 0.0F, 0.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, h + (float)j, f, i + (float)k).color(1.0F, 0.0F, 0.0F, 0.5F).next();
|
||||
vertexConsumer.vertex(matrix4f, h + (float)j, g, i + (float)k).color(1.0F, 0.0F, 0.0F, 0.5F).next();
|
||||
vertexConsumer.vertex(matrix4f, h + (float)j, g, i + (float)k).color(1.0F, 0.0F, 0.0F, 0.0F).next();*/
|
||||
}
|
||||
}
|
||||
|
||||
for(j = 2; j < 16; j += 2) {
|
||||
k = j % 4 == 0 ? DARK_CYAN : YELLOW;
|
||||
/*vertexConsumer.vertex(matrix4f, h + (float)j, f, i).color(1.0F, 1.0F, 0.0F, 0.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, h + (float)j, f, i).color(k).next();
|
||||
vertexConsumer.vertex(matrix4f, h + (float)j, g, i).color(k).next();
|
||||
vertexConsumer.vertex(matrix4f, h + (float)j, g, i).color(1.0F, 1.0F, 0.0F, 0.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, h + (float)j, f, i + 16.0F).color(1.0F, 1.0F, 0.0F, 0.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, h + (float)j, f, i + 16.0F).color(k).next();
|
||||
vertexConsumer.vertex(matrix4f, h + (float)j, g, i + 16.0F).color(k).next();
|
||||
vertexConsumer.vertex(matrix4f, h + (float)j, g, i + 16.0F).color(1.0F, 1.0F, 0.0F, 0.0F).next();*/
|
||||
}
|
||||
|
||||
for(j = 2; j < 16; j += 2) {
|
||||
k = j % 4 == 0 ? DARK_CYAN : YELLOW;
|
||||
/*vertexConsumer.vertex(matrix4f, h, f, i + (float)j).color(1.0F, 1.0F, 0.0F, 0.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, h, f, i + (float)j).color(k).next();
|
||||
vertexConsumer.vertex(matrix4f, h, g, i + (float)j).color(k).next();
|
||||
vertexConsumer.vertex(matrix4f, h, g, i + (float)j).color(1.0F, 1.0F, 0.0F, 0.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, h + 16.0F, f, i + (float)j).color(1.0F, 1.0F, 0.0F, 0.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, h + 16.0F, f, i + (float)j).color(k).next();
|
||||
vertexConsumer.vertex(matrix4f, h + 16.0F, g, i + (float)j).color(k).next();
|
||||
vertexConsumer.vertex(matrix4f, h + 16.0F, g, i + (float)j).color(1.0F, 1.0F, 0.0F, 0.0F).next();*/
|
||||
}
|
||||
|
||||
float l;
|
||||
for(j = this.client.world.getBottomY(); j <= this.client.world.getTopY(); j += 2) {
|
||||
l = (float)((double)j - cameraY);
|
||||
int m = j % 8 == 0 ? DARK_CYAN : YELLOW;/*
|
||||
vertexConsumer.vertex(matrix4f, h, l, i).color(1.0F, 1.0F, 0.0F, 0.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, h, l, i).color(m).next();
|
||||
vertexConsumer.vertex(matrix4f, h, l, i + 16.0F).color(m).next();
|
||||
vertexConsumer.vertex(matrix4f, h + 16.0F, l, i + 16.0F).color(m).next();
|
||||
vertexConsumer.vertex(matrix4f, h + 16.0F, l, i).color(m).next();
|
||||
vertexConsumer.vertex(matrix4f, h, l, i).color(m).next();
|
||||
vertexConsumer.vertex(matrix4f, h, l, i).color(1.0F, 1.0F, 0.0F, 0.0F).next();*/
|
||||
}
|
||||
|
||||
vertexConsumer = vertexConsumers.getBuffer(RenderLayer.getDebugLineStrip(2.0));
|
||||
|
||||
for(j = 0; j <= 16; j += 16) {
|
||||
for(k = 0; k <= 16; k += 16) {
|
||||
vertexConsumer.vertex(matrix4f, h + (float)j, f, i + (float)k).color(1.0F, 0F, 1.0F, 0.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, h + (float)j, f, i + (float)k).color(1.0F, 0F, 1.0F, 1.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, h + (float)j, g, i + (float)k).color(1.0F, 0F, 1.0F, 1.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, h + (float)j, g, i + (float)k).color(1.0F, 0F, 1.0F, 0.0F).next();
|
||||
}
|
||||
}
|
||||
|
||||
for(j = this.client.world.getBottomY(); j <= this.client.world.getTopY(); j += 2) {
|
||||
l = (float)((double)j - cameraY);
|
||||
vertexConsumer.vertex(matrix4f, h, l, i).color(1.0F, 0F, 1.0F, 0.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, h, l, i).color(1.0F, 0F, 1.0F, 1.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, h, l, i + 16.0F).color(1.0F, 0F, 1.0F, 1.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, h + 16.0F, l, i + 16.0F).color(1.0F, 0F, 1.0F, 1.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, h + 16.0F, l, i).color(1.0F, 0F, 1.0F, 1.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, h, l, i).color(1.0F, 0F, 1.0F, 1.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, h, l, i).color(1.0F, 0F, 1.0F, 0.0F).next();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package modern_chunk_detector.mixin.client;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(MinecraftClient.class)
|
||||
public class ExampleClientMixin {
|
||||
@Inject(at = @At("HEAD"), method = "run")
|
||||
private void init(CallbackInfo info) {
|
||||
// This code is injected into the start of MinecraftClient.run()V
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "modern_chunk_detector.mixin.client",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"client": [
|
||||
"ExampleClientMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
22
src/main/java/modern_chunk_detector/ModernChunkDetector.java
Normal file
22
src/main/java/modern_chunk_detector/ModernChunkDetector.java
Normal file
@ -0,0 +1,22 @@
|
||||
package modern_chunk_detector;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ModernChunkDetector implements ModInitializer {
|
||||
// This logger is used to write text to the console and the log file.
|
||||
// It is considered best practice to use your mod id as the logger's name.
|
||||
// That way, it's clear which mod wrote info, warnings, and errors.
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("modern_chunk_detector");
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
||||
// However, some things (like resources) may still be uninitialized.
|
||||
// Proceed with mild caution.
|
||||
|
||||
LOGGER.info("Hello Fabric world!");
|
||||
}
|
||||
}
|
15
src/main/java/modern_chunk_detector/mixin/ExampleMixin.java
Normal file
15
src/main/java/modern_chunk_detector/mixin/ExampleMixin.java
Normal file
@ -0,0 +1,15 @@
|
||||
package modern_chunk_detector.mixin;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(MinecraftServer.class)
|
||||
public class ExampleMixin {
|
||||
@Inject(at = @At("HEAD"), method = "loadWorld")
|
||||
private void init(CallbackInfo info) {
|
||||
// This code is injected into the start of MinecraftServer.loadWorld()V
|
||||
}
|
||||
}
|
BIN
src/main/resources/assets/modern_chunk_detector/Steve.png
Normal file
BIN
src/main/resources/assets/modern_chunk_detector/Steve.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 294 B |
BIN
src/main/resources/assets/modern_chunk_detector/icon.png
Normal file
BIN
src/main/resources/assets/modern_chunk_detector/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.9 KiB |
41
src/main/resources/fabric.mod.json
Normal file
41
src/main/resources/fabric.mod.json
Normal file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "modern_chunk_detector",
|
||||
"version": "${version}",
|
||||
"name": "Modern Chunk Detector",
|
||||
"description": "This mod shows you if a chunk is new or old, can be useful on server like 2b2t or 9b9t",
|
||||
"authors": [
|
||||
"Ayabusa!"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://ayabusa.dev/",
|
||||
"sources": "https://github.com/ayabusa"
|
||||
},
|
||||
"license": "CC0-1.0",
|
||||
"icon": "assets/modern_chunk_detector/icon.png",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"modern_chunk_detector.ModernChunkDetector"
|
||||
],
|
||||
"client": [
|
||||
"modern_chunk_detector.ModernChunkDetectorClient"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"modern_chunk_detector.mixins.json",
|
||||
{
|
||||
"config": "modern_chunk_detector.client.mixins.json",
|
||||
"environment": "client"
|
||||
}
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.15.11",
|
||||
"minecraft": "~1.20.6",
|
||||
"java": ">=21",
|
||||
"fabric-api": "*"
|
||||
},
|
||||
"suggests": {
|
||||
"another-mod": "*"
|
||||
}
|
||||
}
|
11
src/main/resources/modern_chunk_detector.mixins.json
Normal file
11
src/main/resources/modern_chunk_detector.mixins.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "modern_chunk_detector.mixin",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"mixins": [
|
||||
"ExampleMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user