From d5105831b2348645bc105e148855c969bee6ae64 Mon Sep 17 00:00:00 2001 From: andi-makes Date: Wed, 12 Jun 2024 21:46:36 +0200 Subject: [PATCH] 1.21.0 --- .../dev/schmarrn/lighty/api/LightyMode.java | 7 +- .../dev/schmarrn/lighty/config/Config.java | 8 +- .../lighty/config/ResourceLocationConfig.java | 2 +- .../lighty/config/compat/Lighty2Config.java | 2 +- .../schmarrn/lighty/event/BufferHolder.java | 6 +- .../dev/schmarrn/lighty/event/Compute.java | 8 +- .../schmarrn/lighty/mode/BoringCrossMode.java | 16 ++-- .../dev/schmarrn/lighty/mode/CarpetMode.java | 90 +++++++++---------- .../schmarrn/lighty/mode/FarmlandMode.java | 48 +++++----- .../dev/schmarrn/lighty/mode/NumberMode.java | 53 +++++------ .../schmarrn/lighty/ui/SettingsScreen.java | 46 +++------- fabric/build.gradle | 3 +- fabric/src/main/resources/fabric.mod.json | 2 +- gradle.properties | 11 +-- 14 files changed, 137 insertions(+), 165 deletions(-) diff --git a/common/src/main/java/dev/schmarrn/lighty/api/LightyMode.java b/common/src/main/java/dev/schmarrn/lighty/api/LightyMode.java index 03aabc0..b84a7de 100644 --- a/common/src/main/java/dev/schmarrn/lighty/api/LightyMode.java +++ b/common/src/main/java/dev/schmarrn/lighty/api/LightyMode.java @@ -15,6 +15,9 @@ package dev.schmarrn.lighty.api; import com.mojang.blaze3d.vertex.BufferBuilder; +import com.mojang.blaze3d.vertex.DefaultVertexFormat; +import com.mojang.blaze3d.vertex.Tesselator; +import com.mojang.blaze3d.vertex.VertexFormat; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.core.BlockPos; import net.minecraft.resources.ResourceLocation; @@ -30,7 +33,9 @@ public abstract class LightyMode { * - a bunch of `compute()` calls
* - exactly one call to `afterCompute()` */ - public void beforeCompute(BufferBuilder builder) {} + public BufferBuilder beforeCompute(Tesselator builder) { + return builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); + } public void beforeRendering() {} public void afterRendering() {} diff --git a/common/src/main/java/dev/schmarrn/lighty/config/Config.java b/common/src/main/java/dev/schmarrn/lighty/config/Config.java index bc63617..4774443 100644 --- a/common/src/main/java/dev/schmarrn/lighty/config/Config.java +++ b/common/src/main/java/dev/schmarrn/lighty/config/Config.java @@ -32,7 +32,7 @@ public class Config { private static boolean initStage = true; // all the different config values - public static final ResourceLocationConfig LAST_USED_MODE = new ResourceLocationConfig("lighty.last_used_mode", new ResourceLocation("lighty:carpet_mode")); + public static final ResourceLocationConfig LAST_USED_MODE = new ResourceLocationConfig("lighty.last_used_mode", ResourceLocation.parse("lighty:carpet_mode")); public static final IntegerConfig SKY_THRESHOLD = new IntegerConfig("lighty.sky_threshold", 0, 0, 15); public static final IntegerConfig BLOCK_THRESHOLD = new IntegerConfig("lighty.block_threshold", 0, 0, 15); @@ -48,11 +48,11 @@ public class Config { public static final ColorConfig OVERLAY_ORANGE = new ColorConfig("lighty.overlay_orange", 0xFF6600); public static final ColorConfig OVERLAY_RED = new ColorConfig("lighty.overlay_red", 0xFF0000); - public static final ResourceLocationConfig AUTO_ON_ITEM = new ResourceLocationConfig("lighty.auto_on.item", new ResourceLocation("minecraft:torch")); + public static final ResourceLocationConfig AUTO_ON_ITEM = new ResourceLocationConfig("lighty.auto_on.item", ResourceLocation.parse("minecraft:torch")); public static final BooleanConfig SHOULD_AUTO_ON = new BooleanConfig("lighty.auto_on", false); - public static final ResourceLocationConfig CARPET_TEXTURE = new ResourceLocationConfig("lighty.mode.carpet.texture", new ResourceLocation(Lighty.MOD_ID, "textures/block/transparent.png")); - public static final ResourceLocationConfig CROSS_TEXTURE = new ResourceLocationConfig("lighty.mode.cross.texture", new ResourceLocation(Lighty.MOD_ID, "textures/block/cross.png")); + public static final ResourceLocationConfig CARPET_TEXTURE = new ResourceLocationConfig("lighty.mode.carpet.texture", ResourceLocation.fromNamespaceAndPath(Lighty.MOD_ID, "textures/block/transparent.png")); + public static final ResourceLocationConfig CROSS_TEXTURE = new ResourceLocationConfig("lighty.mode.cross.texture", ResourceLocation.fromNamespaceAndPath(Lighty.MOD_ID, "textures/block/cross.png")); private static void loadFromFile(String key, ConfigSerDe type) { // If the file contains the config value, get the configured value... diff --git a/common/src/main/java/dev/schmarrn/lighty/config/ResourceLocationConfig.java b/common/src/main/java/dev/schmarrn/lighty/config/ResourceLocationConfig.java index 4d0bfcb..ab56859 100644 --- a/common/src/main/java/dev/schmarrn/lighty/config/ResourceLocationConfig.java +++ b/common/src/main/java/dev/schmarrn/lighty/config/ResourceLocationConfig.java @@ -20,6 +20,6 @@ String serialize() { @Override void deserialize(String value) { - setValue(new ResourceLocation(value)); + setValue(ResourceLocation.parse(value)); } } diff --git a/common/src/main/java/dev/schmarrn/lighty/config/compat/Lighty2Config.java b/common/src/main/java/dev/schmarrn/lighty/config/compat/Lighty2Config.java index 53645bd..bc95ebb 100644 --- a/common/src/main/java/dev/schmarrn/lighty/config/compat/Lighty2Config.java +++ b/common/src/main/java/dev/schmarrn/lighty/config/compat/Lighty2Config.java @@ -49,7 +49,7 @@ public static void migrate() { properties.putIfAbsent(OVERLAY_RED, Integer.toHexString(0xFF0000)); // Set the new stuff - Config.LAST_USED_MODE.setValue(new ResourceLocation(properties.getProperty(LAST_USED_MODE))); + Config.LAST_USED_MODE.setValue(ResourceLocation.parse(properties.getProperty(LAST_USED_MODE))); Config.SKY_THRESHOLD.setValue(Integer.valueOf(properties.getProperty(SKY_THRESHOLD))); Config.BLOCK_THRESHOLD.setValue(Integer.valueOf(properties.getProperty(BLOCK_THRESHOLD))); Config.FARM_GROWTH_THRESHOLD.setValue(Integer.valueOf(properties.getProperty(FARM_GROWTH_THRESHOLD))); diff --git a/common/src/main/java/dev/schmarrn/lighty/event/BufferHolder.java b/common/src/main/java/dev/schmarrn/lighty/event/BufferHolder.java index e362fe3..c1ebc32 100644 --- a/common/src/main/java/dev/schmarrn/lighty/event/BufferHolder.java +++ b/common/src/main/java/dev/schmarrn/lighty/event/BufferHolder.java @@ -15,6 +15,7 @@ package dev.schmarrn.lighty.event; import com.mojang.blaze3d.vertex.BufferBuilder; +import com.mojang.blaze3d.vertex.MeshData; import com.mojang.blaze3d.vertex.VertexBuffer; import net.minecraft.client.renderer.ShaderInstance; import org.jetbrains.annotations.Nullable; @@ -42,15 +43,14 @@ void close() { } } - void upload(BufferBuilder.RenderedBuffer buffer) { + void upload(MeshData buffer) { if (vertexBuffer != null) { vertexBuffer.close(); } - if (buffer.isEmpty()) { + if (buffer == null) { // Don't upload isEmpty = true; vertexBuffer = null; - buffer.release(); } else { isEmpty = false; vertexBuffer = new VertexBuffer(VertexBuffer.Usage.DYNAMIC); diff --git a/common/src/main/java/dev/schmarrn/lighty/event/Compute.java b/common/src/main/java/dev/schmarrn/lighty/event/Compute.java index 9c781ab..d8a2cf9 100644 --- a/common/src/main/java/dev/schmarrn/lighty/event/Compute.java +++ b/common/src/main/java/dev/schmarrn/lighty/event/Compute.java @@ -86,8 +86,8 @@ public static void updateSubChunk(SectionPos pos) { toBeUpdated.add(pos); } - private static BufferHolder buildChunk(LightyMode mode, SectionPos chunkPos, BufferBuilder builder, ClientLevel world) { - mode.beforeCompute(builder); + private static BufferHolder buildChunk(LightyMode mode, SectionPos chunkPos, Tesselator tesselator, ClientLevel world) { + BufferBuilder builder = mode.beforeCompute(tesselator); for (int x = 0; x < 16; ++x) { for (int y = 0; y < 16; ++y) { for (int z = 0; z < 16; ++z) { @@ -102,7 +102,7 @@ private static BufferHolder buildChunk(LightyMode mode, SectionPos chunkPos, Buf if (buffer == null) { buffer = new BufferHolder(); } - buffer.upload(builder.end()); + buffer.upload(builder.build()); mode.afterCompute(); return buffer; @@ -155,7 +155,7 @@ public static void computeCache(Minecraft client) { if (vertexBuffer != null) { vertexBuffer.close(); } - return buildChunk(mode, pos, Tesselator.getInstance().getBuilder(), world); + return buildChunk(mode, pos, Tesselator.getInstance(), world); }); } } diff --git a/common/src/main/java/dev/schmarrn/lighty/mode/BoringCrossMode.java b/common/src/main/java/dev/schmarrn/lighty/mode/BoringCrossMode.java index 0c40939..fe208bf 100644 --- a/common/src/main/java/dev/schmarrn/lighty/mode/BoringCrossMode.java +++ b/common/src/main/java/dev/schmarrn/lighty/mode/BoringCrossMode.java @@ -17,6 +17,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.DefaultVertexFormat; +import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.blaze3d.vertex.VertexFormat; import dev.schmarrn.lighty.Lighty; import dev.schmarrn.lighty.api.LightyColors; @@ -33,11 +34,6 @@ import net.minecraft.world.level.block.state.BlockState; public class BoringCrossMode extends LightyMode { - @Override - public void beforeCompute(BufferBuilder builder) { - builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); - } - @Override public void compute(ClientLevel world, BlockPos pos, BufferBuilder builder) { BlockState blockState = world.getBlockState(pos); @@ -65,10 +61,10 @@ public void compute(ClientLevel world, BlockPos pos, BufferBuilder builder) { int overlayBrightness = Config.OVERLAY_BRIGHTNESS.getValue(); int lightmap = LightTexture.pack(overlayBrightness, overlayBrightness); - builder.vertex(x1, y, z1).color(color).uv(0, 0).uv2(lightmap).normal(0f, 1f, 0f).endVertex(); - builder.vertex(x1, y, z2).color(color).uv(0, 1).uv2(lightmap).normal(0f, 1f, 0f).endVertex(); - builder.vertex(x2, y, z2).color(color).uv(1, 1).uv2(lightmap).normal(0f, 1f, 0f).endVertex(); - builder.vertex(x2, y, z1).color(color).uv(1, 0).uv2(lightmap).normal(0f, 1f, 0f).endVertex(); + builder.addVertex(x1, y, z1).setColor(color).setUv(0, 0).setLight(lightmap).setNormal(0f, 1f, 0f); + builder.addVertex(x1, y, z2).setColor(color).setUv(0, 1).setLight(lightmap).setNormal(0f, 1f, 0f); + builder.addVertex(x2, y, z2).setColor(color).setUv(1, 1).setLight(lightmap).setNormal(0f, 1f, 0f); + builder.addVertex(x2, y, z1).setColor(color).setUv(1, 0).setLight(lightmap).setNormal(0f, 1f, 0f); } } @@ -86,7 +82,7 @@ public void afterRendering() { @Override public ResourceLocation getResourceLocation() { - return new ResourceLocation(Lighty.MOD_ID, "boring_cross_mode"); + return ResourceLocation.fromNamespaceAndPath(Lighty.MOD_ID, "boring_cross_mode"); } public static void init() { diff --git a/common/src/main/java/dev/schmarrn/lighty/mode/CarpetMode.java b/common/src/main/java/dev/schmarrn/lighty/mode/CarpetMode.java index c767c25..08403ba 100644 --- a/common/src/main/java/dev/schmarrn/lighty/mode/CarpetMode.java +++ b/common/src/main/java/dev/schmarrn/lighty/mode/CarpetMode.java @@ -17,6 +17,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.DefaultVertexFormat; +import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.blaze3d.vertex.VertexFormat; import dev.schmarrn.lighty.Lighty; import dev.schmarrn.lighty.api.LightyColors; @@ -36,11 +37,6 @@ import net.minecraft.world.level.block.state.BlockState; public class CarpetMode extends LightyMode { - @Override - public void beforeCompute(BufferBuilder builder) { - builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); - } - @Override public void compute(ClientLevel world, BlockPos pos, BufferBuilder builder) { BlockPos posUp = pos.above(); @@ -59,53 +55,57 @@ public void compute(ClientLevel world, BlockPos pos, BufferBuilder builder) { int color = LightyColors.getARGB(blockLightLevel, skyLightLevel); - double offset = LightyHelper.getOffset(blockState, pos, world); + float offset = LightyHelper.getOffset(blockState, pos, world); if (offset == -1f) { return; } - double x = pos.getX(); - double y = pos.getY() + 1 + offset; - double z = pos.getZ(); + float x = pos.getX(); + float y = pos.getY() + 1 + offset; + float z = pos.getZ(); int overlayBrightness = Config.OVERLAY_BRIGHTNESS.getValue(); // the first parameter corresponds to the blockLightLevel, the second to the skyLightLevel int lightmap = LightTexture.pack(overlayBrightness, overlayBrightness); //TOP - builder.vertex(x, y + 1 / 16f, z).color(color).uv(0, 0).uv2(lightmap).normal(0f, 1f, 0f).endVertex(); - builder.vertex(x, y + 1 / 16f, z + 1).color(color).uv(0, 1).uv2(lightmap).normal(0f, 1f, 0f).endVertex(); - builder.vertex(x + 1, y + 1 / 16f, z + 1).color(color).uv(1, 1).uv2(lightmap).normal(0f, 1f, 0f).endVertex(); - builder.vertex(x + 1, y + 1 / 16f, z).color(color).uv(1, 0).uv2(lightmap).normal(0f, 1f, 0f).endVertex(); - if (offset > 0.001f) { - //if it renders above it should check if the block above culls the faces - pos = pos.above(); - } - //NORTH - if (Block.shouldRenderFace(Blocks.STONE.defaultBlockState(), world, pos, Direction.SOUTH, pos.relative(Direction.SOUTH))) { - builder.vertex(x, y + 1 / 16f, z + 1).color(color).uv(0, 1f / 16).uv2(lightmap).normal(0f, 0f, -1f).endVertex(); - builder.vertex(x, y, z + 1).color(color).uv(0, 0).uv2(lightmap).normal(0f, 0f, -1f).endVertex(); - builder.vertex(x + 1, y, z + 1).color(color).uv(1, 0).uv2(lightmap).normal(0f, 0f, -1f).endVertex(); - builder.vertex(x + 1, y + 1 / 16f, z + 1).color(color).uv(1, 1f / 16).uv2(lightmap).normal(0f, 0f, -1f).endVertex(); - } - //EAST - if (Block.shouldRenderFace(Blocks.STONE.defaultBlockState(), world, pos, Direction.WEST, pos.relative(Direction.WEST))) { - builder.vertex(x, y + 1/16f, z).color(color).uv(0,1f/16).uv2(lightmap).normal(-1f, 0f, 0f).endVertex(); - builder.vertex(x, y, z).color(color).uv(0, 0).uv2(lightmap).normal(-1f, 0f, 0f).endVertex(); - builder.vertex(x, y, z + 1).color(color).uv(1, 0).uv2(lightmap).normal(-1f, 0f, 0f).endVertex(); - builder.vertex(x, y + 1/16f, z + 1).color(color).uv(1, 1f/16).uv2(lightmap).normal(-1f, 0f, 0f).endVertex(); - } - //SOUTH - if (Block.shouldRenderFace(Blocks.STONE.defaultBlockState(), world, pos, Direction.NORTH, pos.relative(Direction.NORTH))) { - builder.vertex(x+1, y + 1/16f, z).color(color).uv(0,1f/16).uv2(lightmap).normal(0f, 0f, 1f).endVertex(); - builder.vertex(x+1, y, z).color(color).uv(0, 0).uv2(lightmap).normal(0f, 0f, -1f).endVertex(); - builder.vertex(x, y, z).color(color).uv(1, 0).uv2(lightmap).normal(0f, 0f, -1f).endVertex(); - builder.vertex(x, y + 1/16f, z).color(color).uv(1, 1f/16).uv2(lightmap).normal(0f, 0f, -1f).endVertex(); - } - //WEST - if (Block.shouldRenderFace(Blocks.STONE.defaultBlockState(), world, pos, Direction.EAST, pos.relative(Direction.EAST))) { - builder.vertex(x+1, y + 1/16f, z+1).color(color).uv(0,1f/16).uv2(lightmap).normal(1f, 0f, 0f).endVertex(); - builder.vertex(x+1, y, z+1).color(color).uv(0, 0).uv2(lightmap).normal(1f, 0f, 0f).endVertex(); - builder.vertex(x+1, y, z).color(color).uv(1, 0).uv2(lightmap).normal(1f, 0f, 0f).endVertex(); - builder.vertex(x+1, y + 1/16f, z).color(color).uv(1, 1f/16).uv2(lightmap).normal(1f, 0f, 0f).endVertex(); + try { + builder.addVertex(x, y + 1 / 16f, z).setColor(color).setUv(0, 0).setLight(lightmap).setNormal(0f, 1f, 0f); + builder.addVertex(x, y + 1 / 16f, z + 1).setColor(color).setUv(0, 1).setLight(lightmap).setNormal(0f, 1f, 0f); + builder.addVertex(x + 1, y + 1 / 16f, z + 1).setColor(color).setUv(1, 1).setLight(lightmap).setNormal(0f, 1f, 0f); + builder.addVertex(x + 1, y + 1 / 16f, z).setColor(color).setUv(1, 0).setLight(lightmap).setNormal(0f, 1f, 0f); + if (offset > 0.001f) { + //if it renders above it should check if the block above culls the faces + pos = pos.above(); + } + //NORTH + if (Block.shouldRenderFace(Blocks.STONE.defaultBlockState(), world, pos, Direction.SOUTH, pos.relative(Direction.SOUTH))) { + builder.addVertex(x, y + 1 / 16f, z + 1).setColor(color).setUv(0, 1f / 16).setLight(lightmap).setNormal(0f, 0f, -1f); + builder.addVertex(x, y, z + 1).setColor(color).setUv(0, 0).setLight(lightmap).setNormal(0f, 0f, -1f); + builder.addVertex(x + 1, y, z + 1).setColor(color).setUv(1, 0).setLight(lightmap).setNormal(0f, 0f, -1f); + builder.addVertex(x + 1, y + 1 / 16f, z + 1).setColor(color).setUv(1, 1f / 16).setLight(lightmap).setNormal(0f, 0f, -1f); + } + //EAST + if (Block.shouldRenderFace(Blocks.STONE.defaultBlockState(), world, pos, Direction.WEST, pos.relative(Direction.WEST))) { + builder.addVertex(x, y + 1/16f, z).setColor(color).setUv(0,1f/16).setLight(lightmap).setNormal(-1f, 0f, 0f); + builder.addVertex(x, y, z).setColor(color).setUv(0, 0).setLight(lightmap).setNormal(-1f, 0f, 0f); + builder.addVertex(x, y, z + 1).setColor(color).setUv(1, 0).setLight(lightmap).setNormal(-1f, 0f, 0f); + builder.addVertex(x, y + 1/16f, z + 1).setColor(color).setUv(1, 1f/16).setLight(lightmap).setNormal(-1f, 0f, 0f); + } + //SOUTH + if (Block.shouldRenderFace(Blocks.STONE.defaultBlockState(), world, pos, Direction.NORTH, pos.relative(Direction.NORTH))) { + builder.addVertex(x+1, y + 1/16f, z).setColor(color).setUv(0,1f/16).setLight(lightmap).setNormal(0f, 0f, 1f); + builder.addVertex(x+1, y, z).setColor(color).setUv(0, 0).setLight(lightmap).setNormal(0f, 0f, -1f); + builder.addVertex(x, y, z).setColor(color).setUv(1, 0).setLight(lightmap).setNormal(0f, 0f, -1f); + builder.addVertex(x, y + 1/16f, z).setColor(color).setUv(1, 1f/16).setLight(lightmap).setNormal(0f, 0f, -1f); + } + //WEST + if (Block.shouldRenderFace(Blocks.STONE.defaultBlockState(), world, pos, Direction.EAST, pos.relative(Direction.EAST))) { + builder.addVertex(x+1, y + 1/16f, z+1).setColor(color).setUv(0,1f/16).setLight(lightmap).setNormal(1f, 0f, 0f); + builder.addVertex(x+1, y, z+1).setColor(color).setUv(0, 0).setLight(lightmap).setNormal(1f, 0f, 0f); + builder.addVertex(x+1, y, z).setColor(color).setUv(1, 0).setLight(lightmap).setNormal(1f, 0f, 0f); + builder.addVertex(x+1, y + 1/16f, z).setColor(color).setUv(1, 1f/16).setLight(lightmap).setNormal(1f, 0f, 0f); + } + } catch (Exception e) { + throw new RuntimeException(e); } } @@ -124,7 +124,7 @@ public void afterRendering() { @Override public ResourceLocation getResourceLocation() { - return new ResourceLocation(Lighty.MOD_ID, "carpet_mode"); + return ResourceLocation.fromNamespaceAndPath(Lighty.MOD_ID, "carpet_mode"); } public static void init() { diff --git a/common/src/main/java/dev/schmarrn/lighty/mode/FarmlandMode.java b/common/src/main/java/dev/schmarrn/lighty/mode/FarmlandMode.java index 4f6f315..b4f2ede 100644 --- a/common/src/main/java/dev/schmarrn/lighty/mode/FarmlandMode.java +++ b/common/src/main/java/dev/schmarrn/lighty/mode/FarmlandMode.java @@ -33,50 +33,50 @@ public void compute(ClientLevel world, BlockPos pos, BufferBuilder builder) { int skyLightLevel = world.getBrightness(LightLayer.SKY, posUp); int color = LightyColors.getGrowthARGB(blockLightLevel, skyLightLevel); - double x = pos.getX(); - double y = pos.getY() + 15f/16f; - double z = pos.getZ(); + float x = pos.getX(); + float y = pos.getY() + 15f/16f; + float z = pos.getZ(); int overlayBrightness = Config.OVERLAY_BRIGHTNESS.getValue(); // the first parameter corresponds to the blockLightLevel, the second to the skyLightLevel int lightmap = LightTexture.pack(overlayBrightness, overlayBrightness); //TOP - builder.vertex(x, y + 1 / 16f, z).color(color).uv(0, 0).uv2(lightmap).normal(0f, 1f, 0f).endVertex(); - builder.vertex(x, y + 1 / 16f, z + 1).color(color).uv(0, 1).uv2(lightmap).normal(0f, 1f, 0f).endVertex(); - builder.vertex(x + 1, y + 1 / 16f, z + 1).color(color).uv(1, 1).uv2(lightmap).normal(0f, 1f, 0f).endVertex(); - builder.vertex(x + 1, y + 1 / 16f, z).color(color).uv(1, 0).uv2(lightmap).normal(0f, 1f, 0f).endVertex(); + builder.addVertex(x, y + 1 / 16f, z).setColor(color).setUv(0, 0).setLight(lightmap).setNormal(0f, 1f, 0f); + builder.addVertex(x, y + 1 / 16f, z + 1).setColor(color).setUv(0, 1).setLight(lightmap).setNormal(0f, 1f, 0f); + builder.addVertex(x + 1, y + 1 / 16f, z + 1).setColor(color).setUv(1, 1).setLight(lightmap).setNormal(0f, 1f, 0f); + builder.addVertex(x + 1, y + 1 / 16f, z).setColor(color).setUv(1, 0).setLight(lightmap).setNormal(0f, 1f, 0f); //NORTH if (Block.shouldRenderFace(Blocks.FARMLAND.defaultBlockState(), world, pos, Direction.SOUTH, pos.relative(Direction.SOUTH))) { - builder.vertex(x, y + 1 / 16f, z + 1).color(color).uv(0, 1f / 16).uv2(lightmap).normal(0f, 0f, -1f).endVertex(); - builder.vertex(x, y, z + 1).color(color).uv(0, 0).uv2(lightmap).normal(0f, 0f, -1f).endVertex(); - builder.vertex(x + 1, y, z + 1).color(color).uv(1, 0).uv2(lightmap).normal(0f, 0f, -1f).endVertex(); - builder.vertex(x + 1, y + 1 / 16f, z + 1).color(color).uv(1, 1f / 16).uv2(lightmap).normal(0f, 0f, -1f).endVertex(); + builder.addVertex(x, y + 1 / 16f, z + 1).setColor(color).setUv(0, 1f / 16).setLight(lightmap).setNormal(0f, 0f, -1f); + builder.addVertex(x, y, z + 1).setColor(color).setUv(0, 0).setLight(lightmap).setNormal(0f, 0f, -1f); + builder.addVertex(x + 1, y, z + 1).setColor(color).setUv(1, 0).setLight(lightmap).setNormal(0f, 0f, -1f); + builder.addVertex(x + 1, y + 1 / 16f, z + 1).setColor(color).setUv(1, 1f / 16).setLight(lightmap).setNormal(0f, 0f, -1f); } //EAST if (Block.shouldRenderFace(Blocks.FARMLAND.defaultBlockState(), world, pos, Direction.WEST, pos.relative(Direction.WEST))) { - builder.vertex(x, y + 1/16f, z).color(color).uv(0,1f/16).uv2(lightmap).normal(-1f, 0f, 0f).endVertex(); - builder.vertex(x, y, z).color(color).uv(0, 0).uv2(lightmap).normal(-1f, 0f, 0f).endVertex(); - builder.vertex(x, y, z + 1).color(color).uv(1, 0).uv2(lightmap).normal(-1f, 0f, 0f).endVertex(); - builder.vertex(x, y + 1/16f, z + 1).color(color).uv(1, 1f/16).uv2(lightmap).normal(-1f, 0f, 0f).endVertex(); + builder.addVertex(x, y + 1/16f, z).setColor(color).setUv(0,1f/16).setLight(lightmap).setNormal(-1f, 0f, 0f); + builder.addVertex(x, y, z).setColor(color).setUv(0, 0).setLight(lightmap).setNormal(-1f, 0f, 0f); + builder.addVertex(x, y, z + 1).setColor(color).setUv(1, 0).setLight(lightmap).setNormal(-1f, 0f, 0f); + builder.addVertex(x, y + 1/16f, z + 1).setColor(color).setUv(1, 1f/16).setLight(lightmap).setNormal(-1f, 0f, 0f); } //SOUTH if (Block.shouldRenderFace(Blocks.FARMLAND.defaultBlockState(), world, pos, Direction.NORTH, pos.relative(Direction.NORTH))) { - builder.vertex(x+1, y + 1/16f, z).color(color).uv(0,1f/16).uv2(lightmap).normal(0f, 0f, 1f).endVertex(); - builder.vertex(x+1, y, z).color(color).uv(0, 0).uv2(lightmap).normal(0f, 0f, -1f).endVertex(); - builder.vertex(x, y, z).color(color).uv(1, 0).uv2(lightmap).normal(0f, 0f, -1f).endVertex(); - builder.vertex(x, y + 1/16f, z).color(color).uv(1, 1f/16).uv2(lightmap).normal(0f, 0f, -1f).endVertex(); + builder.addVertex(x+1, y + 1/16f, z).setColor(color).setUv(0,1f/16).setLight(lightmap).setNormal(0f, 0f, 1f); + builder.addVertex(x+1, y, z).setColor(color).setUv(0, 0).setLight(lightmap).setNormal(0f, 0f, -1f); + builder.addVertex(x, y, z).setColor(color).setUv(1, 0).setLight(lightmap).setNormal(0f, 0f, -1f); + builder.addVertex(x, y + 1/16f, z).setColor(color).setUv(1, 1f/16).setLight(lightmap).setNormal(0f, 0f, -1f); } //WEST if (Block.shouldRenderFace(Blocks.FARMLAND.defaultBlockState(), world, pos, Direction.EAST, pos.relative(Direction.EAST))) { - builder.vertex(x+1, y + 1/16f, z+1).color(color).uv(0,1f/16).uv2(lightmap).normal(1f, 0f, 0f).endVertex(); - builder.vertex(x+1, y, z+1).color(color).uv(0, 0).uv2(lightmap).normal(1f, 0f, 0f).endVertex(); - builder.vertex(x+1, y, z).color(color).uv(1, 0).uv2(lightmap).normal(1f, 0f, 0f).endVertex(); - builder.vertex(x+1, y + 1/16f, z).color(color).uv(1, 1f/16).uv2(lightmap).normal(1f, 0f, 0f).endVertex(); + builder.addVertex(x+1, y + 1/16f, z+1).setColor(color).setUv(0,1f/16).setLight(lightmap).setNormal(1f, 0f, 0f); + builder.addVertex(x+1, y, z+1).setColor(color).setUv(0, 0).setLight(lightmap).setNormal(1f, 0f, 0f); + builder.addVertex(x+1, y, z).setColor(color).setUv(1, 0).setLight(lightmap).setNormal(1f, 0f, 0f); + builder.addVertex(x+1, y + 1/16f, z).setColor(color).setUv(1, 1f/16).setLight(lightmap).setNormal(1f, 0f, 0f); } } @Override public ResourceLocation getResourceLocation() { - return new ResourceLocation(Lighty.MOD_ID, "farmland_mode"); + return ResourceLocation.fromNamespaceAndPath(Lighty.MOD_ID, "farmland_mode"); } public static void init() { diff --git a/common/src/main/java/dev/schmarrn/lighty/mode/NumberMode.java b/common/src/main/java/dev/schmarrn/lighty/mode/NumberMode.java index 6fabdda..f5f61c8 100644 --- a/common/src/main/java/dev/schmarrn/lighty/mode/NumberMode.java +++ b/common/src/main/java/dev/schmarrn/lighty/mode/NumberMode.java @@ -33,11 +33,6 @@ import net.minecraft.world.level.block.state.BlockState; public class NumberMode extends LightyMode { - @Override - public void beforeCompute(BufferBuilder builder) { - builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); - } - private static final float PXL = 1/16f; private static final float dx = 0.25f; private static final float dz = 0.25f; @@ -46,30 +41,26 @@ private static void renderDigit(BufferBuilder builder, int digit, float x, float float startU = (0b11 & digit) / 4f; float startV = ((digit >> 2) & 0b11) / 4f; - builder.vertex(x, y, z) - .color(color) - .uv(startU,startV) - .uv2(lightmap) - .normal(0f, 1f, 0f) - .endVertex(); - builder.vertex(x, y, z + dz) - .color(color) - .uv(startU, startV + 0.25f) - .uv2(lightmap) - .normal(0f, 1f, 0f) - .endVertex(); - builder.vertex(x + dx, y, z + dz) - .color(color) - .uv(startU + 0.25f, startV + 0.25f) - .uv2(lightmap) - .normal(0f, 1f, 0f) - .endVertex(); - builder.vertex(x + dx, y, z) - .color(color) - .uv(startU + 0.25f, startV) - .uv2(lightmap) - .normal(0f, 1f, 0f) - .endVertex(); + builder.addVertex(x, y, z) + .setColor(color) + .setUv(startU,startV) + .setLight(lightmap) + .setNormal(0f, 1f, 0f); + builder.addVertex(x, y, z + dz) + .setColor(color) + .setUv(startU, startV + 0.25f) + .setLight(lightmap) + .setNormal(0f, 1f, 0f); + builder.addVertex(x + dx, y, z + dz) + .setColor(color) + .setUv(startU + 0.25f, startV + 0.25f) + .setLight(lightmap) + .setNormal(0f, 1f, 0f); + builder.addVertex(x + dx, y, z) + .setColor(color) + .setUv(startU + 0.25f, startV) + .setLight(lightmap) + .setNormal(0f, 1f, 0f); } private static void renderNumber(BufferBuilder builder, int number, float x, float y, float z, int color, int lightmap) { @@ -121,12 +112,12 @@ public void compute(ClientLevel world, BlockPos pos, BufferBuilder builder) { public void beforeRendering() { RenderType.cutout().setupRenderState(); RenderSystem.enableDepthTest(); - RenderSystem.setShaderTexture(0, new ResourceLocation(Lighty.MOD_ID, "textures/block/numbers.png")); + RenderSystem.setShaderTexture(0, ResourceLocation.fromNamespaceAndPath(Lighty.MOD_ID, "textures/block/numbers.png")); } @Override public ResourceLocation getResourceLocation() { - return new ResourceLocation(Lighty.MOD_ID, "number_mode"); + return ResourceLocation.fromNamespaceAndPath(Lighty.MOD_ID, "number_mode"); } public static void init() { diff --git a/common/src/main/java/dev/schmarrn/lighty/ui/SettingsScreen.java b/common/src/main/java/dev/schmarrn/lighty/ui/SettingsScreen.java index ac49c24..0ce4b08 100644 --- a/common/src/main/java/dev/schmarrn/lighty/ui/SettingsScreen.java +++ b/common/src/main/java/dev/schmarrn/lighty/ui/SettingsScreen.java @@ -16,66 +16,44 @@ import dev.schmarrn.lighty.config.Config; import dev.schmarrn.lighty.event.Compute; +import net.minecraft.client.Minecraft; import net.minecraft.client.OptionInstance; -import net.minecraft.client.gui.components.Button; -import net.minecraft.client.gui.components.OptionsList; -import net.minecraft.client.gui.screens.OptionsSubScreen; +import net.minecraft.client.gui.screens.options.OptionsSubScreen; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; public class SettingsScreen extends OptionsSubScreen { - private final Screen parent; - private OptionsList list; + public SettingsScreen(Screen parent) { // passing null to options is fine, because it is only used in the respective OptionsSubScreens, // and we don't use it here //noinspection DataFlowIssue - super(parent, null, Component.translatable("settings.lighty.title")); - this.parent = parent; + super(parent, Minecraft.getInstance().options, Component.translatable("settings.lighty.title")); } @Override - protected void init() { - assert this.minecraft != null; - list = new OptionsList(this.minecraft, this.width, this.height - 32, this); - - list.addBig(Config.OVERLAY_DISTANCE.getOptionInstance()); - list.addBig(Config.OVERLAY_BRIGHTNESS.getOptionInstance()); - list.addSmall( + protected void addOptions() { + this.list.addBig(Config.OVERLAY_DISTANCE.getOptionInstance()); + this.list.addBig(Config.OVERLAY_BRIGHTNESS.getOptionInstance()); + this.list.addSmall( new OptionInstance[]{ Config.BLOCK_THRESHOLD.getOptionInstance(), Config.SKY_THRESHOLD.getOptionInstance(), } ); - list.addBig(Config.FARM_GROWTH_THRESHOLD.getOptionInstance()); - list.addBig(Config.FARM_UPROOT_THRESHOLD.getOptionInstance()); - list.addSmall( + this.list.addBig(Config.FARM_GROWTH_THRESHOLD.getOptionInstance()); + this.list.addBig(Config.FARM_UPROOT_THRESHOLD.getOptionInstance()); + this.list.addSmall( new OptionInstance[]{ Config.SHOW_SAFE.getOptionInstance(), Config.SHOULD_AUTO_ON.getOptionInstance() } ); - - this.addRenderableWidget(list); - this.layout.addTitleHeader(this.title, this.font); - this.layout.addToFooter(Button.builder(CommonComponents.GUI_DONE, $$0 -> this.onClose()).width(200).build()); - this.layout.visitWidgets(this::addRenderableWidget); - - this.repositionElements(); - } - - @Override - protected void repositionElements() { - super.repositionElements(); - this.list.updateSize(this.width, this.layout); } @Override - public void onClose() { + public void removed() { Compute.clear(); - assert this.minecraft != null; - this.minecraft.setScreen(parent); } @Override diff --git a/fabric/build.gradle b/fabric/build.gradle index c900b99..8ec77c7 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -67,7 +67,8 @@ processResources { mod_description: mod_description, issue_url: issue_url, modmenu_version: modmenu_version, - fabric_loader_version: fabric_loader_version + fabric_loader_version: fabric_loader_version, + minecraft_version_lower_bound: minecraft_version_lower_bound ] inputs.properties replaceProperties diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 12dfb5e..101b7a9 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -32,7 +32,7 @@ ], "depends": { "fabricloader": ">=${fabric_loader_version}", - "minecraft": ">=${minecraft_version}", + "minecraft": ">=${minecraft_version_lower_bound}", "fabric-api-base": "*", "fabric-lifecycle-events-v1": "*", "fabric-rendering-v1": "*", diff --git a/gradle.properties b/gradle.properties index 679d3c1..2265517 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,10 @@ org.gradle.jvmargs=-Xmx2048M -minecraft_version=1.20.6 +minecraft_version=1.21-rc1 +minecraft_version_lower_bound = 1.21- fabric_enabled=true -neoforge_enabled=true +neoforge_enabled=false issue_url=https://github.com/SchmarrnDevs/Lighty/issues @@ -11,10 +12,10 @@ mod_version=3.0.0-beta.3 maven_group=dev.schmarrn mod_name=Lighty -fabric_loader_version=0.15.6 -fabric_api_version=0.99.0+1.20.6 +fabric_loader_version=0.15.11 +fabric_api_version=0.100.1+1.21 -modmenu_version = 10.0.0-beta.1 +modmenu_version = 11.0.0-beta.1 # neo stuff neo_version=20.6.98-beta