aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/utils
diff options
context:
space:
mode:
authorAaron <51387595+AzureAaron@users.noreply.github.com>2024-06-13 21:46:56 -0400
committerAaron <51387595+AzureAaron@users.noreply.github.com>2024-06-18 16:34:37 -0400
commit3a53e51494523871870491617ae6add9b3fe87fe (patch)
tree2ad7c2e1718b3441f33d09e1be19c4051b0a1b44 /src/main/java/de/hysky/skyblocker/utils
parent265c09b16b78b93a55745ce8dd008d405e735d6b (diff)
downloadSkyblocker-3a53e51494523871870491617ae6add9b3fe87fe.tar.gz
Skyblocker-3a53e51494523871870491617ae6add9b3fe87fe.tar.bz2
Skyblocker-3a53e51494523871870491617ae6add9b3fe87fe.zip
1.21
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/utils')
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/ColorUtils.java13
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/datafixer/ItemStackComponentizationFixer.java19
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java43
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/render/gui/AbstractPopupScreen.java4
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/render/gui/SideTabButtonWidget.java2
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/render/title/TitleContainer.java5
6 files changed, 47 insertions, 39 deletions
diff --git a/src/main/java/de/hysky/skyblocker/utils/ColorUtils.java b/src/main/java/de/hysky/skyblocker/utils/ColorUtils.java
index 0196edf2..4b17ef1a 100644
--- a/src/main/java/de/hysky/skyblocker/utils/ColorUtils.java
+++ b/src/main/java/de/hysky/skyblocker/utils/ColorUtils.java
@@ -1,5 +1,7 @@
package de.hysky.skyblocker.utils;
+import net.minecraft.util.DyeColor;
+
public class ColorUtils {
/**
* Takes an RGB color as an integer and returns an array of the color's components as floats, in RGB format.
@@ -13,4 +15,15 @@ public class ColorUtils {
(color & 0xFF) / 255f
};
}
+
+ /**
+ * @param dye The dye from which the entity color will be used for the components.
+ */
+ public static float[] getFloatComponents(DyeColor dye) {
+ return new float[] {
+ ((dye.getEntityColor() >> 16) & 0xFF) / 255f,
+ ((dye.getEntityColor() >> 8) & 0xFF) / 255f,
+ (dye.getEntityColor() & 0xFF) / 255f
+ };
+ }
}
diff --git a/src/main/java/de/hysky/skyblocker/utils/datafixer/ItemStackComponentizationFixer.java b/src/main/java/de/hysky/skyblocker/utils/datafixer/ItemStackComponentizationFixer.java
index 3543a2f1..959e6a5f 100644
--- a/src/main/java/de/hysky/skyblocker/utils/datafixer/ItemStackComponentizationFixer.java
+++ b/src/main/java/de/hysky/skyblocker/utils/datafixer/ItemStackComponentizationFixer.java
@@ -1,7 +1,6 @@
package de.hysky.skyblocker.utils.datafixer;
import java.util.Arrays;
-import java.util.List;
import java.util.Objects;
import java.util.Optional;
@@ -10,16 +9,17 @@ import com.mojang.serialization.Dynamic;
import net.minecraft.command.argument.ItemStringReader;
import net.minecraft.command.argument.ItemStringReader.ItemResult;
-import net.minecraft.component.DataComponentType;
+import net.minecraft.component.ComponentType;
import net.minecraft.datafixer.Schemas;
import net.minecraft.datafixer.TypeReferences;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtOps;
-import net.minecraft.registry.DynamicRegistryManager;
+import net.minecraft.registry.BuiltinRegistries;
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryOps;
+import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.util.Identifier;
/**
@@ -30,10 +30,10 @@ import net.minecraft.util.Identifier;
public class ItemStackComponentizationFixer {
private static final int ITEM_NBT_DATA_VERSION = 3817;
private static final int ITEM_COMPONENTS_DATA_VERSION = 3825;
- private static final DynamicRegistryManager REGISTRY_MANAGER = new DynamicRegistryManager.ImmutableImpl(List.of(Registries.ITEM, Registries.DATA_COMPONENT_TYPE));
+ private static final WrapperLookup LOOKUP = BuiltinRegistries.createWrapperLookup();
public static ItemStack fixUpItem(NbtCompound nbt) {
- Dynamic<NbtElement> dynamic = Schemas.getFixer().update(TypeReferences.ITEM_STACK, new Dynamic<>(NbtOps.INSTANCE, nbt), ITEM_NBT_DATA_VERSION, ITEM_COMPONENTS_DATA_VERSION);
+ Dynamic<NbtElement> dynamic = Schemas.getFixer().update(TypeReferences.ITEM_STACK, new Dynamic<>(LOOKUP.getOps(NbtOps.INSTANCE), nbt), ITEM_NBT_DATA_VERSION, ITEM_COMPONENTS_DATA_VERSION);
return ItemStack.CODEC.parse(dynamic).getOrThrow();
}
@@ -44,11 +44,11 @@ public class ItemStackComponentizationFixer {
* @return The {@link ItemStack}'s components as a string which is in the format that the {@code /give} command accepts.
*/
public static String componentsAsString(ItemStack stack) {
- RegistryOps<NbtElement> nbtRegistryOps = REGISTRY_MANAGER.getOps(NbtOps.INSTANCE);
+ RegistryOps<NbtElement> nbtRegistryOps = LOOKUP.getOps(NbtOps.INSTANCE);
return Arrays.toString(stack.getComponentChanges().entrySet().stream().map(entry -> {
@SuppressWarnings("unchecked")
- DataComponentType<Object> dataComponentType = (DataComponentType<Object>) entry.getKey();
+ ComponentType<Object> dataComponentType = (ComponentType<Object>) entry.getKey();
Identifier componentId = Registries.DATA_COMPONENT_TYPE.getId(dataComponentType);
Optional<NbtElement> encodedComponent = dataComponentType.getCodec().encodeStart(nbtRegistryOps, entry.getValue().orElseThrow()).result();
@@ -66,13 +66,14 @@ public class ItemStackComponentizationFixer {
* @return an {@link ItemStack} or {@link ItemStack#EMPTY} if there was an exception thrown.
*/
public static ItemStack fromComponentsString(String itemId, int count, String componentsString) {
- ItemStringReader reader = new ItemStringReader(REGISTRY_MANAGER);
+ ItemStringReader reader = new ItemStringReader(LOOKUP);
try {
ItemResult result = reader.consume(new StringReader(itemId + componentsString));
ItemStack stack = new ItemStack(result.item(), count);
- stack.applyComponentsFrom(result.components());
+ //Vanilla skips validation with /give so we will too
+ stack.applyUnvalidatedChanges(result.components());
return stack;
} catch (Exception ignored) {}
diff --git a/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java b/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java
index a6772fb2..50ffabd6 100644
--- a/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java
+++ b/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java
@@ -18,6 +18,7 @@ import net.minecraft.client.render.*;
import net.minecraft.client.render.VertexFormat.DrawMode;
import net.minecraft.client.texture.Scaling;
import net.minecraft.client.texture.Sprite;
+import net.minecraft.client.util.BufferAllocator;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.OrderedText;
@@ -25,6 +26,7 @@ import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
+import net.minecraft.util.math.ColorHelper;
import net.minecraft.util.math.Vec3d;
import org.joml.Matrix3f;
@@ -40,11 +42,12 @@ import java.lang.invoke.MethodType;
public class RenderHelper {
private static final Logger LOGGER = LogUtils.getLogger();
- private static final Identifier TRANSLUCENT_DRAW = new Identifier(SkyblockerMod.NAMESPACE, "translucent_draw");
+ private static final Identifier TRANSLUCENT_DRAW = Identifier.of(SkyblockerMod.NAMESPACE, "translucent_draw");
private static final MethodHandle SCHEDULE_DEFERRED_RENDER_TASK = getDeferredRenderTaskHandle();
private static final Vec3d ONE = new Vec3d(1, 1, 1);
private static final int MAX_OVERWORLD_BUILD_HEIGHT = 319;
private static final MinecraftClient client = MinecraftClient.getInstance();
+ private static final BufferAllocator ALLOCATOR = new BufferAllocator(1536);
public static void init() {
WorldRenderEvents.AFTER_TRANSLUCENT.addPhaseOrdering(Event.DEFAULT_PHASE, TRANSLUCENT_DRAW);
@@ -95,7 +98,7 @@ public class RenderHelper {
matrices.push();
matrices.translate(pos.getX() - camera.getX(), pos.getY() - camera.getY(), pos.getZ() - camera.getZ());
- BeaconBlockEntityRendererInvoker.renderBeam(matrices, context.consumers(), context.tickDelta(), context.world().getTime(), 0, MAX_OVERWORLD_BUILD_HEIGHT, colorComponents);
+ BeaconBlockEntityRendererInvoker.renderBeam(matrices, context.consumers(), context.tickCounter().getTickDelta(true), context.world().getTime(), 0, MAX_OVERWORLD_BUILD_HEIGHT, ColorHelper.Argb.fromFloats(1f, colorComponents[0], colorComponents[1], colorComponents[2]));
matrices.pop();
}
@@ -110,7 +113,6 @@ public class RenderHelper {
MatrixStack matrices = context.matrixStack();
Vec3d camera = context.camera().getPos();
Tessellator tessellator = RenderSystem.renderThreadTesselator();
- BufferBuilder buffer = tessellator.getBuffer();
RenderSystem.setShader(GameRenderer::getRenderTypeLinesProgram);
RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
@@ -122,9 +124,9 @@ public class RenderHelper {
matrices.push();
matrices.translate(-camera.getX(), -camera.getY(), -camera.getZ());
- buffer.begin(DrawMode.LINES, VertexFormats.LINES);
+ BufferBuilder buffer = tessellator.begin(DrawMode.LINES, VertexFormats.LINES);
WorldRenderer.drawBox(matrices, buffer, box, colorComponents[0], colorComponents[1], colorComponents[2], 1f);
- tessellator.draw();
+ BufferRenderer.drawWithGlobalProgram(buffer.end());
matrices.pop();
RenderSystem.lineWidth(1f);
@@ -156,7 +158,6 @@ public class RenderHelper {
matrices.translate(-camera.x, -camera.y, -camera.z);
Tessellator tessellator = RenderSystem.renderThreadTesselator();
- BufferBuilder buffer = tessellator.getBuffer();
Matrix4f positionMatrix = matrices.peek().getPositionMatrix();
Matrix3f normalMatrix = matrices.peek().getNormalMatrix();
@@ -172,7 +173,7 @@ public class RenderHelper {
RenderSystem.enableDepthTest();
RenderSystem.depthFunc(throughWalls ? GL11.GL_ALWAYS : GL11.GL_LEQUAL);
- buffer.begin(DrawMode.LINE_STRIP, VertexFormats.LINES);
+ BufferBuilder buffer = tessellator.begin(DrawMode.LINE_STRIP, VertexFormats.LINES);
for (int i = 0; i < points.length; i++) {
Vec3d nextPoint = points[i + 1 == points.length ? i - 1 : i + 1];
@@ -180,11 +181,10 @@ public class RenderHelper {
buffer
.vertex(positionMatrix, (float) points[i].getX(), (float) points[i].getY(), (float) points[i].getZ())
.color(colorComponents[0], colorComponents[1], colorComponents[2], alpha)
- .normal(normalVec.x, normalVec.y, normalVec.z)
- .next();
+ .normal(normalVec.x, normalVec.y, normalVec.z);
}
- tessellator.draw();
+ BufferRenderer.drawWithGlobalProgram(buffer.end());
matrices.pop();
GL11.glDisable(GL11.GL_LINE_SMOOTH);
@@ -201,7 +201,6 @@ public class RenderHelper {
matrices.translate(-camera.x, -camera.y, -camera.z);
Tessellator tessellator = RenderSystem.renderThreadTesselator();
- BufferBuilder buffer = tessellator.getBuffer();
Matrix4f positionMatrix = matrices.peek().getPositionMatrix();
GL11.glEnable(GL11.GL_LINE_SMOOTH);
@@ -219,22 +218,21 @@ public class RenderHelper {
Vec3d offset = Vec3d.fromPolar(context.camera().getPitch(), context.camera().getYaw());
Vec3d cameraPoint = camera.add(offset);
- buffer.begin(DrawMode.LINES, VertexFormats.LINES);
+ BufferBuilder buffer = tessellator.begin(DrawMode.LINES, VertexFormats.LINES);
+
Vector3f normal = new Vector3f((float) offset.x, (float) offset.y, (float) offset.z);
buffer
.vertex(positionMatrix, (float) cameraPoint.x , (float) cameraPoint.y, (float) cameraPoint.z)
.color(colorComponents[0], colorComponents[1], colorComponents[2], alpha)
- .normal(normal.x, normal.y, normal.z)
- .next();
+ .normal(normal.x, normal.y, normal.z);
buffer
.vertex(positionMatrix, (float) point.getX(), (float) point.getY(), (float) point.getZ())
.color(colorComponents[0], colorComponents[1], colorComponents[2], alpha)
- .normal(normal.x, normal.y, normal.z)
- .next();
+ .normal(normal.x, normal.y, normal.z);
- tessellator.draw();
+ BufferRenderer.drawWithGlobalProgram(buffer.end());
matrices.pop();
GL11.glDisable(GL11.GL_LINE_SMOOTH);
@@ -250,7 +248,6 @@ public class RenderHelper {
positionMatrix.translate((float) -camera.x, (float) -camera.y, (float) -camera.z);
Tessellator tessellator = RenderSystem.renderThreadTesselator();
- BufferBuilder buffer = tessellator.getBuffer();
RenderSystem.setShader(GameRenderer::getPositionColorProgram);
RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
@@ -259,11 +256,11 @@ public class RenderHelper {
RenderSystem.disableCull();
RenderSystem.depthFunc(throughWalls ? GL11.GL_ALWAYS : GL11.GL_LEQUAL);
- buffer.begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR);
+ BufferBuilder buffer = tessellator.begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR);
for (int i = 0; i < 4; i++) {
- buffer.vertex(positionMatrix, (float) points[i].getX(), (float) points[i].getY(), (float) points[i].getZ()).color(colorComponents[0], colorComponents[1], colorComponents[2], alpha).next();
+ buffer.vertex(positionMatrix, (float) points[i].getX(), (float) points[i].getY(), (float) points[i].getZ()).color(colorComponents[0], colorComponents[1], colorComponents[2], alpha);
}
- tessellator.draw();
+ BufferRenderer.drawWithGlobalProgram(buffer.end());
RenderSystem.enableCull();
RenderSystem.depthFunc(GL11.GL_LEQUAL);
@@ -301,9 +298,7 @@ public class RenderHelper {
float xOffset = -textRenderer.getWidth(text) / 2f;
- Tessellator tessellator = RenderSystem.renderThreadTesselator();
- BufferBuilder buffer = tessellator.getBuffer();
- VertexConsumerProvider.Immediate consumers = VertexConsumerProvider.immediate(buffer);
+ VertexConsumerProvider.Immediate consumers = VertexConsumerProvider.immediate(ALLOCATOR);
RenderSystem.depthFunc(throughWalls ? GL11.GL_ALWAYS : GL11.GL_LEQUAL);
diff --git a/src/main/java/de/hysky/skyblocker/utils/render/gui/AbstractPopupScreen.java b/src/main/java/de/hysky/skyblocker/utils/render/gui/AbstractPopupScreen.java
index e7a3e8b2..903611ae 100644
--- a/src/main/java/de/hysky/skyblocker/utils/render/gui/AbstractPopupScreen.java
+++ b/src/main/java/de/hysky/skyblocker/utils/render/gui/AbstractPopupScreen.java
@@ -12,13 +12,11 @@ import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;
-import java.util.function.Consumer;
-
/**
* A more bare-bones version of Vanilla's Popup Screen. Meant to be extended.
*/
public class AbstractPopupScreen extends Screen {
- private static final Identifier BACKGROUND_TEXTURE = new Identifier("popup/background");
+ private static final Identifier BACKGROUND_TEXTURE = Identifier.ofVanilla("popup/background");
private final Screen backgroundScreen;
protected AbstractPopupScreen(Text title, Screen backgroundScreen) {
diff --git a/src/main/java/de/hysky/skyblocker/utils/render/gui/SideTabButtonWidget.java b/src/main/java/de/hysky/skyblocker/utils/render/gui/SideTabButtonWidget.java
index 87da0d36..889d3b02 100644
--- a/src/main/java/de/hysky/skyblocker/utils/render/gui/SideTabButtonWidget.java
+++ b/src/main/java/de/hysky/skyblocker/utils/render/gui/SideTabButtonWidget.java
@@ -8,7 +8,7 @@ import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;
public class SideTabButtonWidget extends ToggleButtonWidget {
- private static final ButtonTextures TEXTURES = new ButtonTextures(new Identifier("recipe_book/tab"), new Identifier("recipe_book/tab_selected"));
+ private static final ButtonTextures TEXTURES = new ButtonTextures(Identifier.ofVanilla("recipe_book/tab"), Identifier.ofVanilla("recipe_book/tab_selected"));
protected @NotNull ItemStack icon;
public void setIcon(@NotNull ItemStack icon) {
diff --git a/src/main/java/de/hysky/skyblocker/utils/render/title/TitleContainer.java b/src/main/java/de/hysky/skyblocker/utils/render/title/TitleContainer.java
index c21485e2..cb754308 100644
--- a/src/main/java/de/hysky/skyblocker/utils/render/title/TitleContainer.java
+++ b/src/main/java/de/hysky/skyblocker/utils/render/title/TitleContainer.java
@@ -9,6 +9,7 @@ import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallba
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
+import net.minecraft.client.render.RenderTickCounter;
import net.minecraft.util.math.MathHelper;
import java.util.LinkedHashSet;
@@ -81,8 +82,8 @@ public class TitleContainer {
titles.remove(title);
}
- private static void render(DrawContext context, float tickDelta) {
- render(context, titles, SkyblockerConfigManager.get().uiAndVisuals.titleContainer.x, SkyblockerConfigManager.get().uiAndVisuals.titleContainer.y, tickDelta);
+ private static void render(DrawContext context, RenderTickCounter tickCounter) {
+ render(context, titles, SkyblockerConfigManager.get().uiAndVisuals.titleContainer.x, SkyblockerConfigManager.get().uiAndVisuals.titleContainer.y, tickCounter.getTickDelta(true));
}
protected static void render(DrawContext context, Set<Title> titles, int xPos, int yPos, float tickDelta) {