diff --git a/Versionfiles b/Versionfiles index 1cd2e04..f4d3df2 160000 --- a/Versionfiles +++ b/Versionfiles @@ -1 +1 @@ -Subproject commit 1cd2e046963507d75cc455d6d935d4b2a270dadc +Subproject commit f4d3df2e83c7adb2efb9f8820e7766df7b551d27 diff --git a/build.gradle b/build.gradle index b6aea22..6292cd3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id "fabric-loom" version "1.8-SNAPSHOT" + id "fabric-loom" version "1.10-SNAPSHOT" // id "org.ajoberstar.grgit" version "3.1.1" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index df97d72..cea7a79 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/java/win/baruna/blockmeter/ModConfig.java b/src/main/java/win/baruna/blockmeter/ModConfig.java index 137058b..b1bf9eb 100644 --- a/src/main/java/win/baruna/blockmeter/ModConfig.java +++ b/src/main/java/win/baruna/blockmeter/ModConfig.java @@ -13,6 +13,7 @@ public class ModConfig implements ConfigData { @ConfigEntry.Gui.Tooltip(count = 3) public boolean sendBoxes = true; public boolean showBoxesWhenDisabled = false; + @ConfigEntry.Gui.Excluded public boolean backgroundForLabels = true; @ConfigEntry.BoundedDiscrete(max=200, min = 7) diff --git a/src/main/java/win/baruna/blockmeter/gui/OptionsGui.java b/src/main/java/win/baruna/blockmeter/gui/OptionsGui.java index a5654b1..f398f1f 100644 --- a/src/main/java/win/baruna/blockmeter/gui/OptionsGui.java +++ b/src/main/java/win/baruna/blockmeter/gui/OptionsGui.java @@ -4,9 +4,10 @@ import me.shedaniel.math.Color; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gl.ShaderProgramKey; -import net.minecraft.client.gl.ShaderProgramKeys; +//import net.minecraft.client.gl.ShaderProgramKey; +//import net.minecraft.client.gl.ShaderProgramKeys; import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.ButtonTextures; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.render.*; @@ -14,6 +15,7 @@ import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.DyeColor; +import net.minecraft.util.Identifier; import win.baruna.blockmeter.BlockMeterClient; import win.baruna.blockmeter.ModConfig; import win.baruna.blockmeter.measurebox.ClientMeasureBox; @@ -36,14 +38,14 @@ protected void init() { final int colorIndex = i * 4 + j; this.addDrawableChild(new ColorButton(this.width / 2 - 44 + j * 22, this.height / 2 - 88 + i * 22, 20, 20, null, - Color.ofOpaque(DyeColor.byId(colorIndex) + Color.ofOpaque(DyeColor.byIndex(colorIndex) .getMapColor().color), config.colorIndex == colorIndex, false, button -> { ClientMeasureBox.setColorIndex(colorIndex); final ClientMeasureBox currentBox = BlockMeterClient.getInstance().getCurrentBox(); if (currentBox != null) - currentBox.setColor(DyeColor.byId(colorIndex)); + currentBox.setColor(DyeColor.byIndex(colorIndex)); MinecraftClient.getInstance().setScreen(null); })); } @@ -107,6 +109,9 @@ class ColorButton extends ButtonWidget { boolean selected; boolean texture; MutableText text; + private static final ButtonTextures TEXTURES = new ButtonTextures( + Identifier.ofVanilla("widget/button"), Identifier.ofVanilla("widget/button_disabled"), Identifier.ofVanilla("widget/button_highlighted") + ); @Override public void onPress() { @@ -136,23 +141,28 @@ public void onPress() { @Override public void renderWidget(DrawContext context, final int int_1, final int int_2, final float float_1) { - Tessellator tessellator = Tessellator.getInstance(); - var bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); - RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR); - - int r = this.color.getRed(); - int g = this.color.getGreen(); - int b = this.color.getBlue(); - int a = texture ? 102 : 255; - bufferBuilder.vertex(this.x - (texture ? 1 : 0), this.y - (texture ? 1 : 0), 0f) - .color(r, g, b, a); - bufferBuilder.vertex(this.x - (texture ? 1 : 0), this.y + this.height + (texture ? 1 : 0), 0f) - .color(r, g, b, a); - bufferBuilder.vertex(this.x + this.width + (texture ? 1 : 0), this.y + this.height + (texture ? 1 : 0), 0f) - .color(r, g, b, a); - bufferBuilder.vertex(this.x + this.width + (texture ? 1 : 0), this.y - (texture ? 1 : 0), 0f) - .color(r, g, b, a); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + context.drawGuiTexture( + RenderLayer::getGuiTextured, + TEXTURES.get(this.active, this.isSelected()), + x, y, width, height, color.getColor() + ); +// Tessellator tessellator = Tessellator.getInstance(); +// var bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); +// RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR); +// +// int r = this.color.getRed(); +// int g = this.color.getGreen(); +// int b = this.color.getBlue(); +// int a = texture ? 102 : 255; +// bufferBuilder.vertex(this.x - (texture ? 1 : 0), this.y - (texture ? 1 : 0), 0f) +// .color(r, g, b, a); +// bufferBuilder.vertex(this.x - (texture ? 1 : 0), this.y + this.height + (texture ? 1 : 0), 0f) +// .color(r, g, b, a); +// bufferBuilder.vertex(this.x + this.width + (texture ? 1 : 0), this.y + this.height + (texture ? 1 : 0), 0f) +// .color(r, g, b, a); +// bufferBuilder.vertex(this.x + this.width + (texture ? 1 : 0), this.y - (texture ? 1 : 0), 0f) +// .color(r, g, b, a); +// BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); if (text != null) { boolean dark = (0.299f * color.getRed() + 0.587f * color.getBlue() + 0.114f * color.getRed()) / 255f < 0.8f; diff --git a/src/main/java/win/baruna/blockmeter/measurebox/ClientMeasureBox.java b/src/main/java/win/baruna/blockmeter/measurebox/ClientMeasureBox.java index 6a148a1..9bc1c69 100644 --- a/src/main/java/win/baruna/blockmeter/measurebox/ClientMeasureBox.java +++ b/src/main/java/win/baruna/blockmeter/measurebox/ClientMeasureBox.java @@ -1,13 +1,17 @@ package win.baruna.blockmeter.measurebox; -import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.pipeline.RenderPipeline; +import com.mojang.blaze3d.platform.DepthTestFunction; +import com.mojang.blaze3d.vertex.VertexFormat; import me.shedaniel.autoconfig.AutoConfig; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gl.ShaderProgramKeys; -import net.minecraft.client.render.*; -import net.minecraft.client.render.VertexFormat.DrawMode; +import net.minecraft.client.gl.RenderPipelines; +import net.minecraft.client.render.RenderLayer; +import net.minecraft.client.render.RenderPhase; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.VertexFormats; import net.minecraft.client.util.BufferAllocator; import net.minecraft.text.Text; import net.minecraft.util.DyeColor; @@ -18,17 +22,39 @@ import win.baruna.blockmeter.BlockMeterClient; import win.baruna.blockmeter.ModConfig; -import java.awt.*; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.OptionalDouble; -public class ClientMeasureBox extends MeasureBox { - private Box box; - private int argb; +import static net.minecraft.client.gl.RenderPipelines.MATRICES_COLOR_SNIPPET; +public class ClientMeasureBox extends MeasureBox { + private static final RenderLayer.MultiPhase DEBUG_LINE_STRIP = RenderLayer.of( + "debug_line_strip_no_depth", + 1536, + RenderPipelines.register( + RenderPipeline.builder(MATRICES_COLOR_SNIPPET) + .withLocation("pipeline/debug_line_strip") + .withVertexShader("core/position_color") + .withFragmentShader("core/position_color") + .withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST) + .withCull(false) + .withVertexFormat(VertexFormats.POSITION_COLOR, VertexFormat.DrawMode.DEBUG_LINE_STRIP) + .build() + ), + RenderLayer.MultiPhaseParameters.builder().lineWidth(new RenderPhase.LineWidth(OptionalDouble.of(4.0))).build(false) + + ); + private static final RenderLayer.MultiPhase DEBUG_QUADS = RenderLayer.of( + "debug_quads_no_depth", 1536, false, true, RenderPipelines.register( + RenderPipeline.builder(RenderPipelines.POSITION_COLOR_SNIPPET).withLocation("pipeline/debug_quads").withCull(false).withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST).build() + ), RenderLayer.MultiPhaseParameters.builder().build(false) + ); @NotNull public MiningRestriction miningRestriction; + private Box box; + private int argb; protected ClientMeasureBox(final BlockPos blockStart, final BlockPos blockEnd, final Identifier dimension, final DyeColor color, final boolean finished, final int mode, final int orientation) { @@ -49,6 +75,32 @@ public static ClientMeasureBox getBox(final BlockPos block, final Identifier dim return box; } + /** + * If enabled increments to next color + */ + static private void incrementColor() { + final ModConfig conf = BlockMeterClient.getConfigManager().getConfig(); + + if (conf.incrementColor) { + setColorIndex(conf.colorIndex + 1); + } + } + + /** + * Accessor for the currently selected color + * + * @return currently selected color + */ + static private DyeColor getSelectedColor() { + final ModConfig conf = BlockMeterClient.getConfigManager().getConfig(); + return DyeColor.byIndex(conf.colorIndex); + } + + public static void setColorIndex(final int newColor) { + BlockMeterClient.getConfigManager().getConfig().colorIndex = Math.floorMod(newColor, DyeColor.values().length); + BlockMeterClient.getConfigManager().save(); + } + /** * Sets the second box corner * @@ -123,58 +175,38 @@ public void render(final WorldRenderContext context, final Identifier currentDim } final Vec3d pos = context.camera().getPos(); var stack = context.matrixStack(); - - // FIXME This actually does nothing - RenderSystem.lineWidth(2.0f); - - RenderSystem.disableDepthTest(); - RenderSystem.disableBlend(); + var buffer = context.consumers().getBuffer(DEBUG_LINE_STRIP); stack.push(); stack.translate(-pos.x, -pos.y, -pos.z); final Matrix4f model = stack.peek().getPositionMatrix(); - final Tessellator tess = Tessellator.getInstance(); - - RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR); - - BufferBuilder buffer = tess.begin(DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION_COLOR); buffer.vertex(model, (float) this.box.minX, (float) this.box.minY, (float) this.box.minZ).color(argb); buffer.vertex(model, (float) this.box.maxX, (float) this.box.minY, (float) this.box.minZ).color(argb); buffer.vertex(model, (float) this.box.maxX, (float) this.box.minY, (float) this.box.maxZ).color(argb); buffer.vertex(model, (float) this.box.minX, (float) this.box.minY, (float) this.box.maxZ).color(argb); buffer.vertex(model, (float) this.box.minX, (float) this.box.minY, (float) this.box.minZ).color(argb); - ; buffer.vertex(model, (float) this.box.minX, (float) this.box.maxY, (float) this.box.minZ).color(argb); - ; buffer.vertex(model, (float) this.box.minX, (float) this.box.maxY, (float) this.box.minZ).color(argb); buffer.vertex(model, (float) this.box.maxX, (float) this.box.maxY, (float) this.box.minZ).color(argb); buffer.vertex(model, (float) this.box.maxX, (float) this.box.maxY, (float) this.box.maxZ).color(argb); buffer.vertex(model, (float) this.box.minX, (float) this.box.maxY, (float) this.box.maxZ).color(argb); buffer.vertex(model, (float) this.box.minX, (float) this.box.maxY, (float) this.box.minZ).color(argb); - ; buffer.vertex(model, (float) this.box.minX, (float) this.box.maxY, (float) this.box.maxZ).color(argb); buffer.vertex(model, (float) this.box.minX, (float) this.box.minY, (float) this.box.maxZ).color(argb); - ; buffer.vertex(model, (float) this.box.maxX, (float) this.box.minY, (float) this.box.maxZ).color(argb); buffer.vertex(model, (float) this.box.maxX, (float) this.box.maxY, (float) this.box.maxZ).color(argb); - ; buffer.vertex(model, (float) this.box.maxX, (float) this.box.maxY, (float) this.box.minZ).color(argb); buffer.vertex(model, (float) this.box.maxX, (float) this.box.minY, (float) this.box.minZ).color(argb); - BufferRenderer.drawWithGlobalProgram(buffer.end()); if (BlockMeterClient.getConfigManager().getConfig().innerDiagonal) { - buffer = tess.begin(DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR); + buffer = context.consumers().getBuffer(DEBUG_LINE_STRIP); buffer.vertex(model, (float) this.box.minX, (float) this.box.minY, (float) this.box.minZ).color(argb); buffer.vertex(model, (float) this.box.maxX, (float) this.box.maxY, (float) this.box.maxZ).color(argb); - BufferRenderer.drawWithGlobalProgram(buffer.end()); } - RenderSystem.lineWidth(1.0f); this.drawLengths(context, boxCreatorName); - RenderSystem.enableBlend(); - RenderSystem.enableDepthTest(); stack.pop(); } @@ -278,41 +310,41 @@ private void drawLengths(final WorldRenderContext context, final Text boxCreator private void drawBackground(final WorldRenderContext context, final double x, final double y, final double z, final float yaw, final float pitch, final String text, final Vec3d playerPos) { - final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; - - final var literalText = Text.literal(text); - - float size = 0.03f; - final int constDist = 10; - - if (AutoConfig.getConfigHolder(ModConfig.class).getConfig().minimalLabelSize) { - final float dist = (float) Math.sqrt((x - playerPos.x) * (x - playerPos.x) - + (y - playerPos.y) * (y - playerPos.y) + (z - playerPos.z) * (z - playerPos.z)); - if (dist > constDist) - size = dist * size / constDist; - } - - var stack = context.matrixStack(); - stack.push(); - stack.translate(x, y + 0.15, z); - stack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180.0F - yaw)); - stack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-pitch)); - stack.scale(size, -size, 0.001f); - final int width = textRenderer.getWidth(literalText); - stack.translate((-width / 2f), 0.0, 0.0); - final Matrix4f model = stack.peek().getPositionMatrix(); - - final ModConfig conf = BlockMeterClient.getConfigManager().getConfig(); - if (conf.backgroundForLabels) { - var buffer = Tessellator.getInstance().begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR); - buffer.vertex(model, -1, -1, 0).color(argb); - buffer.vertex(model, -1, 8, 0).color(argb); - buffer.vertex(model, width, 8, 0).color(argb); - buffer.vertex(model, width, -1, 0).color(argb); - BufferRenderer.drawWithGlobalProgram(buffer.end()); - } - - stack.pop(); + // TODO figure this out +// final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; +// +// final var literalText = Text.literal(text); +// +// float size = 0.03f; +// final int constDist = 10; +// +// if (AutoConfig.getConfigHolder(ModConfig.class).getConfig().minimalLabelSize) { +// final float dist = (float) Math.sqrt((x - playerPos.x) * (x - playerPos.x) +// + (y - playerPos.y) * (y - playerPos.y) + (z - playerPos.z) * (z - playerPos.z)); +// if (dist > constDist) +// size = dist * size / constDist; +// } +// +// var stack = context.matrixStack(); +// stack.push(); +// stack.translate(x, y + 0.15, z); +// stack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180.0F - yaw)); +// stack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-pitch)); +// stack.scale(size, -size, 0.001f); +// final int width = textRenderer.getWidth(literalText); +// stack.translate((-width / 2f), 0.0, 0.0); +// final Matrix4f model = stack.peek().getPositionMatrix(); +// +// final ModConfig conf = BlockMeterClient.getConfigManager().getConfig(); +// if (conf.backgroundForLabels) { +// var buffer = context.consumers().getBuffer(DEBUG_QUADS); +// buffer.vertex(model, -1, -1, 0).color(argb); +// buffer.vertex(model, -1, 8, 0).color(argb); +// buffer.vertex(model, width, 8, 0).color(argb); +// buffer.vertex(model, width, -1, 0).color(argb); +// } +// +// stack.pop(); } private void drawText(final WorldRenderContext context, final double x, final double y, final double z, @@ -345,11 +377,12 @@ private void drawText(final WorldRenderContext context, final double x, final do int textColor = color.getSignColor(); final ModConfig conf = BlockMeterClient.getConfigManager().getConfig(); - if (conf.backgroundForLabels) { - var color = new Color(argb); - float luminance = (0.299f * color.getRed() + 0.587f * color.getGreen() + 0.114f * color.getBlue()); - textColor = luminance < 0.4f ? DyeColor.WHITE.getSignColor() : DyeColor.BLACK.getSignColor(); - } + // TODO figure this out +// if (conf.backgroundForLabels) { +// var color = new Color(argb); +// float luminance = (0.299f * color.getRed() + 0.587f * color.getGreen() + 0.114f * color.getBlue()); +// textColor = luminance < 0.4f ? DyeColor.WHITE.getSignColor() : DyeColor.BLACK.getSignColor(); +// } final VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(new BufferAllocator(0)); textRenderer.draw( @@ -369,51 +402,10 @@ private void drawText(final WorldRenderContext context, final double x, final do stack.pop(); } - /** - * If enabled increments to next color - */ - static private void incrementColor() { - final ModConfig conf = BlockMeterClient.getConfigManager().getConfig(); - - if (conf.incrementColor) { - setColorIndex(conf.colorIndex + 1); - } - } - - /** - * Accessor for the currently selected color - * - * @return currently selected color - */ - static private DyeColor getSelectedColor() { - final ModConfig conf = BlockMeterClient.getConfigManager().getConfig(); - return DyeColor.byId(conf.colorIndex); - } - - public static void setColorIndex(final int newColor) { - BlockMeterClient.getConfigManager().getConfig().colorIndex = Math.floorMod(newColor, DyeColor.values().length); - BlockMeterClient.getConfigManager().save(); - } - public boolean contains(BlockPos block) { return BlockBox.create(blockStart, blockEnd).contains(block); } - private static class Line implements Comparable { - Box line; - double distance; - - Line(final Box line, final Vec3d pos) { - this.line = line; - this.distance = line.getCenter().distanceTo(pos); - } - - @Override - public int compareTo(final Line l) { - return Double.compare(this.distance, l.distance); - } - } - public enum MiningRestriction { Off("options.off"), Inside("blockmeter.restrictMining.inside"), @@ -440,4 +432,19 @@ public MiningRestriction next() { } } } + + private static class Line implements Comparable { + Box line; + double distance; + + Line(final Box line, final Vec3d pos) { + this.line = line; + this.distance = line.getCenter().distanceTo(pos); + } + + @Override + public int compareTo(final Line l) { + return Double.compare(this.distance, l.distance); + } + } } diff --git a/src/main/java/win/baruna/blockmeter/measurebox/MeasureBox.java b/src/main/java/win/baruna/blockmeter/measurebox/MeasureBox.java index 2e8033e..66030c5 100644 --- a/src/main/java/win/baruna/blockmeter/measurebox/MeasureBox.java +++ b/src/main/java/win/baruna/blockmeter/measurebox/MeasureBox.java @@ -57,7 +57,7 @@ protected MeasureBox(PacketByteBuf attachedData) { this.blockStart = attachedData.readBlockPos(); this.blockEnd = attachedData.readBlockPos(); this.dimension = attachedData.readIdentifier(); - this.color = DyeColor.byId(attachedData.readInt()); + this.color = DyeColor.byIndex(attachedData.readInt()); this.finished = attachedData.readBoolean(); this.mode = attachedData.readInt(); this.orientation = attachedData.readInt(); @@ -76,7 +76,7 @@ public void writePacketBuf(PacketByteBuf buf) { buf.writeBlockPos(this.blockStart); buf.writeBlockPos(this.blockEnd); buf.writeIdentifier(dimension); - buf.writeInt(color.getId()); + buf.writeInt(color.getIndex()); buf.writeBoolean(finished); buf.writeInt(mode); buf.writeInt(orientation); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 832671a..97e60df 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -19,7 +19,7 @@ "depends": { "fabricloader": "*", "fabric": "*", - "minecraft": "1.21.*" + "minecraft": ">=1.21.5" }, "recommends": { "modmenu": "*" diff --git a/src/test/java/de/modprog/blockmeter/measurebox/ClientMeasureBoxTest.java b/src/test/java/de/modprog/blockmeter/measurebox/ClientMeasureBoxTest.java deleted file mode 100644 index d206f50..0000000 --- a/src/test/java/de/modprog/blockmeter/measurebox/ClientMeasureBoxTest.java +++ /dev/null @@ -1,112 +0,0 @@ -package de.modprog.blockmeter.measurebox; - -import de.modprog.blockmeter.util.JSONSource; -import de.modprog.blockmeter.util.parser.ParseBlockPos; -import de.modprog.blockmeter.util.parser.ParseDyeColor; -import me.shedaniel.autoconfig.ConfigManager; -import net.minecraft.util.DyeColor; -import net.minecraft.util.math.BlockPos; -import org.junit.jupiter.params.ParameterizedTest; -import org.mockito.MockedStatic; -import org.mockito.Mockito; -import win.baruna.blockmeter.BlockMeterClient; -import win.baruna.blockmeter.ModConfig; -import win.baruna.blockmeter.measurebox.ClientMeasureBox; - -import static net.minecraft.world.dimension.DimensionTypes.OVERWORLD_ID; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.when; - -public class ClientMeasureBoxTest { - - @ParameterizedTest - @JSONSource(classes = {ParseDyeColor.class}, jsons = {"red", "black", - "green", "blue"}) - void testSetColor(final DyeColor color) { - try (MockedStatic client = getBMC()) { - final ClientMeasureBox box = ClientMeasureBox.getBox(new BlockPos(0, 0, 0), - OVERWORLD_ID); - - box.setColor(color); - - assertThat(box.getColor()).isEqualTo(color); - } - } - - @ParameterizedTest - @JSONSource(classes = {ParseBlockPos.class, ParseBlockPos.class, - ParseBlockPos.class, ParseBlockPos.class, ParseBlockPos.class, - ParseBlockPos.class, ParseBlockPos.class, - ParseBlockPos.class}, jsons = { - "(0|0|0), (10|10|10), (0|0|10), (0|10|0), (0|10|10), (10|0|0), (10|0|10), (10|10|0)", - "(-30|5|25), (-90|2|50), (-30|5|50), (-30|2|25), (-30|2|50), (-90|5|25), (-90|5|50), (-90|2|25)" - }) - void testIsCorner(BlockPos bp0, BlockPos bp1, BlockPos bp2, BlockPos bp3, - BlockPos bp4, BlockPos bp5, BlockPos bp6, BlockPos bp7) { - try (MockedStatic client = getBMC()) { - final ClientMeasureBox box = ClientMeasureBox - .getBox(bp0, OVERWORLD_ID); - - box.setBlockEnd(bp1); - - assertThat(box.isCorner(bp0)); - assertThat(box.isCorner(bp1)); - assertThat(box.isCorner(bp2)); - assertThat(box.isCorner(bp3)); - assertThat(box.isCorner(bp4)); - assertThat(box.isCorner(bp5)); - assertThat(box.isCorner(bp6)); - assertThat(box.isCorner(bp7)); - } - - } - - @ParameterizedTest - @JSONSource(classes = {ParseBlockPos.class, ParseBlockPos.class, - ParseBlockPos.class}, jsons = { - "(0|1|2), (3|4|5), (0|4|2)" - }) - void testLoosenCorner(BlockPos bp0, BlockPos bp1, BlockPos newBp0) { - try (MockedStatic client = getBMC()) { - final ClientMeasureBox box = ClientMeasureBox - .getBox(bp0, OVERWORLD_ID); - - box.setBlockEnd(bp1); - box.setFinished(); - - box.loosenCorner(newBp0); - - assertThat(box.isCorner(bp0)).isTrue(); - assertThat(box.isCorner(bp1)).isTrue(); - assertThat(box.getBlockEnd()).isEqualTo(newBp0); - assertThat(box.isFinished()).isFalse(); - } - } - - @ParameterizedTest - @JSONSource(classes = {ParseDyeColor.class}, jsons = { - "red", "blue", "white", "black" - }) - void testSetColorIndex(DyeColor color) { - try (MockedStatic client = getBMC()) { - ClientMeasureBox.setColorIndex(color.getId()); - final ClientMeasureBox box = ClientMeasureBox - .getBox(new BlockPos(0, 0, 0), OVERWORLD_ID); - - assertThat(box.getColor()).isEqualTo(color); - } - } - - @SuppressWarnings("unchecked") - private MockedStatic getBMC() { - final MockedStatic client = Mockito - .mockStatic(BlockMeterClient.class); - final ConfigManager configHolder = Mockito - .mock(ConfigManager.class); - when(configHolder.getConfig()).thenReturn(new ModConfig()); - - client.when(BlockMeterClient::getConfigManager) - .thenReturn(configHolder); - return client; - } -} diff --git a/src/test/java/de/modprog/blockmeter/util/JSONProvider.java b/src/test/java/de/modprog/blockmeter/util/JSONProvider.java deleted file mode 100644 index f39636f..0000000 --- a/src/test/java/de/modprog/blockmeter/util/JSONProvider.java +++ /dev/null @@ -1,91 +0,0 @@ -package de.modprog.blockmeter.util; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.stream.Stream; -import java.util.stream.Stream.Builder; - -import com.google.gson.Gson; - -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.ArgumentsProvider; -import org.junit.jupiter.params.support.AnnotationConsumer; - -import de.modprog.blockmeter.util.parser.Parser; - -public class JSONProvider - implements ArgumentsProvider, AnnotationConsumer { - private String[] jsons; - @SuppressWarnings("rawtypes") - private Class[] classes; - - JSONProvider() {} - - @Override - public void accept(JSONSource source) { - jsons = source.jsons(); - classes = source.classes(); - } - - @SuppressWarnings("unchecked") - public Stream provideArguments( - ExtensionContext context) { - Gson gson = new Gson(); - return Stream.of(jsons).map(this::split).map((objectsStrings) -> { - Builder builder = Stream.builder(); - for (int i = 0; i < objectsStrings.length; i++) { - - if (Parser.class.isAssignableFrom(classes[i])) - - try { - builder.add( - ((Parser) classes[i] - .getConstructor() - .newInstance()) - .parse(trimspaces( - objectsStrings[i]))); - } catch (InstantiationException | IllegalAccessException - | IllegalArgumentException - | InvocationTargetException | NoSuchMethodException - | SecurityException e) { - e.printStackTrace(); - } - else { - builder.add(gson.fromJson(objectsStrings[i], classes[i])); - } - } - return Arguments.of(builder.build().toArray()); - }); - } - - private String trimspaces(String string) { - return string.replaceAll("^\\s*|\\s*$", ""); - } - - public String[] split(String input) { - int parans = 0; - ArrayList output = new ArrayList(); - output.add(""); - for (char c: input.toCharArray()) { - switch (c) { - case '(': - case '{': - case '[': - parans++; - break; - case ')': - case ']': - case '}': - parans--; - } - if (parans == 0 && c == ',') - output.add(""); - else - output.set(output.size() - 1, - output.get(output.size() - 1) + c); - } - return output.toArray(new String[] {}); - } - -} diff --git a/src/test/java/de/modprog/blockmeter/util/JSONSource.java b/src/test/java/de/modprog/blockmeter/util/JSONSource.java deleted file mode 100644 index 5440c02..0000000 --- a/src/test/java/de/modprog/blockmeter/util/JSONSource.java +++ /dev/null @@ -1,19 +0,0 @@ -package de.modprog.blockmeter.util; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.junit.jupiter.params.provider.ArgumentsSource; - -@Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD }) -@Retention(RetentionPolicy.RUNTIME) -@ArgumentsSource(JSONProvider.class) -public @interface JSONSource { - - String[] jsons(); - - @SuppressWarnings("rawtypes") - Class[] classes(); -} diff --git a/src/test/java/de/modprog/blockmeter/util/parser/ParseBlockPos.java b/src/test/java/de/modprog/blockmeter/util/parser/ParseBlockPos.java deleted file mode 100644 index 61ba958..0000000 --- a/src/test/java/de/modprog/blockmeter/util/parser/ParseBlockPos.java +++ /dev/null @@ -1,18 +0,0 @@ -package de.modprog.blockmeter.util.parser; - -import java.util.stream.Stream; - -import net.minecraft.util.math.BlockPos; - -public class ParseBlockPos implements Parser { - - @Override - public BlockPos parse(String string) { - Integer[] split = Stream - .of(string.substring(1, string.length() - 1).split("\\|")) - .map(Integer::parseInt) - .toArray(Integer[]::new); - return new BlockPos(split[0], split[1], split[2]); - } - -} diff --git a/src/test/java/de/modprog/blockmeter/util/parser/ParseDyeColor.java b/src/test/java/de/modprog/blockmeter/util/parser/ParseDyeColor.java deleted file mode 100644 index 553962f..0000000 --- a/src/test/java/de/modprog/blockmeter/util/parser/ParseDyeColor.java +++ /dev/null @@ -1,12 +0,0 @@ -package de.modprog.blockmeter.util.parser; - -import net.minecraft.util.DyeColor; - -public class ParseDyeColor implements Parser { - - @Override - public DyeColor parse(String string) { - return DyeColor.byName(string, DyeColor.BLACK); - } - -} diff --git a/src/test/java/de/modprog/blockmeter/util/parser/Parser.java b/src/test/java/de/modprog/blockmeter/util/parser/Parser.java deleted file mode 100644 index 32e4145..0000000 --- a/src/test/java/de/modprog/blockmeter/util/parser/Parser.java +++ /dev/null @@ -1,5 +0,0 @@ -package de.modprog.blockmeter.util.parser; - -public interface Parser { - T parse(String string); -} diff --git a/src/test/resources/org/powermock/extensions/configuration.properties b/src/test/resources/org/powermock/extensions/configuration.properties deleted file mode 100644 index 07a84de..0000000 --- a/src/test/resources/org/powermock/extensions/configuration.properties +++ /dev/null @@ -1 +0,0 @@ -powermock.global-ignore=javax.xml.parsers.*,org.apache.xerces.jaxp.*,com.sun.org.apache.xerces.*,org.xml.* \ No newline at end of file diff --git a/version.properties b/version.properties index 66ac2be..6a42784 100644 --- a/version.properties +++ b/version.properties @@ -1,2 +1,2 @@ -modVersion = 1.15 -minecraftVersion = 1.21.3 +modVersion = 1.16 +minecraftVersion = 1.21.5