diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/CloseablePoseStack.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/CloseablePoseStack.java deleted file mode 100644 index 98f8afe..0000000 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/CloseablePoseStack.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.teamresourceful.resourcefullib.client; - -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.world.phys.Vec3; -import org.jetbrains.annotations.NotNull; -import org.joml.Matrix4fc; -import org.joml.Quaternionfc; - -public class CloseablePoseStack extends PoseStack implements AutoCloseable { - - private final PoseStack stack; - - public CloseablePoseStack(PoseStack stack) { - super(); - this.stack = stack; - this.stack.pushPose(); - } - - public CloseablePoseStack(GuiGraphics graphics) { - this(graphics.pose()); - } - - public CloseablePoseStack() { - this(new PoseStack()); - } - - @Override - public void translate(Vec3 vec3) { - stack.translate(vec3); - } - - @Override - public void translate(double d, double e, double f) { - stack.translate(d, e, f); - } - - @Override - public void translate(float f, float g, float h) { - stack.translate(f, g, h); - } - - @Override - public void scale(float f, float g, float h) { - stack.scale(f, g, h); - } - - @Override - public void mulPose(Quaternionfc quaternionfc) { - stack.mulPose(quaternionfc); - } - - @Override - public void rotateAround(Quaternionfc quaternionfc, float f, float g, float h) { - stack.rotateAround(quaternionfc, f, g, h); - } - - @NotNull - @Override - public PoseStack.Pose last() { - return stack.last(); - } - - @Override - public void setIdentity() { - stack.setIdentity(); - } - - @Override - public void mulPose(Matrix4fc matrix4fc) { - stack.mulPose(matrix4fc); - } - - @Override - public void close() { - stack.popPose(); - } - - @Override - public boolean isEmpty() { - return stack.isEmpty(); - } - - @Override - public void pushPose() { - stack.pushPose(); - } - - @Override - public void popPose() { - stack.popPose(); - } -} diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/closables/CloseablePose.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/closables/CloseablePose.java new file mode 100644 index 0000000..81c6443 --- /dev/null +++ b/common/src/main/java/com/teamresourceful/resourcefullib/client/closables/CloseablePose.java @@ -0,0 +1,15 @@ +package com.teamresourceful.resourcefullib.client.closables; + +import net.minecraft.client.gui.GuiGraphics; + +public record CloseablePose(GuiGraphics graphics) implements AutoCloseable { + + public CloseablePose { + graphics.pose().pushMatrix(); + } + + @Override + public void close() { + this.graphics.pose().popMatrix(); + } +} diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/closables/CloseableScissor.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/closables/CloseableScissor.java new file mode 100644 index 0000000..9e1b8a7 --- /dev/null +++ b/common/src/main/java/com/teamresourceful/resourcefullib/client/closables/CloseableScissor.java @@ -0,0 +1,16 @@ +package com.teamresourceful.resourcefullib.client.closables; + +import net.minecraft.client.gui.GuiGraphics; + +public record CloseableScissor(GuiGraphics graphics) implements AutoCloseable { + + public CloseableScissor(GuiGraphics graphics, int x, int y, int width, int height) { + this(graphics); + graphics.enableScissor(x, y, width, height); + } + + @Override + public void close() { + graphics.disableScissor(); + } +} \ No newline at end of file diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/components/ImageButton.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/components/ImageButton.java deleted file mode 100644 index cb3c0ee..0000000 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/components/ImageButton.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.teamresourceful.resourcefullib.client.components; - -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.components.AbstractButton; -import net.minecraft.client.gui.narration.NarrationElementOutput; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.network.chat.CommonComponents; -import net.minecraft.resources.ResourceLocation; -import org.jetbrains.annotations.NotNull; - -public abstract class ImageButton extends AbstractButton { - - protected int imageWidth = 256; - protected int imageHeight = 256; - - public ImageButton(int x, int y, int width, int height) { - super(x, y, width, height, CommonComponents.EMPTY); - } - - @Override - public void renderWidget(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) { - graphics.blit( - RenderType::guiTextured, - getTexture(mouseX, mouseY), - getX(), getY(), - getU(mouseX, mouseY), getV(mouseX, mouseY), - this.width, this.height, - this.imageWidth, this.imageHeight - ); - } - - public abstract ResourceLocation getTexture(int mouseX, int mouseY); - public abstract int getU(int mouseX, int mouseY); - public abstract int getV(int mouseX, int mouseY); - - @Override - protected void updateWidgetNarration(@NotNull NarrationElementOutput output) { - - } -} diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/components/ParentWidget.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/components/ParentWidget.java deleted file mode 100644 index 95e315b..0000000 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/components/ParentWidget.java +++ /dev/null @@ -1,145 +0,0 @@ -package com.teamresourceful.resourcefullib.client.components; - -import com.google.common.collect.Lists; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.components.AbstractWidget; -import net.minecraft.client.gui.components.Renderable; -import net.minecraft.client.gui.components.events.AbstractContainerEventHandler; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.layouts.LayoutElement; -import net.minecraft.client.gui.narration.NarratableEntry; -import net.minecraft.client.gui.narration.NarrationElementOutput; -import net.minecraft.client.gui.navigation.ScreenRectangle; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.function.Consumer; - -public abstract class ParentWidget extends AbstractContainerEventHandler implements Renderable, LayoutElement, NarratableEntry { - - public final List renderables = Lists.newArrayList(); - protected final List children = Lists.newArrayList(); - - protected int x, y; - protected int width, height; - - private boolean active = true; - - public ParentWidget(int x, int y) { - this.x = x; - this.y = y; - } - - abstract protected void init(); - - @Override - public @NotNull List children() { - if (!this.active) return List.of(); - return children; - } - - protected T addRenderableWidget(T widget) { - this.renderables.add(widget); - this.children.add(widget); - return widget; - } - - @Override - public void render(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) { - if (!this.active) return; - for (Renderable renderable : renderables) { - renderable.render(graphics, mouseX, mouseY, partialTicks); - } - } - - @Override - public @NotNull NarrationPriority narrationPriority() { - return NarrationPriority.NONE; - } - - @Override - public void updateNarration(@NotNull NarrationElementOutput output) { - - } - - @Override - public void setFocused(boolean focused) { - if (!focused) { - setFocused(null); - } - } - - @Override - public void setX(int x) { - this.x = x; - } - - @Override - public void setY(int y) { - this.y = y; - } - - @Override - public int getX() { - return this.x; - } - - @Override - public int getY() { - return this.y; - } - - @Override - public int getWidth() { - return this.width; - } - - @Override - public int getHeight() { - return this.height; - } - - public void setWidth(int width) { - this.width = width; - } - - public void setHeight(int height) { - this.height = height; - } - - @Override - public void visitWidgets(Consumer consumer) { - for (GuiEventListener child : this.children()) { - if (child instanceof AbstractWidget widget) { - consumer.accept(widget); - } - if (child instanceof LayoutElement layout) { - layout.visitWidgets(consumer); - } - } - } - - @Override - public @NotNull ScreenRectangle getRectangle() { - return LayoutElement.super.getRectangle(); - } - - @Override - public boolean isMouseOver(double mouseX, double mouseY) { - return this.active && (mouseX >= this.x && mouseX < this.x + this.width && mouseY >= this.y && mouseY < this.y + this.height); - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - return this.active && super.mouseClicked(mouseX, mouseY, button); - } - - public void setActive(boolean active) { - this.active = active; - } - - @Override - public boolean isActive() { - return this.active; - } -} diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/components/SelectedImageButton.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/components/SelectedImageButton.java deleted file mode 100644 index 5840664..0000000 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/components/SelectedImageButton.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.teamresourceful.resourcefullib.client.components; - -import net.minecraft.resources.ResourceLocation; - -public class SelectedImageButton extends ImageButton { - - private final ResourceLocation texture; - private final int u; - private final int v; - private boolean selected; - - public SelectedImageButton(int x, int y, int u, int v, boolean selected, ResourceLocation texture) { - super(x, y, 20, 20); - this.u = u; - this.v = v; - this.selected = selected; - this.texture = texture; - } - - @Override - public ResourceLocation getTexture(int mouseX, int mouseY) { - return this.texture; - } - - @Override - public int getU(int mouseX, int mouseY) { - return selected ? u + 20 : u; - } - - @Override - public int getV(int mouseX, int mouseY) { - return isHovered ? v + 20 : v; - } - - public void setSelected(boolean selected) { - this.selected = selected; - } - - @Override - public void onPress() { - setSelected(!this.selected); - } -} \ No newline at end of file diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/components/selection/ListEntry.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/components/selection/ListEntry.java deleted file mode 100644 index 878fc88..0000000 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/components/selection/ListEntry.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.teamresourceful.resourcefullib.client.components.selection; - -import com.teamresourceful.resourcefullib.client.scissor.ScissorBoxStack; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.components.events.GuiEventListener; -import org.jetbrains.annotations.NotNull; - -public abstract class ListEntry implements GuiEventListener { - - abstract protected void render(@NotNull GuiGraphics graphics, @NotNull ScissorBoxStack stack, int id, int left, int top, int width, int height, int mouseX, int mouseY, boolean hovered, float partialTick, boolean selected); -} \ No newline at end of file diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/components/selection/SelectionList.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/components/selection/SelectionList.java deleted file mode 100644 index c43b027..0000000 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/components/selection/SelectionList.java +++ /dev/null @@ -1,206 +0,0 @@ -package com.teamresourceful.resourcefullib.client.components.selection; - -import com.teamresourceful.resourcefullib.client.utils.RenderUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.components.Renderable; -import net.minecraft.client.gui.components.events.AbstractContainerEventHandler; -import net.minecraft.client.gui.narration.NarratableEntry; -import net.minecraft.client.gui.narration.NarrationElementOutput; -import net.minecraft.util.Mth; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.lwjgl.glfw.GLFW; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.function.Consumer; - -public class SelectionList extends AbstractContainerEventHandler implements Renderable, NarratableEntry { - - private final List entries = new ArrayList<>(); - private final int x, y, width, height, itemHeight; - private final Consumer<@Nullable T> onSelection; - private final boolean relativeClicks; - - @Nullable - private T selected, hovered; - private double scrollAmount; - - public SelectionList(int x, int y, int width, int height, int itemHeight, Consumer<@Nullable T> onSelection) { - this(x, y, width, height, itemHeight, onSelection, false); - } - - public SelectionList(int x, int y, int width, int height, int itemHeight, Consumer<@Nullable T> onSelection, boolean relativeClicks) { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - this.itemHeight = itemHeight; - this.onSelection = onSelection; - this.relativeClicks = relativeClicks; - } - - @Override - public void render(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) { - this.hovered = this.getEntryAtPosition(mouseX, mouseY); - - try (var scissorStack = RenderUtils.createScissor(Minecraft.getInstance(), graphics, x, y, width, height)) { - for (int i = 0; i < this.entries.size(); i++) { - int scrollY = this.y - (int) this.scrollAmount + i * this.itemHeight; - if (scrollY + this.itemHeight >= this.y && scrollY <= this.y + this.height) { - ListEntry entry = this.entries.get(i); - entry.render(graphics, scissorStack.stack(), i, this.x, scrollY, width, itemHeight, mouseX, mouseY, isHoveredItem(i), partialTicks, isSelectedItem(i)); - } - } - } - } - - @Override - public @NotNull List children() { - return this.entries; - } - - public void addEntry(@NotNull T entry) { - this.entries.add(entry); - } - - public boolean removeEntry(T entry) { - boolean removed = this.entries.remove(entry); - if (removed && entry == this.selected) { - setSelected(null); - } - return removed; - } - - protected boolean isSelectedItem(int index) { - return Objects.equals(this.selected, this.children().get(index)); - } - - protected boolean isHoveredItem(int index) { - return Objects.equals(this.hovered, this.children().get(index)); - } - - @Nullable - protected final T getEntryAtPosition(double mouseX, double mouseY) { - if (!isMouseOver(mouseX, mouseY)) return null; - int index = Mth.floor(this.scrollAmount + (mouseY - this.y)) / this.itemHeight; - return index < 0 || index >= this.children().size() ? null : this.children().get(index); - } - - public void ensureVisible(T entry) { - int i = (int) (this.y - this.scrollAmount + this.children().indexOf(entry) * this.itemHeight); - int j = i - this.y - this.itemHeight; - if (j < 0) this.setScrollAmount(this.scrollAmount + j); - - int k = this.y + this.height - i - this.itemHeight - this.itemHeight; - if (k < 0) this.setScrollAmount(this.scrollAmount - k); - } - - @Override - public boolean isMouseOver(double mouseX, double mouseY) { - return mouseX <= this.x + this.width && mouseX >= this.x && mouseY <= this.y + this.height && mouseY >= this.y; - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - T entry = this.getEntryAtPosition(mouseX, mouseY); - if (entry != null) { - if (relativeClicks) { - int scrollY = this.y - (int) this.scrollAmount + this.children().indexOf(entry) * this.itemHeight; - mouseX -= this.x; - mouseY -= scrollY; - } - if (entry.mouseClicked(mouseX, mouseY, button)) { - this.setFocused(entry); - this.setDragging(true); - } - setSelected(entry); - return true; - } - return false; - } - - @Override - public boolean mouseReleased(double mouseX, double mouseY, int button) { - for (int i = 0; i < this.entries.size(); i++) { - int scrollY = this.y - (int) this.scrollAmount + i * this.itemHeight; - T entry = this.entries.get(i); - if (relativeClicks) { - if (entry.mouseReleased(mouseX - this.x, mouseY - scrollY, button)) { - return true; - } - } else if (entry.mouseReleased(mouseX, mouseY, button)) { - return true; - } - } - return false; - } - - @Override - public boolean mouseScrolled(double mouseX, double mouseY, double horizontalScroll, double verticalScroll) { - this.setScrollAmount(this.scrollAmount - verticalScroll * (double)this.itemHeight / 2.0D); - return true; - } - - @Override - public boolean keyPressed(int key, int point, int mod) { - if (super.keyPressed(key, point, mod)) return true; - if (key == GLFW.GLFW_KEY_UP || key == GLFW.GLFW_KEY_DOWN) { - if (!this.children().isEmpty()) { - int index = this.children().indexOf(this.selected); - - int clampedIndex = Mth.clamp(index + (key == GLFW.GLFW_KEY_UP ? -1 : 1), 0, this.entries.size() - 1); - if (index == clampedIndex) { - return true; - } - - T entry = this.children().get(clampedIndex); - setSelected(entry); - this.ensureVisible(entry); - } - return true; - } - return false; - } - - public void setSelected(@Nullable T entry) { - this.selected = entry; - this.onSelection.accept(this.selected); - } - - protected void setScrollAmount(double amount) { - this.scrollAmount = Mth.clamp(amount, 0.0D, Math.max(0, this.entries.size() * this.itemHeight - height)); - } - - public void updateEntries(List entries) { - this.scrollAmount = 0; - this.selected = null; - this.hovered = null; - this.entries.clear(); - entries.forEach(this::addEntry); - } - - @Override - public @NotNull NarrationPriority narrationPriority() { - return NarrationPriority.NONE; - } - - @Override - public void updateNarration(@NotNull NarrationElementOutput output) { - - } - - public T getSelected() { - return selected; - } - - public T getHovered() { - return hovered; - } - - public double getScrollAmount() { - return scrollAmount; - } -} diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/fluid/data/ClientFluidProperties.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/fluid/data/ClientFluidProperties.java index bc656b3..dcd8eb5 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/fluid/data/ClientFluidProperties.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/client/fluid/data/ClientFluidProperties.java @@ -7,7 +7,10 @@ import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.renderer.*; +import net.minecraft.client.renderer.LightTexture; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.fog.FogData; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.BlockPos; import net.minecraft.resources.ResourceLocation; @@ -66,8 +69,8 @@ default Vector4f modifyFogColor(Camera camera, float partialTick, ClientLevel le return fluidFogColor; } - default FogParameters modifyFogRender(Camera camera, FogRenderer.FogMode mode, float renderDistance, float partialTick, FogParameters parameters) { - return parameters; + default FogData modifyFogRender(Camera camera, float renderDistance, float partialTick, FogData data) { + return data; } static ClientFluidProperties.Builder builder() { diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/highlights/HighlightHandler.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/highlights/HighlightHandler.java index 9156bee..3345f30 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/highlights/HighlightHandler.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/client/highlights/HighlightHandler.java @@ -5,7 +5,6 @@ import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.serialization.Codec; import com.mojang.serialization.JsonOps; -import com.teamresourceful.resourcefullib.client.CloseablePoseStack; import com.teamresourceful.resourcefullib.client.highlights.base.Highlight; import com.teamresourceful.resourcefullib.client.highlights.base.HighlightLine; import com.teamresourceful.resourcefullib.client.highlights.base.Highlightable; @@ -36,7 +35,7 @@ public class HighlightHandler extends SimpleJsonResourceReloadListener HIGHLIGHT_CODEC = ResourceLocation.CODEC.xmap(HighlightHandler::getOrThrow, Highlight::id); public HighlightHandler() { - super(ExtraCodecs.JSON, FileToIdConverter.json("resourcefullib/highlights")); + super(ExtraCodecs.JSON, FileToIdConverter.json("resourcefullib/highlights")); } @Override @@ -90,28 +89,28 @@ public static boolean onBlockHighlight(Vec3 cameraPos, Entity cameraEntity, Pose } if (STATE_CACHE.containsKey(state)) { Vec3 offset = state.getOffset(blockPos); - try (var ignored = new CloseablePoseStack(stack)) { - float x = (float) (blockPos.getX() - cameraPos.x()); - float y = (float) (blockPos.getY() - cameraPos.y()); - float z = (float) (blockPos.getZ() - cameraPos.z()); - x += (float) offset.x(); - y += (float) offset.y(); - z += (float) offset.z(); - - float[] lines = STATE_CACHE.get(state); - if (lines.length % 9 != 0) return false; - - for (int i = 0; i < lines.length; i += 9) { - HighlightLine.render( - stack, consumer, - color, - x, y, z, - lines[i], lines[i + 1], lines[i + 2], - lines[i + 3], lines[i + 4], lines[i + 5], - lines[i + 6], lines[i + 7], lines[i + 8] - ); - } + stack.pushPose(); + float x = (float) (blockPos.getX() - cameraPos.x()); + float y = (float) (blockPos.getY() - cameraPos.y()); + float z = (float) (blockPos.getZ() - cameraPos.z()); + x += (float) offset.x(); + y += (float) offset.y(); + z += (float) offset.z(); + + float[] lines = STATE_CACHE.get(state); + if (lines.length % 9 != 0) return false; + + for (int i = 0; i < lines.length; i += 9) { + HighlightLine.render( + stack, consumer, + color, + x, y, z, + lines[i], lines[i + 1], lines[i + 2], + lines[i + 3], lines[i + 4], lines[i + 5], + lines[i + 6], lines[i + 7], lines[i + 8] + ); } + stack.popPose(); return true; } diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/highlights/base/Highlight.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/highlights/base/Highlight.java index 119932a..b6843dc 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/highlights/base/Highlight.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/client/highlights/base/Highlight.java @@ -4,7 +4,6 @@ import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; -import com.teamresourceful.resourcefullib.client.CloseablePoseStack; import net.minecraft.core.BlockPos; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.phys.Vec3; @@ -32,17 +31,19 @@ public Highlight copy() { return new Highlight(null, this.lines.stream().map(HighlightLine::copy).toList()); } - public void render(VertexConsumer consumer, PoseStack poseStack, Vec3 cameraPos, Vec3 offset, BlockPos blockPos) { - try (var ignored = new CloseablePoseStack(poseStack)) { - float x = (float) (blockPos.getX() - cameraPos.x()); - float y = (float) (blockPos.getY() - cameraPos.y()); - float z = (float) (blockPos.getZ() - cameraPos.z()); - x += (float) offset.x(); - y += (float) offset.y(); - z += (float) offset.z(); - - for (HighlightLine line : lines) line.render(poseStack, consumer, x, y, z); + public void render(VertexConsumer consumer, PoseStack stack, Vec3 cameraPos, Vec3 offset, BlockPos blockPos) { + stack.pushPose(); + float x = (float) (blockPos.getX() - cameraPos.x()); + float y = (float) (blockPos.getY() - cameraPos.y()); + float z = (float) (blockPos.getZ() - cameraPos.z()); + x += (float) offset.x(); + y += (float) offset.y(); + z += (float) offset.z(); + + for (HighlightLine line : lines) { + line.render(stack, consumer, x, y, z); } + stack.popPose(); } } diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/scissor/CloseableScissorStack.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/scissor/CloseableScissorStack.java deleted file mode 100644 index 866c74f..0000000 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/scissor/CloseableScissorStack.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.teamresourceful.resourcefullib.client.scissor; - -public record CloseableScissorStack(ScissorBoxStack stack, int x, int y, int width, int height) implements AutoCloseable { - - public CloseableScissorStack { - stack.push(x, y, width, height); - } - - @Override - public void close() { - stack.pop(); - } -} diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/scissor/ClosingScissorBox.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/scissor/ClosingScissorBox.java deleted file mode 100644 index 54808c9..0000000 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/scissor/ClosingScissorBox.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.teamresourceful.resourcefullib.client.scissor; - -import com.mojang.blaze3d.systems.RenderSystem; - -public record ClosingScissorBox(int x, int y, int width, int height) implements AutoCloseable { - - public ClosingScissorBox { - RenderSystem.enableScissor(x, y, width, height); - } - - @Override - public void close() { - RenderSystem.disableScissor(); - } -} diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/scissor/GuiCloseableScissor.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/scissor/GuiCloseableScissor.java index b95de4e..9cb322c 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/scissor/GuiCloseableScissor.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/client/scissor/GuiCloseableScissor.java @@ -1,7 +1,13 @@ package com.teamresourceful.resourcefullib.client.scissor; import net.minecraft.client.gui.GuiGraphics; +import org.jetbrains.annotations.ApiStatus; +/** + * @deprecated use {@link com.teamresourceful.resourcefullib.client.closables.CloseableScissor} + */ +@Deprecated +@ApiStatus.ScheduledForRemoval(inVersion = ">1.21.6") public record GuiCloseableScissor(GuiGraphics graphics) implements AutoCloseable { public GuiCloseableScissor(GuiGraphics graphics, int x, int y, int width, int height) { diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/scissor/ScissorBox.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/scissor/ScissorBox.java deleted file mode 100644 index 2150ace..0000000 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/scissor/ScissorBox.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.teamresourceful.resourcefullib.client.scissor; - -import com.mojang.blaze3d.systems.RenderSystem; - -@SuppressWarnings("UnusedReturnValue") -public record ScissorBox(int x, int y, int width, int height) { - - public ScissorBox subBox(int x, int y, int width, int height) { - int startY = Math.max(this.y(), y); - int endY = Math.min(this.y() + this.height(), y + height); - int startX = Math.max(this.x(), x); - int endX = Math.min(this.x() + this.width(), x + width); - - startY = Math.min(startY, endY); - startX = Math.min(startX, endX); - - return new ScissorBox(startX, startY, endX - startX, endY - startY); - } - - public ScissorBox start() { - RenderSystem.enableScissor(x, y, width, height); - return this; - } - - public ScissorBox end() { - RenderSystem.disableScissor(); - return this; - } - -} diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/scissor/ScissorBoxStack.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/scissor/ScissorBoxStack.java deleted file mode 100644 index deec900..0000000 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/scissor/ScissorBoxStack.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.teamresourceful.resourcefullib.client.scissor; - -import com.mojang.blaze3d.systems.RenderSystem; - -import java.util.LinkedList; - -public class ScissorBoxStack { - - private final LinkedList stack = new LinkedList<>(); - - public void push(int x, int y, int width, int height) { - ScissorBox box = !stack.isEmpty() ? stack.peek().subBox(x, y, width, height) : new ScissorBox(x, y, width, height); - box.start(); - stack.push(box); - } - - public void pop() { - //Ensure safety - if (stack.isEmpty()) return; - - stack.pop(); - if (stack.isEmpty()) { - RenderSystem.disableScissor(); - } else { - stack.peek().start(); - } - } -} diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/sysinfo/defaults/MinecraftInfo.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/sysinfo/defaults/MinecraftInfo.java index c735dd3..a923dcb 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/sysinfo/defaults/MinecraftInfo.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/client/sysinfo/defaults/MinecraftInfo.java @@ -88,7 +88,7 @@ private static String getPing(Minecraft mc) { public void accept(SystemInfoBuilder builder) { Minecraft mc = Minecraft.getInstance(); - builder.append("Minecraft Version", SharedConstants.getCurrentVersion().getName()); + builder.append("Minecraft Version", SharedConstants.getCurrentVersion().name()); builder.append("Client Brand", ClientBrandRetriever.getClientModName()); builder.append("Language", mc.getLanguageManager().getSelected()); tryAppendingFabric(builder); diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/utils/RenderUtils.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/utils/RenderUtils.java index 5b4d4e4..9cdaf0d 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/utils/RenderUtils.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/client/utils/RenderUtils.java @@ -1,17 +1,16 @@ package com.teamresourceful.resourcefullib.client.utils; import com.mojang.blaze3d.vertex.PoseStack; -import com.teamresourceful.resourcefullib.client.scissor.CloseableScissorStack; -import com.teamresourceful.resourcefullib.client.scissor.ClosingScissorBox; -import com.teamresourceful.resourcefullib.client.scissor.ScissorBoxStack; import com.teamresourceful.resourcefullib.common.exceptions.UtilityClassException; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.renderer.Rect2i; +import org.jetbrains.annotations.ApiStatus; import org.joml.Matrix4f; import org.joml.Vector2i; import org.joml.Vector2ic; +@Deprecated +@ApiStatus.ScheduledForRemoval(inVersion = ">1.21.6") public final class RenderUtils { private RenderUtils() throws UtilityClassException { @@ -36,32 +35,4 @@ public static Vector2ic getTranslation(PoseStack stack) { Matrix4f pose = stack.last().pose(); return new Vector2i((int) pose.m30(), (int) pose.m31()); } - - /** - * Returns a scissor box using the stack's translation and the given bounds. - *
- * You likely want to use {@link #createScissor(Minecraft, GuiGraphics, int, int, int, int)} instead. - */ - public static ClosingScissorBox createScissorBox(Minecraft minecraft, PoseStack stack, int x, int y, int width, int height) { - Rect2i bound = getScissorRect(minecraft, stack, x, y, width, height); - return new ClosingScissorBox(bound.getX(), bound.getY(), bound.getWidth(), bound.getHeight()); - } - - /** - * Returns a scissor box stack using the stack's translation and the given bounds. - *
- * You likely want to use {@link #createScissor(Minecraft, GuiGraphics, int, int, int, int)} instead. - */ - public static CloseableScissorStack createScissorBoxStack(ScissorBoxStack scissorStack, Minecraft minecraft, PoseStack stack, int x, int y, int width, int height) { - Rect2i bound = getScissorRect(minecraft, stack, x, y, width, height); - return new CloseableScissorStack(scissorStack, bound.getX(), bound.getY(), bound.getWidth(), bound.getHeight()); - } - - /** - * Returns a scissor box stack using the stack's translation and the given bounds. - */ - public static CloseableScissorStack createScissor(Minecraft minecraft, GuiGraphics graphics, int x, int y, int width, int height) { - Rect2i bound = getScissorRect(minecraft, graphics.pose(), x, y, width, height); - return new CloseableScissorStack(new ScissorBoxStack(), bound.getX(), bound.getY(), bound.getWidth(), bound.getHeight()); - } } \ No newline at end of file diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/utils/ScreenUtils.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/utils/ScreenUtils.java index 5116142..c22630d 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/utils/ScreenUtils.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/client/utils/ScreenUtils.java @@ -3,15 +3,6 @@ import com.teamresourceful.resourcefullib.common.exceptions.UtilityClassException; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.navigation.ScreenRectangle; -import net.minecraft.client.gui.screens.inventory.tooltip.DefaultTooltipPositioner; -import net.minecraft.network.chat.Component; -import net.minecraft.util.FormattedCharSequence; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.TooltipFlag; - -import java.util.ArrayList; -import java.util.List; public final class ScreenUtils { @@ -19,49 +10,9 @@ private ScreenUtils() throws UtilityClassException { throw new UtilityClassException(); } - public static void setTooltip(ItemStack stack) { - setTooltip(stack, true); - } - - public static void setTooltip(Component component) { - setTooltip(List.of(component), true); - } - - public static void setTooltip(List component) { - setTooltip(component, true); - } - - public static void setTooltip(ItemStack stack, boolean replace) { - Minecraft mc = Minecraft.getInstance(); - Item.TooltipContext context = Item.TooltipContext.of(mc.level); - setTooltip(stack.getTooltipLines( - context, - mc.player, - mc.options.advancedItemTooltips ? TooltipFlag.ADVANCED : TooltipFlag.NORMAL - ), replace); - } - - public static void setTooltip(Component component, boolean replace) { - setTooltip(List.of(component), replace); - } - - public static void setTooltip(List component, boolean replace) { - if (Minecraft.getInstance().screen != null) { - List formattedComponents = new ArrayList<>(component.size()); - for (Component comp : component) { - formattedComponents.add(comp.getVisualOrderText()); - } - Minecraft.getInstance().screen.setTooltipForNextRenderPass(formattedComponents, DefaultTooltipPositioner.INSTANCE, replace); - } - } - - public static void clearTooltip() { - setTooltip(List.of(), true); - } - public static void sendCommand(String command) { if (Minecraft.getInstance().getConnection() != null) { - Minecraft.getInstance().getConnection().sendUnsignedCommand(command); + Minecraft.getInstance().getConnection().sendUnattendedCommand(command, null); } } diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/common/codecs/predicates/NbtPredicate.java b/common/src/main/java/com/teamresourceful/resourcefullib/common/codecs/predicates/NbtPredicate.java index 03ff356..75c0565 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/common/codecs/predicates/NbtPredicate.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/common/codecs/predicates/NbtPredicate.java @@ -4,7 +4,6 @@ import net.minecraft.core.component.DataComponents; import net.minecraft.nbt.*; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.component.CustomData; import org.jetbrains.annotations.Nullable; @@ -24,7 +23,7 @@ public boolean matches(ItemStack stack) { public boolean matches(Entity pEntity) { if (this == ANY || isEmpty(this.tag)) return true; - return this.matches(getEntityTagToCompare(pEntity)); + return this.matches(net.minecraft.advancements.critereon.NbtPredicate.getEntityTagToCompare(pEntity)); } public boolean matches(@Nullable Tag tag) { @@ -89,16 +88,5 @@ public static boolean compareNbt(@Nullable Tag tag, @Nullable Tag tag2) { public static boolean isEmpty(Tag tag) { return tag == null || (tag instanceof CompoundTag compoundTag && compoundTag.isEmpty()) || (tag instanceof ListTag list && list.isEmpty()); } - private static CompoundTag getEntityTagToCompare(Entity entity) { - CompoundTag compoundtag = entity.saveWithoutId(new CompoundTag()); - if (entity instanceof Player player) { - ItemStack itemstack = player.getInventory().getSelectedItem(); - if (!itemstack.isEmpty()) { - compoundtag.put("SelectedItem", itemstack.save(entity.level().registryAccess())); - } - } - - return compoundtag; - } } diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/common/network/Network.java b/common/src/main/java/com/teamresourceful/resourcefullib/common/network/Network.java index c12a756..e0034ef 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/common/network/Network.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/common/network/Network.java @@ -33,19 +33,6 @@ public Network(ResourceLocation channel, int protocolVersion, boolean optional) this.optional = optional; } - @Deprecated - @ApiStatus.ScheduledForRemoval(inVersion = "22.0") - public Network(String modid, int protocolVersion, String channel) { - this(modid, protocolVersion, channel, false); - } - - @Deprecated - @ApiStatus.ScheduledForRemoval(inVersion = "22.0") - public Network(String modid, int protocolVersion, String channel, boolean optional) { - this.networking = getNetwork(ResourceLocation.fromNamespaceAndPath(modid, channel), protocolVersion, optional); - this.optional = optional; - } - @Override public final > void register(ClientboundPacketType type) { this.networking.register(type); diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/common/network/defaults/CodecPacketType.java b/common/src/main/java/com/teamresourceful/resourcefullib/common/network/defaults/CodecPacketType.java index 25b4d57..4defd04 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/common/network/defaults/CodecPacketType.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/common/network/defaults/CodecPacketType.java @@ -9,7 +9,6 @@ import net.minecraft.network.codec.StreamCodec; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; -import org.jetbrains.annotations.ApiStatus; import java.util.function.Consumer; import java.util.function.Function; @@ -23,23 +22,10 @@ public CodecPacketType(ResourceLocation id, StreamCodec clazz, ResourceLocation id, StreamCodec codec) { - super(clazz, id); - this.codec = codec; - } - public CodecPacketType(ResourceLocation id, ByteCodec codec) { this(id, StreamCodecByteCodec.toRegistry(codec)); } - @Deprecated - @ApiStatus.ScheduledForRemoval(inVersion = "22.0") - public CodecPacketType(Class clazz, ResourceLocation id, ByteCodec codec) { - this(clazz, id, StreamCodecByteCodec.toRegistry(codec)); - } - @Override public void encode(T message, RegistryFriendlyByteBuf buffer) { codec.encode(buffer, message); diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/common/network/defaults/DatalessPacketType.java b/common/src/main/java/com/teamresourceful/resourcefullib/common/network/defaults/DatalessPacketType.java index 518520a..ec7a22f 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/common/network/defaults/DatalessPacketType.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/common/network/defaults/DatalessPacketType.java @@ -3,7 +3,6 @@ import com.teamresourceful.resourcefullib.common.network.Packet; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.resources.ResourceLocation; -import org.jetbrains.annotations.ApiStatus; import java.util.function.Supplier; @@ -16,13 +15,6 @@ public DatalessPacketType(ResourceLocation id, Supplier factory) { this.factory = factory; } - @Deprecated - @ApiStatus.ScheduledForRemoval(inVersion = "22.0") - public DatalessPacketType(Class clazz, ResourceLocation id, Supplier factory) { - super(clazz, id); - this.factory = factory; - } - @Override public void encode(T message, RegistryFriendlyByteBuf buffer) { diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/common/registry/ResourcefulRegistryType.java b/common/src/main/java/com/teamresourceful/resourcefullib/common/registry/ResourcefulRegistryType.java index e345c5c..2719f89 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/common/registry/ResourcefulRegistryType.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/common/registry/ResourcefulRegistryType.java @@ -2,11 +2,9 @@ import com.teamresourceful.resourcefullib.common.fluid.data.FluidData; import com.teamresourceful.resourcefullib.common.fluid.registry.ResourcefulFluidRegistry; -import org.jetbrains.annotations.ApiStatus; public final class ResourcefulRegistryType> { - @ApiStatus.Experimental public static final ResourcefulRegistryType FLUID = new ResourcefulRegistryType<>( ResourcefulFluidRegistry.class ); diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/common/utils/EnumBuilder.java b/common/src/main/java/com/teamresourceful/resourcefullib/common/utils/EnumBuilder.java deleted file mode 100644 index f553c3e..0000000 --- a/common/src/main/java/com/teamresourceful/resourcefullib/common/utils/EnumBuilder.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.teamresourceful.resourcefullib.common.utils; - -import org.jetbrains.annotations.ApiStatus; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Array; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.List; -import java.util.function.Predicate; - -/** - * Use mixins and extensible enums to create new enum values at runtime. - */ -@Deprecated -@ApiStatus.Obsolete -@SuppressWarnings({"unchecked", "unused"}) -@ApiStatus.ScheduledForRemoval(inVersion = "1.22") -public class EnumBuilder> { - - private static final Field ENUM_CONSTANTS = UnsafeUtils.getField(Class.class, field -> field.getName().equals("enumConstants")); - private static final Field ENUM_CONSTANT_DIRECTORY = UnsafeUtils.getField(Class.class, field -> field.getName().equals("enumConstantDirectory")); - - private static final Predicate IS_SYNTHETIC = Field::isSynthetic; - private static final Predicate IS_ARRAY = field -> field.getType().isArray(); - private static final Predicate IS_STATIC = field -> Modifier.isStatic(field.getModifiers()); - private static final Predicate NAMED_VALUES = field -> field.getName().contains("VALUES"); - private static final Predicate IS_VALUES_FIELD = IS_SYNTHETIC.and(IS_STATIC).and(IS_ARRAY).and(NAMED_VALUES); - - private final Class enumClass; - private final String id; - private final List args = new ArrayList<>(); - private final List> types = new ArrayList<>(); - - public EnumBuilder(Class enumClass, String id) { - this.enumClass = enumClass; - this.id = id; - } - - public static > EnumBuilder of(Class enumClass, String id) { - return new EnumBuilder<>(enumClass, id); - } - - public EnumBuilder withArg(Class type, Object arg) { - this.args.add(arg); - this.types.add(type); - return this; - } - - @SuppressWarnings("SuspiciousSystemArraycopy") - public T build() throws Throwable { - Class[] argTypes = new Class[types.size() + 2]; - argTypes[0] = String.class; - argTypes[1] = int.class; - System.arraycopy(types.toArray(), 0, argTypes, 2, types.size()); - - Object[] newArgs = new Object[args.size() + 2]; - newArgs[0] = id; - newArgs[1] = enumClass.getEnumConstants().length; - System.arraycopy(args.toArray(), 0, newArgs, 2, args.size()); - - verify(argTypes, newArgs); - - return EnumBuilder.create(enumClass, newArgs, argTypes); - } - - private void verify(Class[] argTypes, Object[] newArgs) { - if (argTypes.length != newArgs.length) { - throw new IllegalArgumentException("Argument types and arguments must be the same length"); - } - } - - //region Unsafe operations for enum creation - - private static > T create(Class enumClass, Object[] args, Class[] types) throws Throwable { - Constructor constructor = enumClass.getDeclaredConstructor(types); - constructor.setAccessible(true); - T output = (T) MethodHandles.lookup() - .unreflectConstructor(constructor) - .invokeWithArguments(args); - - Field valuesField = UnsafeUtils.getField(enumClass, field -> IS_VALUES_FIELD.test(field) && field.getType().getComponentType().equals(enumClass)); - addArrayValue(valuesField, enumClass, output); - UnsafeUtils.setField(enumClass, ENUM_CONSTANT_DIRECTORY, null); - UnsafeUtils.setField(enumClass, ENUM_CONSTANTS, null); - return output; - } - - public static void addArrayValue(Field data, Class object, T arrayEntry) { - Object base = UnsafeUtils.unsafe().staticFieldBase(data); - long offset = UnsafeUtils.unsafe().staticFieldOffset(data); - T[] array = (T[]) UnsafeUtils.unsafe().getObject(base, offset); - T[] newArray = (T[]) Array.newInstance(object, array.length + 1); - System.arraycopy(array, 0, newArray, 0, array.length); - newArray[array.length] = arrayEntry; - UnsafeUtils.unsafe().putObject(base, offset, newArray); - } - - //endregion -} \ No newline at end of file diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/common/utils/GenericMemoryPack.java b/common/src/main/java/com/teamresourceful/resourcefullib/common/utils/GenericMemoryPack.java index 26f62cd..777293a 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/common/utils/GenericMemoryPack.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/common/utils/GenericMemoryPack.java @@ -1,8 +1,6 @@ package com.teamresourceful.resourcefullib.common.utils; import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.mojang.serialization.JsonOps; import com.teamresourceful.resourcefullib.common.lib.Constants; import net.minecraft.network.chat.CommonComponents; import net.minecraft.resources.ResourceLocation; @@ -13,7 +11,6 @@ import net.minecraft.server.packs.metadata.pack.PackMetadataSection; import net.minecraft.server.packs.repository.PackSource; import net.minecraft.server.packs.resources.IoSupplier; -import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -33,12 +30,6 @@ public abstract class GenericMemoryPack implements PackResources { private final String id; private final PackLocationInfo info; - @Deprecated - @ApiStatus.ScheduledForRemoval(inVersion = "1.22") - protected GenericMemoryPack(PackType type, String id, JsonObject meta) { - this(type, id, PackMetadataSection.CODEC.parse(JsonOps.INSTANCE, meta).getOrThrow()); - } - protected GenericMemoryPack(PackType type, String id, PackMetadataSection meta) { this.metaData = meta; this.allowedType = type; diff --git a/fabric/src/main/java/com/teamresourceful/resourcefullib/mixins/fabric/FogRendererMixin.java b/fabric/src/main/java/com/teamresourceful/resourcefullib/mixins/fabric/FogRendererMixin.java index 28a0cd4..67eb6a1 100644 --- a/fabric/src/main/java/com/teamresourceful/resourcefullib/mixins/fabric/FogRendererMixin.java +++ b/fabric/src/main/java/com/teamresourceful/resourcefullib/mixins/fabric/FogRendererMixin.java @@ -1,14 +1,17 @@ package com.teamresourceful.resourcefullib.mixins.fabric; -import com.teamresourceful.resourcefullib.client.fluid.data.ClientFluidProperties; +import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.sugar.ref.LocalRef; import com.teamresourceful.resourcefullib.client.fluid.registry.ResourcefulClientFluidRegistry; import com.teamresourceful.resourcefullib.common.fluid.ResourcefulFlowingFluid; import com.teamresourceful.resourcefullib.common.fluid.data.FluidData; import net.minecraft.client.Camera; +import net.minecraft.client.DeltaTracker; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.renderer.FogParameters; -import net.minecraft.client.renderer.FogRenderer; +import net.minecraft.client.renderer.fog.FogData; +import net.minecraft.client.renderer.fog.FogRenderer; import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.FogType; import org.joml.Vector4f; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -18,35 +21,35 @@ @Mixin(FogRenderer.class) public class FogRendererMixin { - @Inject(method = "setupFog", at = @At("RETURN"), cancellable = true) - private static void setupFog( + @Inject(method = "setupFog", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/fog/FogRenderer;updateBuffer(Ljava/nio/ByteBuffer;ILorg/joml/Vector4f;FFFFFF)V")) + private void setupFog( Camera camera, - FogRenderer.FogMode fogMode, - Vector4f vector4f, - float partialTicks, - boolean ignored, - float renderDistance, - CallbackInfoReturnable cir + int renderDistance, boolean cameraFoggy, DeltaTracker deltaTracker, float darkenWorldAmount, + ClientLevel level, + CallbackInfoReturnable cir, + + @Local LocalRef data ) { - FogParameters parameters = cir.getReturnValue(); - FluidState state = camera.getEntity().level().getFluidState(camera.getBlockPosition()); - double fluidY = camera.getBlockPosition().getY() + state.getHeight(camera.getEntity().level(), camera.getBlockPosition()); + FluidState state = level.getFluidState(camera.getBlockPosition()); + double fluidY = camera.getBlockPosition().getY() + state.getHeight(level, camera.getBlockPosition()); if (camera.getPosition().y >= fluidY) return; if (!(state.getType() instanceof ResourcefulFlowingFluid fluid)) return; - FluidData data = fluid.getData(); - ClientFluidProperties properties = ResourcefulClientFluidRegistry.get(data.id()); + var properties = ResourcefulClientFluidRegistry.get(fluid.getData().id()); if (properties == null) return; - - cir.setReturnValue(properties.modifyFogRender(camera, fogMode, partialTicks, renderDistance, parameters)); + data.set(properties.modifyFogRender( + camera, + renderDistance, + deltaTracker.getGameTimeDeltaPartialTick(false), + data.get() + )); } @Inject(method = "computeFogColor", at = @At("RETURN"), cancellable = true) - private static void setupColor( + private void setupColor( Camera camera, float partialTicks, ClientLevel clientLevel, - int renderDistance, - float darkenWorldAmount, + int renderDistance, float darkenWorldAmount, boolean cameraFoggy, CallbackInfoReturnable cir ) { FluidState state = camera.getEntity().level().getFluidState(camera.getBlockPosition()); @@ -54,7 +57,7 @@ private static void setupColor( if (camera.getPosition().y >= fluidY) return; if (!(state.getType() instanceof ResourcefulFlowingFluid fluid)) return; FluidData data = fluid.getData(); - ClientFluidProperties properties = ResourcefulClientFluidRegistry.get(data.id()); + var properties = ResourcefulClientFluidRegistry.get(data.id()); if (properties == null) return; cir.setReturnValue(properties.modifyFogColor(camera, partialTicks, clientLevel, renderDistance, darkenWorldAmount, cir.getReturnValue())); diff --git a/fabric/src/main/java/com/teamresourceful/resourcefullib/mixins/fabric/ScreenEffectRendererMixin.java b/fabric/src/main/java/com/teamresourceful/resourcefullib/mixins/fabric/ScreenEffectRendererMixin.java index 210c05f..e0ae008 100644 --- a/fabric/src/main/java/com/teamresourceful/resourcefullib/mixins/fabric/ScreenEffectRendererMixin.java +++ b/fabric/src/main/java/com/teamresourceful/resourcefullib/mixins/fabric/ScreenEffectRendererMixin.java @@ -1,5 +1,6 @@ package com.teamresourceful.resourcefullib.mixins.fabric; +import com.llamalad7.mixinextras.sugar.Local; import com.mojang.blaze3d.vertex.PoseStack; import com.teamresourceful.resourcefullib.client.fluid.data.ClientFluidProperties; import com.teamresourceful.resourcefullib.client.fluid.fabric.EntityFluidEyesHook; @@ -10,7 +11,9 @@ import net.minecraft.client.renderer.ScreenEffectRenderer; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -18,14 +21,18 @@ @Mixin(ScreenEffectRenderer.class) public class ScreenEffectRendererMixin { + @Shadow @Final private Minecraft minecraft; + + @Shadow @Final private MultiBufferSource bufferSource; + @Inject(method = "renderScreenEffect", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;isEyeInFluid(Lnet/minecraft/tags/TagKey;)Z", shift = At.Shift.BEFORE)) - private static void rlib_renderScreenEffect(Minecraft minecraft, PoseStack poseStack, MultiBufferSource source, CallbackInfo ci) { - Player player = minecraft.player; + private void rlib_renderScreenEffect(boolean bl, float f, CallbackInfo ci, @Local PoseStack stack) { + Player player = this.minecraft.player; if (player instanceof EntityFluidEyesHook hook && hook.rlib$getEyesFluid() != null && hook.rlib$getEyesFluid().getType() instanceof ResourcefulFlowingFluid fluid) { ResourceLocation id = fluid.getData().id(); ClientFluidProperties properties = ResourcefulClientFluidRegistry.get(id); if (properties != null) { - properties.renderOverlay(minecraft, poseStack, source); + properties.renderOverlay(this.minecraft, stack, this.bufferSource); } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8ca01be..16096d5 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,9 +1,9 @@ [versions] # Minecraft -minecraft = "1.21.5" -fabric-api = "0.119.5" -neoforge = "21.5.0-beta" +minecraft = "1.21.6" +fabric-api = "0.127.0" +neoforge = "21.6.0-beta" # Libraries yabn = "1.0.3" diff --git a/neoforge/src/main/java/com/teamresourceful/resourcefullib/client/fluid/neoforge/ResourcefulClientFluidType.java b/neoforge/src/main/java/com/teamresourceful/resourcefullib/client/fluid/neoforge/ResourcefulClientFluidType.java index 1dc8265..8179ac1 100644 --- a/neoforge/src/main/java/com/teamresourceful/resourcefullib/client/fluid/neoforge/ResourcefulClientFluidType.java +++ b/neoforge/src/main/java/com/teamresourceful/resourcefullib/client/fluid/neoforge/ResourcefulClientFluidType.java @@ -6,9 +6,9 @@ import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.renderer.FogParameters; -import net.minecraft.client.renderer.FogRenderer; import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.fog.FogData; +import net.minecraft.client.renderer.fog.environment.FogEnvironment; import net.minecraft.core.BlockPos; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.BlockAndTintGetter; @@ -102,8 +102,14 @@ public boolean renderFluid(@NotNull FluidState fluidState, @NotNull BlockAndTint } @Override - public @NotNull FogParameters modifyFogRender(@NotNull Camera camera, FogRenderer.@NotNull FogMode mode, float renderDistance, float partialTick, @NotNull FogParameters parameters) { - return properties().modifyFogRender(camera, mode, renderDistance, partialTick, parameters); + public void modifyFogRender(@NotNull Camera camera, @Nullable FogEnvironment environment, float renderDistance, float partialTick, @NotNull FogData data) { + var newData = properties().modifyFogRender(camera, renderDistance, partialTick, data); + data.environmentalStart = newData.environmentalStart; + data.renderDistanceStart = newData.renderDistanceStart; + data.environmentalEnd = newData.environmentalEnd; + data.renderDistanceEnd = newData.renderDistanceEnd; + data.skyEnd = newData.skyEnd; + data.cloudEnd = newData.cloudEnd; } } diff --git a/neoforge/src/main/java/com/teamresourceful/resourcefullib/common/utils/neoforge/HiddenGenericMemoryPack.java b/neoforge/src/main/java/com/teamresourceful/resourcefullib/common/utils/neoforge/HiddenGenericMemoryPack.java index 28d3139..f88112b 100644 --- a/neoforge/src/main/java/com/teamresourceful/resourcefullib/common/utils/neoforge/HiddenGenericMemoryPack.java +++ b/neoforge/src/main/java/com/teamresourceful/resourcefullib/common/utils/neoforge/HiddenGenericMemoryPack.java @@ -8,12 +8,6 @@ public class HiddenGenericMemoryPack extends GenericMemoryPack { - @Deprecated - @ApiStatus.ScheduledForRemoval(inVersion = "1.22") - protected HiddenGenericMemoryPack(PackType type, String id, JsonObject meta) { - super(type, id, meta); - } - protected HiddenGenericMemoryPack(PackType type, String id, PackMetadataSection meta) { super(type, id, meta); } diff --git a/neoforge/src/main/java/com/teamresourceful/resourcefullib/neoforge/NeoForgeResourcePackHandler.java b/neoforge/src/main/java/com/teamresourceful/resourcefullib/neoforge/NeoForgeResourcePackHandler.java index 946d989..7f03b29 100644 --- a/neoforge/src/main/java/com/teamresourceful/resourcefullib/neoforge/NeoForgeResourcePackHandler.java +++ b/neoforge/src/main/java/com/teamresourceful/resourcefullib/neoforge/NeoForgeResourcePackHandler.java @@ -99,7 +99,7 @@ public static void onRegisterPackFinders(AddPackFindersEvent event) { private static Pack.Metadata getInfo(PackLocationInfo locationInfo, Pack.ResourcesSupplier supplier, PackType type, boolean hidden) { if (!hidden) { - Pack.Metadata info = Pack.readPackMetadata(locationInfo, supplier, SharedConstants.getCurrentVersion().getPackVersion(type)); + Pack.Metadata info = Pack.readPackMetadata(locationInfo, supplier, SharedConstants.getCurrentVersion().packVersion(type)); if (info != null) { return info; } diff --git a/version.properties b/version.properties index 4834536..5c123f5 100644 --- a/version.properties +++ b/version.properties @@ -2,6 +2,6 @@ patch=0 buildTime=0 build=0 releaseType=release -currentMCVersion=1.21.5 +currentMCVersion=1.21.6 initialMCVersion=1.19.1 version=3.5.0