diff --git a/src/main/java/nl/requios/effortlessbuilding/AllIcons.java b/src/main/java/nl/requios/effortlessbuilding/AllIcons.java new file mode 100644 index 0000000..3805ed8 --- /dev/null +++ b/src/main/java/nl/requios/effortlessbuilding/AllIcons.java @@ -0,0 +1,144 @@ +package nl.requios.effortlessbuilding; + +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.math.Matrix4f; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.renderer.LightTexture; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.phys.Vec3; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import nl.requios.effortlessbuilding.create.Create; +import nl.requios.effortlessbuilding.create.foundation.gui.element.DelegatedStencilElement; +import nl.requios.effortlessbuilding.create.foundation.gui.element.ScreenElement; +import nl.requios.effortlessbuilding.create.foundation.utility.Color; + +public class AllIcons implements ScreenElement { + + public static final ResourceLocation ICON_ATLAS = Create.asResource("textures/gui/icons.png"); + public static final int ICON_ATLAS_SIZE = 256; + private static int x = 0, y = -1; + private int iconX; + private int iconY; + + public static final AllIcons + I_SETTINGS = newRow(), + I_UNDO = next(), + I_REDO = next(), + I_REPLACE = next(); + + public static final AllIcons + I_DISABLE = newRow(), + I_SINGLE = next(), + I_LINE = next(), + I_WALL = next(), + I_FLOOR = next(), + I_CUBE = next(), + I_DIAGONAL_LINE = next(), + I_DIAGONAL_WALL = next(), + I_SLOPED_FLOOR = next(), + I_CIRCLE = next(), + I_CYLINDER = next(), + I_SPHERE = next(), + I_PYRAMID = next(), + I_CONE = next(), + I_DOME = next(); + + public static final AllIcons + I_NORMAL_SPEED = newRow(), + I_FAST_SPEED = next(), + I_FILLED = next(), + I_HOLLOW = next(), + I_CUBE_FILLED = next(), + I_CUBE_HOLLOW = next(), + I_CUBE_SKELETON = next(), + I_SHORT_EDGE = next(), + I_LONG_EDGE = next(), + I_CIRCLE_START_CORNER = next(), + I_CIRCLE_START_CENTER = next(), + I_THICKNESS_1 = next(), + I_THICKNESS_3 = next(), + I_THICKNESS_5 = next(); + + public static final AllIcons + I_PLAYER = newRow(), + I_BLOCK_CENTER = next(), + I_BLOCK_CORNER = next(), + I_HIDE_LINES = next(), + I_SHOW_LINES = next(), + I_HIDE_AREAS = next(), + I_SHOW_AREAS = next(); + + + public AllIcons(int x, int y) { + iconX = x * 16; + iconY = y * 16; + } + + private static AllIcons next() { + return new AllIcons(++x, y); + } + + private static AllIcons newRow() { + return new AllIcons(x = 0, ++y); + } + + @OnlyIn(Dist.CLIENT) + public void bind() { + RenderSystem.setShaderTexture(0, ICON_ATLAS); + } + + @OnlyIn(Dist.CLIENT) + @Override + public void render(PoseStack matrixStack, int x, int y) { + bind(); + GuiComponent.blit(matrixStack, x, y, 0, iconX, iconY, 16, 16, 256, 256); + } + + @OnlyIn(Dist.CLIENT) + public void render(PoseStack matrixStack, int x, int y, GuiComponent component) { + bind(); + component.blit(matrixStack, x, y, iconX, iconY, 16, 16); + } + + @OnlyIn(Dist.CLIENT) + public void render(PoseStack ms, MultiBufferSource buffer, int color) { + VertexConsumer builder = buffer.getBuffer(RenderType.textSeeThrough(ICON_ATLAS)); + Matrix4f matrix = ms.last().pose(); + Color rgb = new Color(color); + int light = LightTexture.FULL_BRIGHT; + + Vec3 vec1 = new Vec3(0, 0, 0); + Vec3 vec2 = new Vec3(0, 1, 0); + Vec3 vec3 = new Vec3(1, 1, 0); + Vec3 vec4 = new Vec3(1, 0, 0); + + float u1 = iconX * 1f / ICON_ATLAS_SIZE; + float u2 = (iconX + 16) * 1f / ICON_ATLAS_SIZE; + float v1 = iconY * 1f / ICON_ATLAS_SIZE; + float v2 = (iconY + 16) * 1f / ICON_ATLAS_SIZE; + + vertex(builder, matrix, vec1, rgb, u1, v1, light); + vertex(builder, matrix, vec2, rgb, u1, v2, light); + vertex(builder, matrix, vec3, rgb, u2, v2, light); + vertex(builder, matrix, vec4, rgb, u2, v1, light); + } + + @OnlyIn(Dist.CLIENT) + private void vertex(VertexConsumer builder, Matrix4f matrix, Vec3 vec, Color rgb, float u, float v, int light) { + builder.vertex(matrix, (float) vec.x, (float) vec.y, (float) vec.z) + .color(rgb.getRed(), rgb.getGreen(), rgb.getBlue(), 255) + .uv(u, v) + .uv2(light) + .endVertex(); + } + + @OnlyIn(Dist.CLIENT) + public DelegatedStencilElement asStencil() { + return new DelegatedStencilElement().withStencilRenderer((ms, w, h, alpha) -> this.render(ms, 0, 0)).withBounds(16, 16); + } +} diff --git a/src/main/java/nl/requios/effortlessbuilding/create/foundation/gui/AllIcons.java b/src/main/java/nl/requios/effortlessbuilding/create/foundation/gui/AllIcons.java index f97f8fa..3b14501 100644 --- a/src/main/java/nl/requios/effortlessbuilding/create/foundation/gui/AllIcons.java +++ b/src/main/java/nl/requios/effortlessbuilding/create/foundation/gui/AllIcons.java @@ -19,7 +19,7 @@ import net.minecraftforge.api.distmarker.OnlyIn; public class AllIcons implements ScreenElement { - public static final ResourceLocation ICON_ATLAS = Create.asResource("textures/gui/icons.png"); + public static final ResourceLocation ICON_ATLAS = Create.asResource("textures/gui/create_icons.png"); public static final int ICON_ATLAS_SIZE = 256; private static int x = 0, y = -1; diff --git a/src/main/java/nl/requios/effortlessbuilding/gui/buildmodifier/ArrayEntry.java b/src/main/java/nl/requios/effortlessbuilding/gui/buildmodifier/ArrayEntry.java index 7ef3f81..c113e02 100644 --- a/src/main/java/nl/requios/effortlessbuilding/gui/buildmodifier/ArrayEntry.java +++ b/src/main/java/nl/requios/effortlessbuilding/gui/buildmodifier/ArrayEntry.java @@ -17,6 +17,7 @@ import nl.requios.effortlessbuilding.create.foundation.gui.AbstractSimiScreen; import nl.requios.effortlessbuilding.create.foundation.gui.widget.Label; import nl.requios.effortlessbuilding.create.foundation.gui.widget.ScrollInput; import nl.requios.effortlessbuilding.create.foundation.utility.Components; +import nl.requios.effortlessbuilding.create.foundation.utility.FontHelper; import nl.requios.effortlessbuilding.gui.elements.GuiCheckBoxFixed; import nl.requios.effortlessbuilding.gui.elements.GuiNumberField; import nl.requios.effortlessbuilding.gui.elements.GuiScrollPane; @@ -100,31 +101,31 @@ public class ArrayEntry extends BaseModifierEntry { //draw offset labels for (int i = 0; i < 3; i++) { - offsetLabels.get(i).x = x + 75 + 20 * i; - offsetLabels.get(i).y = y + 24; + offsetLabels.get(i).x = x + 65 + 20 * i - getFont().width(offsetLabels.get(i).text) / 2; + offsetLabels.get(i).y = y + 23; offsetLabels.get(i).render(ms, mouseX, mouseY, partialTicks); } //draw offset inputs for (int i = 0; i < 3; i++) { - offsetInputs.get(i).x = x + 75 + 20 * i; - offsetInputs.get(i).y = y + 24; + offsetInputs.get(i).x = x + 65 + 20 * i; + offsetInputs.get(i).y = y + 23; offsetInputs.get(i).render(ms, mouseX, mouseY, partialTicks); } //draw count label - countLabel.x = x + 140; - countLabel.y = y + 24; + countLabel.x = x + 65; + countLabel.y = y + 45; countLabel.render(ms, mouseX, mouseY, partialTicks); //draw count input - countInput.x = x + 140; - countInput.y = y + 24; + countInput.x = x + 65; + countInput.y = y + 45; countInput.render(ms, mouseX, mouseY, partialTicks); //draw reach label reachLabel.x = x + width - 125; - reachLabel.y = y + 40; + reachLabel.y = y + 23; reachLabel.render(ms, mouseX, mouseY, partialTicks); } @@ -135,7 +136,7 @@ public class ArrayEntry extends BaseModifierEntry { int currentReach = Math.max(-1, getArrayReach()); int maxReach = ReachHelper.getMaxReach(Minecraft.getInstance().player); ChatFormatting reachColor = isCurrentReachValid(currentReach, maxReach) ? ChatFormatting.GRAY : ChatFormatting.RED; - var reachText = "Reach: " + reachColor + currentReach + ChatFormatting.GRAY + "/" + ChatFormatting.GRAY + maxReach; + var reachText = "" + reachColor + currentReach + ChatFormatting.GRAY + "/" + ChatFormatting.GRAY + maxReach; reachLabel.text = Component.literal(reachText); } diff --git a/src/main/java/nl/requios/effortlessbuilding/gui/buildmodifier/ModifiersScreenList.java b/src/main/java/nl/requios/effortlessbuilding/gui/buildmodifier/ModifiersScreenList.java index 31ba404..143fea1 100644 --- a/src/main/java/nl/requios/effortlessbuilding/gui/buildmodifier/ModifiersScreenList.java +++ b/src/main/java/nl/requios/effortlessbuilding/gui/buildmodifier/ModifiersScreenList.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; import net.minecraft.client.gui.components.ObjectSelectionList; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.network.chat.Component; @@ -150,5 +151,9 @@ public class ModifiersScreenList extends ObjectSelectionList