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 3345f30..35b9535 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 @@ -19,10 +19,11 @@ import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener; import net.minecraft.util.ExtraCodecs; import net.minecraft.util.profiling.ProfilerFiller; -import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; @@ -79,27 +80,32 @@ protected void apply(@NotNull Map jsons, @NotNull BOX_CACHE.clear(); } - public static boolean onBlockHighlight(Vec3 cameraPos, Entity cameraEntity, PoseStack stack, BlockPos blockPos, BlockState state, VertexConsumer consumer, int color) { + public static @Nullable HighlightRenderState extractState(Level level, BlockPos pos, BlockState state) { if (state.getBlock() instanceof Highlightable highlightable) { - var highlight = highlightable.getHighlight(cameraEntity.level(), blockPos, state); + var highlight = highlightable.getHighlight(level, pos, state); if (highlight != null) { - highlight.render(consumer, stack, cameraPos, state.getOffset(blockPos), blockPos); - return true; + return new HighlightRenderState.Dynamic(highlight, state.getOffset(pos)); } } if (STATE_CACHE.containsKey(state)) { - Vec3 offset = state.getOffset(blockPos); + return new HighlightRenderState.Cached(STATE_CACHE.get(state), state.getOffset(pos)); + } + return null; + } + + public static boolean onBlockHighlight(Vec3 cameraPos, PoseStack stack, BlockPos pos, HighlightRenderState state, VertexConsumer consumer, int color) { + if (state instanceof HighlightRenderState.Dynamic(var highlight, var offset)) { + highlight.render(consumer, stack, cameraPos, offset, pos); + return true; + } else if (state instanceof HighlightRenderState.Cached(var lines, var offset) && lines.length % 9 == 0) { stack.pushPose(); - float x = (float) (blockPos.getX() - cameraPos.x()); - float y = (float) (blockPos.getY() - cameraPos.y()); - float z = (float) (blockPos.getZ() - cameraPos.z()); + float x = (float) (pos.getX() - cameraPos.x()); + float y = (float) (pos.getY() - cameraPos.y()); + float z = (float) (pos.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, diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/highlights/HighlightRenderState.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/highlights/HighlightRenderState.java new file mode 100644 index 0000000..3e4a810 --- /dev/null +++ b/common/src/main/java/com/teamresourceful/resourcefullib/client/highlights/HighlightRenderState.java @@ -0,0 +1,12 @@ +package com.teamresourceful.resourcefullib.client.highlights; + +import com.teamresourceful.resourcefullib.client.highlights.base.Highlight; +import net.minecraft.world.phys.Vec3; + +public sealed interface HighlightRenderState { + + Vec3 offset(); + + record Dynamic(Highlight highlight, Vec3 offset) implements HighlightRenderState {} + record Cached(float[] data, Vec3 offset) implements HighlightRenderState {} +} 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 deleted file mode 100644 index 9cb322c..0000000 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/scissor/GuiCloseableScissor.java +++ /dev/null @@ -1,22 +0,0 @@ -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) { - 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/screens/AbstractContainerCursorScreen.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/screens/AbstractContainerCursorScreen.java index a7ad022..9106529 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/screens/AbstractContainerCursorScreen.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/client/screens/AbstractContainerCursorScreen.java @@ -1,6 +1,5 @@ package com.teamresourceful.resourcefullib.client.screens; -import com.teamresourceful.resourcefullib.client.utils.CursorUtils; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.network.chat.Component; @@ -10,40 +9,15 @@ public abstract class AbstractContainerCursorScreen extends AbstractContainerScreen implements CursorScreen { - private Cursor cursor = Cursor.DEFAULT; - public AbstractContainerCursorScreen(T abstractContainerMenu, Inventory inventory, Component component) { super(abstractContainerMenu, inventory, component); } @Override public void render(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float f) { - setCursor(Cursor.DEFAULT); super.render(graphics, mouseX, mouseY, f); - setCursor(children(), mouseX, mouseY); - - switch (cursor) { - case DEFAULT -> CursorUtils.setDefault(); - case POINTER -> CursorUtils.setPointing(); - case DISABLED -> CursorUtils.setDisabled(); - case TEXT -> CursorUtils.setText(); - case CROSSHAIR -> CursorUtils.setCrosshair(); - case RESIZE_EW -> CursorUtils.setResizeEastWest(); - case RESIZE_NS -> CursorUtils.setResizeNorthSouth(); - case RESIZE_NESW -> CursorUtils.setResizeNorthEastSouthWest(); - case RESIZE_NWSE -> CursorUtils.setResizeNorthWestSouthEast(); - case RESIZE_ALL -> CursorUtils.setResizeAll(); + if (this.getRectangle().containsPoint(mouseX, mouseY)) { + applyCursor(graphics, children(), mouseX, mouseY); } } - - @Override - public void removed() { - super.removed(); - CursorUtils.setDefault(); - } - - @Override - public void setCursor(Cursor cursor) { - this.cursor = cursor; - } } diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/screens/BaseCursorScreen.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/screens/BaseCursorScreen.java index a8441e4..1a4582d 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/screens/BaseCursorScreen.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/client/screens/BaseCursorScreen.java @@ -1,7 +1,5 @@ package com.teamresourceful.resourcefullib.client.screens; -import com.teamresourceful.resourcefullib.client.utils.CursorUtils; -import com.teamresourceful.resourcefullib.client.utils.ScreenUtils; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; @@ -9,49 +7,15 @@ public abstract class BaseCursorScreen extends Screen implements CursorScreen { - private Cursor cursor = Cursor.DEFAULT; - protected BaseCursorScreen(Component component) { super(component); } @Override public void render(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float f) { - boolean wihinBounds = ScreenUtils.inBounds(this.getRectangle(), mouseX, mouseY); - if (!wihinBounds) { - actuallyRender(graphics, mouseX, mouseY, f); - } else { - setCursor(Cursor.DEFAULT); - actuallyRender(graphics, mouseX, mouseY, f); - setCursor(children(), mouseX, mouseY); - - switch (cursor) { - case DEFAULT -> CursorUtils.setDefault(); - case POINTER -> CursorUtils.setPointing(); - case DISABLED -> CursorUtils.setDisabled(); - case TEXT -> CursorUtils.setText(); - case CROSSHAIR -> CursorUtils.setCrosshair(); - case RESIZE_EW -> CursorUtils.setResizeEastWest(); - case RESIZE_NS -> CursorUtils.setResizeNorthSouth(); - case RESIZE_NESW -> CursorUtils.setResizeNorthEastSouthWest(); - case RESIZE_NWSE -> CursorUtils.setResizeNorthWestSouthEast(); - case RESIZE_ALL -> CursorUtils.setResizeAll(); - } + super.render(graphics, mouseX, mouseY, f); + if (this.getRectangle().containsPoint(mouseX, mouseY)) { + applyCursor(graphics, children(), mouseX, mouseY); } } - - public void actuallyRender(@NotNull GuiGraphics graphics, int i, int j, float f) { - super.render(graphics, i, j, f); - } - - @Override - public void removed() { - super.removed(); - CursorUtils.setDefault(); - } - - @Override - public void setCursor(Cursor cursor) { - this.cursor = cursor; - } } diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/screens/CursorScreen.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/screens/CursorScreen.java index cd35801..0e9ef75 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/screens/CursorScreen.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/client/screens/CursorScreen.java @@ -1,6 +1,9 @@ package com.teamresourceful.resourcefullib.client.screens; +import com.mojang.blaze3d.platform.cursor.CursorType; +import com.mojang.blaze3d.platform.cursor.CursorTypes; import com.teamresourceful.resourcefullib.client.components.CursorWidget; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.components.MultiLineEditBox; @@ -10,36 +13,34 @@ public interface CursorScreen { - void setCursor(Cursor cursor); - - - default void setCursor(List listeners, double mouseX, double mouseY) { + default void applyCursor(GuiGraphics graphics, List listeners, double mouseX, double mouseY) { for (GuiEventListener child : listeners) { - boolean hovered = child.isMouseOver(mouseX, mouseY); - if (child instanceof CursorWidget widget && hovered) { - setCursor(widget.getCursor()); - break; - } else if (child instanceof AbstractWidget widget && hovered && widget.visible) { - if (widget.active) { - setCursor(widget instanceof EditBox || widget instanceof MultiLineEditBox ? Cursor.TEXT : Cursor.POINTER); - } else { - setCursor(Cursor.DISABLED); - } + if (child instanceof CursorWidget widget && child.isMouseOver(mouseX, mouseY)) { + widget.getCursor().apply(graphics); break; } } } enum Cursor { - DEFAULT, - POINTER, - DISABLED, - TEXT, - CROSSHAIR, - RESIZE_EW, - RESIZE_NS, - RESIZE_NWSE, - RESIZE_NESW, - RESIZE_ALL + DEFAULT(CursorType.DEFAULT), + POINTER(CursorTypes.POINTING_HAND), + DISABLED(CursorTypes.NOT_ALLOWED), + TEXT(CursorTypes.IBEAM), + CROSSHAIR(CursorTypes.CROSSHAIR), + RESIZE_EW(CursorTypes.RESIZE_EW), + RESIZE_NS(CursorTypes.RESIZE_NS), + RESIZE_ALL(CursorTypes.RESIZE_ALL), + ; + + private final CursorType type; + + Cursor(CursorType type) { + this.type = type; + } + + public void apply(GuiGraphics graphics) { + graphics.requestCursor(this.type); + } } } 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 a923dcb..c31ed73 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 @@ -66,11 +66,15 @@ private static long mean(long[] values) { private static String getPing(Minecraft mc) { var logger = mc.getDebugOverlay().getPingLogger(); + if (logger.size() == 0) { + return "N/A"; + } + long min = Long.MAX_VALUE; long max = Long.MIN_VALUE; long sum = 0L; - for (int i = 0; i < logger.capacity(); i++) { + for (int i = 0; i < logger.size(); i++) { long sample = logger.get(i); min = Math.min(min, sample); max = Math.max(max, sample); @@ -78,7 +82,7 @@ private static String getPing(Minecraft mc) { } return "%.2f avg ms / %d min ms / %d max ms".formatted( - sum / (double) logger.capacity(), + sum / (double) logger.size(), min, max ); diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/utils/CursorUtils.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/utils/CursorUtils.java deleted file mode 100644 index 1ac6ea6..0000000 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/utils/CursorUtils.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.teamresourceful.resourcefullib.client.utils; - - -import com.teamresourceful.resourcefullib.client.screens.CursorScreen; -import com.teamresourceful.resourcefullib.common.exceptions.UtilityClassException; -import net.minecraft.client.Minecraft; -import org.lwjgl.glfw.GLFW; - -public final class CursorUtils { - - private static final long DEFAULT_CURSOR = GLFW.glfwCreateStandardCursor(GLFW.GLFW_ARROW_CURSOR); - private static final long POINTING_CURSOR = GLFW.glfwCreateStandardCursor(GLFW.GLFW_POINTING_HAND_CURSOR); - private static final long DISABLED_CURSOR = GLFW.glfwCreateStandardCursor(GLFW.GLFW_NOT_ALLOWED_CURSOR); - private static final long TEXT_CURSOR = GLFW.glfwCreateStandardCursor(GLFW.GLFW_IBEAM_CURSOR); - private static final long CROSSHAIR_CURSOR = GLFW.glfwCreateStandardCursor(GLFW.GLFW_CROSSHAIR_CURSOR); - private static final long RESIZE_EW_CURSOR = GLFW.glfwCreateStandardCursor(GLFW.GLFW_RESIZE_EW_CURSOR); - private static final long RESIZE_NS_CURSOR = GLFW.glfwCreateStandardCursor(GLFW.GLFW_RESIZE_NS_CURSOR); - private static final long RESIZE_NWSE_CURSOR = GLFW.glfwCreateStandardCursor(GLFW.GLFW_RESIZE_NWSE_CURSOR); - private static final long RESIZE_NESW_CURSOR = GLFW.glfwCreateStandardCursor(GLFW.GLFW_RESIZE_NESW_CURSOR); - private static final long RESIZE_ALL_CURSOR = GLFW.glfwCreateStandardCursor(GLFW.GLFW_RESIZE_ALL_CURSOR); - - private CursorUtils() throws UtilityClassException { - throw new UtilityClassException(); - } - - public static void setDefault() { - GLFW.glfwSetCursor(Minecraft.getInstance().getWindow().getWindow(), CursorUtils.DEFAULT_CURSOR); - } - - public static void setPointing() { - GLFW.glfwSetCursor(Minecraft.getInstance().getWindow().getWindow(), CursorUtils.POINTING_CURSOR); - } - - public static void setDisabled() { - GLFW.glfwSetCursor(Minecraft.getInstance().getWindow().getWindow(), CursorUtils.DISABLED_CURSOR); - } - - public static void setText() { - GLFW.glfwSetCursor(Minecraft.getInstance().getWindow().getWindow(), CursorUtils.TEXT_CURSOR); - } - - public static void setCrosshair() { - GLFW.glfwSetCursor(Minecraft.getInstance().getWindow().getWindow(), CursorUtils.CROSSHAIR_CURSOR); - } - - public static void setResizeEastWest() { - GLFW.glfwSetCursor(Minecraft.getInstance().getWindow().getWindow(), CursorUtils.RESIZE_EW_CURSOR); - } - - public static void setResizeNorthSouth() { - GLFW.glfwSetCursor(Minecraft.getInstance().getWindow().getWindow(), CursorUtils.RESIZE_NS_CURSOR); - } - - public static void setResizeNorthWestSouthEast() { - GLFW.glfwSetCursor(Minecraft.getInstance().getWindow().getWindow(), CursorUtils.RESIZE_NWSE_CURSOR); - } - - public static void setResizeNorthEastSouthWest() { - GLFW.glfwSetCursor(Minecraft.getInstance().getWindow().getWindow(), CursorUtils.RESIZE_NESW_CURSOR); - } - - public static void setResizeAll() { - GLFW.glfwSetCursor(Minecraft.getInstance().getWindow().getWindow(), CursorUtils.RESIZE_ALL_CURSOR); - } - - public static void setCursor(boolean state, CursorScreen.Cursor cursor) { - if (Minecraft.getInstance().screen instanceof CursorScreen cursorScreen && state) { - cursorScreen.setCursor(cursor); - } - } - -} 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 deleted file mode 100644 index 9cdaf0d..0000000 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/utils/RenderUtils.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.teamresourceful.resourcefullib.client.utils; - -import com.mojang.blaze3d.vertex.PoseStack; -import com.teamresourceful.resourcefullib.common.exceptions.UtilityClassException; -import net.minecraft.client.Minecraft; -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 { - throw new UtilityClassException(); - } - - /** - * Get the current bounds for a GL scissor. - */ - public static Rect2i getScissorRect(Minecraft minecraft, PoseStack stack, int x, int y, int width, int height) { - float guiScale = (float) minecraft.getWindow().getGuiScale(); - Vector2ic translation = getTranslation(stack); - float translationX = translation.x() * guiScale; - float translationY = translation.y() * guiScale; - return new Rect2i((int) (translationX + x * guiScale), (int) (Minecraft.getInstance().getWindow().getHeight() - y * guiScale - translationY - height * guiScale), (int) (width * guiScale), (int) (height * guiScale)); - } - - /** - * @return returns the point of the current translation of the stack. - */ - public static Vector2ic getTranslation(PoseStack stack) { - Matrix4f pose = stack.last().pose(); - return new Vector2i((int) pose.m30(), (int) pose.m31()); - } -} \ 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 c22630d..0f87798 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,6 +3,7 @@ import com.teamresourceful.resourcefullib.common.exceptions.UtilityClassException; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.navigation.ScreenRectangle; +import org.jetbrains.annotations.ApiStatus; public final class ScreenUtils { @@ -22,6 +23,11 @@ public static void sendClick(int containerId, int buttonId) { } } + /** + * @deprecated use {@link ScreenRectangle#containsPoint(int, int)} instead + */ + @Deprecated + @ApiStatus.ScheduledForRemoval(inVersion = ">1.21.9") public static boolean inBounds(ScreenRectangle rectangle, int x, int y) { return x >= rectangle.left() && x <= rectangle.right() && y >= rectangle.top() && y <= rectangle.bottom(); } 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 75c0565..7242bae 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 @@ -17,8 +17,7 @@ public record NbtPredicate(CompoundTag tag) { public boolean matches(ItemStack stack) { if (this == ANY || isEmpty(this.tag)) return true; - //noinspection deprecation - return this.matches(stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY).getUnsafe()); + return this.matches(stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY).copyTag()); } public boolean matches(Entity pEntity) { diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/common/fluid/package-info.java b/common/src/main/java/com/teamresourceful/resourcefullib/common/fluid/package-info.java deleted file mode 100644 index 6c58db2..0000000 --- a/common/src/main/java/com/teamresourceful/resourcefullib/common/fluid/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/* - * This package is experimental because it has not been tested enough to be considered stable. - */ - -@ApiStatus.Experimental -package com.teamresourceful.resourcefullib.common.fluid; - -import org.jetbrains.annotations.ApiStatus; \ 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 777293a..595c204 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 @@ -83,7 +83,7 @@ public void listResources(@NotNull PackType type, @NotNull String namespace, @No @Override public @Nullable T getMetadataSection(MetadataSectionType type) { - if (type.equals(PackMetadataSection.TYPE)) { + if (type.equals(PackMetadataSection.forPackType(this.allowedType))) { return (T) this.metaData; } return null; diff --git a/fabric/src/main/java/com/teamresourceful/resourcefullib/client/fabric/BlockOutlineRenderStateExtension.java b/fabric/src/main/java/com/teamresourceful/resourcefullib/client/fabric/BlockOutlineRenderStateExtension.java new file mode 100644 index 0000000..16e7e63 --- /dev/null +++ b/fabric/src/main/java/com/teamresourceful/resourcefullib/client/fabric/BlockOutlineRenderStateExtension.java @@ -0,0 +1,11 @@ +package com.teamresourceful.resourcefullib.client.fabric; + +import com.teamresourceful.resourcefullib.client.highlights.HighlightRenderState; +import org.jetbrains.annotations.Nullable; + +public interface BlockOutlineRenderStateExtension { + + @Nullable HighlightRenderState resourcefullib$getHighlight(); + + void resourcefullib$setHighlight(@Nullable HighlightRenderState state); +} diff --git a/fabric/src/main/java/com/teamresourceful/resourcefullib/fabric/FabricResourcePackHandler.java b/fabric/src/main/java/com/teamresourceful/resourcefullib/fabric/FabricResourcePackHandler.java index f7e4a9f..f8ca861 100644 --- a/fabric/src/main/java/com/teamresourceful/resourcefullib/fabric/FabricResourcePackHandler.java +++ b/fabric/src/main/java/com/teamresourceful/resourcefullib/fabric/FabricResourcePackHandler.java @@ -22,8 +22,8 @@ public static void load() { if (metadata.containsCustomValue(RESOURCE_PACK_KEY)) { try { initMod(mod, metadata); - }catch (Exception e) { - Constants.LOGGER.error("Resourceful Lib failed to load resource pack for mod: " + metadata.getName(), e); + } catch (Exception e) { + Constants.LOGGER.error("Resourceful Lib failed to load resource pack for mod: {}", metadata.getName(), e); } } } diff --git a/fabric/src/main/java/com/teamresourceful/resourcefullib/mixins/fabric/BlockOutlineRenderStateMixin.java b/fabric/src/main/java/com/teamresourceful/resourcefullib/mixins/fabric/BlockOutlineRenderStateMixin.java new file mode 100644 index 0000000..af5b4d6 --- /dev/null +++ b/fabric/src/main/java/com/teamresourceful/resourcefullib/mixins/fabric/BlockOutlineRenderStateMixin.java @@ -0,0 +1,26 @@ +package com.teamresourceful.resourcefullib.mixins.fabric; + +import com.teamresourceful.resourcefullib.client.fabric.BlockOutlineRenderStateExtension; +import com.teamresourceful.resourcefullib.client.highlights.HighlightRenderState; +import net.minecraft.client.renderer.state.BlockOutlineRenderState; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; + +@Mixin(BlockOutlineRenderState.class) +public class BlockOutlineRenderStateMixin implements BlockOutlineRenderStateExtension { + + @Unique + @Nullable + private HighlightRenderState resourcefullib$highlight = null; + + @Override + public @Nullable HighlightRenderState resourcefullib$getHighlight() { + return this.resourcefullib$highlight; + } + + @Override + public void resourcefullib$setHighlight(@Nullable HighlightRenderState highlight) { + this.resourcefullib$highlight = highlight; + } +} diff --git a/fabric/src/main/java/com/teamresourceful/resourcefullib/mixins/fabric/DedicatedServerMixin.java b/fabric/src/main/java/com/teamresourceful/resourcefullib/mixins/fabric/DedicatedServerMixin.java index 0013eb2..caa26ac 100644 --- a/fabric/src/main/java/com/teamresourceful/resourcefullib/mixins/fabric/DedicatedServerMixin.java +++ b/fabric/src/main/java/com/teamresourceful/resourcefullib/mixins/fabric/DedicatedServerMixin.java @@ -6,7 +6,7 @@ import net.minecraft.server.Services; import net.minecraft.server.WorldStem; import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.server.level.progress.ChunkProgressListenerFactory; +import net.minecraft.server.level.progress.LevelLoadListener; import net.minecraft.server.packs.repository.PackRepository; import net.minecraft.world.level.storage.LevelStorageSource; import org.spongepowered.asm.mixin.Mixin; @@ -19,14 +19,14 @@ @Mixin(DedicatedServer.class) public abstract class DedicatedServerMixin extends MinecraftServer { - public DedicatedServerMixin(Thread thread, LevelStorageSource.LevelStorageAccess levelStorageAccess, PackRepository packRepository, WorldStem worldStem, Proxy proxy, DataFixer dataFixer, Services services, ChunkProgressListenerFactory chunkProgressListenerFactory) { - super(thread, levelStorageAccess, packRepository, worldStem, proxy, dataFixer, services, chunkProgressListenerFactory); + public DedicatedServerMixin(Thread thread, LevelStorageSource.LevelStorageAccess levelStorageAccess, PackRepository packRepository, WorldStem worldStem, Proxy proxy, DataFixer dataFixer, Services services, LevelLoadListener levelLoadListener) { + super(thread, levelStorageAccess, packRepository, worldStem, proxy, dataFixer, services, levelLoadListener); } @Inject(method = "initServer", at = @At( value = "INVOKE", - target = "Lnet/minecraft/server/players/GameProfileCache;setUsesAuthentication(Z)V", + target = "Lnet/minecraft/server/players/UserNameToIdResolver;resolveOfflineUsers(Z)V", shift = At.Shift.AFTER ) ) diff --git a/fabric/src/main/java/com/teamresourceful/resourcefullib/mixins/fabric/LevelRendererMixin.java b/fabric/src/main/java/com/teamresourceful/resourcefullib/mixins/fabric/LevelRendererMixin.java new file mode 100644 index 0000000..72280c3 --- /dev/null +++ b/fabric/src/main/java/com/teamresourceful/resourcefullib/mixins/fabric/LevelRendererMixin.java @@ -0,0 +1,56 @@ +package com.teamresourceful.resourcefullib.mixins.fabric; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import com.teamresourceful.resourcefullib.client.fabric.BlockOutlineRenderStateExtension; +import com.teamresourceful.resourcefullib.client.highlights.HighlightHandler; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.client.renderer.state.BlockOutlineRenderState; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.Nullable; +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; + +@Mixin(LevelRenderer.class) +public class LevelRendererMixin { + + @Shadow + private @Nullable ClientLevel level; + + @WrapOperation( + method = "extractBlockOutline", + at = @At( + value = "NEW", + target = "(Lnet/minecraft/core/BlockPos;ZZLnet/minecraft/world/phys/shapes/VoxelShape;)Lnet/minecraft/client/renderer/state/BlockOutlineRenderState;" + ) + ) + private BlockOutlineRenderState resourcefullib$extractBlockOutline(BlockPos pos, boolean b1, boolean b2, VoxelShape shape, Operation original, @Local(ordinal = 0) BlockState state) { + var renderState = original.call(pos, b1, b2, shape); + //noinspection ConstantValue + if ((Object) renderState instanceof BlockOutlineRenderStateExtension extension) { + extension.resourcefullib$setHighlight(HighlightHandler.extractState(this.level, pos, state)); + } + return null; + } + + @Inject(method = "renderHitOutline", at = @At("HEAD"), cancellable = true) + public void onRenderHitOutline(PoseStack poseStack, VertexConsumer vertexConsumer, double d, double e, double f, BlockOutlineRenderState state, int i, CallbackInfo ci) { + //noinspection ConstantValue + if ((Object) state instanceof BlockOutlineRenderStateExtension extension) { + var highlight = extension.resourcefullib$getHighlight(); + if (highlight != null && HighlightHandler.onBlockHighlight(new Vec3(d, e, f), poseStack, state.pos(), highlight, vertexConsumer, i)) { + ci.cancel(); + } + } + } +} diff --git a/fabric/src/main/java/com/teamresourceful/resourcefullib/mixins/fabric/MixinLevelRenderer.java b/fabric/src/main/java/com/teamresourceful/resourcefullib/mixins/fabric/MixinLevelRenderer.java deleted file mode 100644 index 7d36a51..0000000 --- a/fabric/src/main/java/com/teamresourceful/resourcefullib/mixins/fabric/MixinLevelRenderer.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.teamresourceful.resourcefullib.mixins.fabric; - -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.vertex.VertexConsumer; -import com.teamresourceful.resourcefullib.client.highlights.HighlightHandler; -import net.minecraft.client.renderer.LevelRenderer; -import net.minecraft.core.BlockPos; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.Vec3; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(LevelRenderer.class) -public class MixinLevelRenderer { - - @Inject(method = "renderHitOutline", at = @At("HEAD"), cancellable = true) - public void onRenderHitOutline(PoseStack poseStack, VertexConsumer vertexConsumer, Entity entity, double d, double e, double f, BlockPos blockPos, BlockState blockState, int i, CallbackInfo ci) { - if (HighlightHandler.onBlockHighlight(new Vec3(d, e, f), entity, poseStack, blockPos, blockState, vertexConsumer, i)) { - ci.cancel(); - } - } -} 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 e0ae008..bba599a 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 @@ -9,6 +9,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.ScreenEffectRenderer; +import net.minecraft.client.renderer.SubmitNodeCollector; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; import org.spongepowered.asm.mixin.Final; @@ -26,7 +27,7 @@ public class ScreenEffectRendererMixin { @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 void rlib_renderScreenEffect(boolean bl, float f, CallbackInfo ci, @Local PoseStack stack) { + private void rlib_renderScreenEffect(boolean bl, float f, SubmitNodeCollector submitNodeCollector, 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(); diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 44dd12a..a7ee5bb 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -31,7 +31,7 @@ "environment": "*", "depends": { "fabric-api": "*", - "minecraft": ">=1.21.5" + "minecraft": ">=1.21.9" }, "custom": { "modmenu": { diff --git a/fabric/src/main/resources/resourcefullib.mixins.json b/fabric/src/main/resources/resourcefullib.mixins.json index d92bfdb..98bd648 100644 --- a/fabric/src/main/resources/resourcefullib.mixins.json +++ b/fabric/src/main/resources/resourcefullib.mixins.json @@ -6,6 +6,15 @@ "injectors": { "defaultRequire": 1 }, - "client": [ "FogRendererMixin", "MixinLevelRenderer", "ScreenEffectRendererMixin" ], - "mixins": [ "DedicatedServerMixin", "EntityMixin", "MinecraftServerMixin" ] + "client": [ + "FogRendererMixin", + "LevelRendererMixin", + "ScreenEffectRendererMixin" + ], + "mixins": [ + "BlockOutlineRenderStateMixin", + "DedicatedServerMixin", + "EntityMixin", + "MinecraftServerMixin" + ] } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 16096d5..de6b94d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,16 +1,16 @@ [versions] # Minecraft -minecraft = "1.21.6" -fabric-api = "0.127.0" -neoforge = "21.6.0-beta" +minecraft = "1.21.9" +fabric-api = "0.133.14" +neoforge = "21.9.0-beta" # Libraries yabn = "1.0.3" bytecodecs = "1.1.3" # Plugins -resourceful-loom = "1.0.4" +resourceful-loom = "1.0.6" [libraries] diff --git a/neoforge/src/main/java/com/teamresourceful/resourcefullib/common/network/neoforge/NeoForgeNetworking.java b/neoforge/src/main/java/com/teamresourceful/resourcefullib/common/network/neoforge/NeoForgeNetworking.java index 064203c..7ba7868 100644 --- a/neoforge/src/main/java/com/teamresourceful/resourcefullib/common/network/neoforge/NeoForgeNetworking.java +++ b/neoforge/src/main/java/com/teamresourceful/resourcefullib/common/network/neoforge/NeoForgeNetworking.java @@ -8,6 +8,8 @@ import com.teamresourceful.resourcefullib.common.network.internal.NetworkPacketPayload; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; +import net.neoforged.fml.loading.FMLLoader; +import net.neoforged.neoforge.client.network.ClientPacketDistributor; import net.neoforged.neoforge.network.PacketDistributor; import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; import net.neoforged.neoforge.network.registration.PayloadRegistrar; @@ -19,6 +21,7 @@ public class NeoForgeNetworking implements Networking { + private static final boolean IS_CLIENT = FMLLoader.getCurrent().getDist().isClient(); private static final List> LISTENERS = Collections.synchronizedList(new ArrayList<>()); private final List> clientPackets = new ArrayList<>(); @@ -48,7 +51,8 @@ public > void register(ServerboundPacketType type) { @Override public > void sendToServer(T message) { - PacketDistributor.sendToServer(new NetworkPacketPayload<>(message, this.channel)); + if (!IS_CLIENT) return; + ClientPacketDistributor.sendToServer(new NetworkPacketPayload<>(message, this.channel)); } @Override diff --git a/neoforge/src/main/java/com/teamresourceful/resourcefullib/common/utils/modinfo/neoforge/ModInfoUtilsImpl.java b/neoforge/src/main/java/com/teamresourceful/resourcefullib/common/utils/modinfo/neoforge/ModInfoUtilsImpl.java index c069644..8903046 100644 --- a/neoforge/src/main/java/com/teamresourceful/resourcefullib/common/utils/modinfo/neoforge/ModInfoUtilsImpl.java +++ b/neoforge/src/main/java/com/teamresourceful/resourcefullib/common/utils/modinfo/neoforge/ModInfoUtilsImpl.java @@ -2,7 +2,7 @@ import com.teamresourceful.resourcefullib.common.utils.modinfo.ModInfo; import net.neoforged.fml.ModList; -import net.neoforged.fml.loading.LoadingModList; +import net.neoforged.fml.loading.FMLLoader; import org.jetbrains.annotations.Nullable; public class ModInfoUtilsImpl { @@ -12,7 +12,7 @@ public static boolean isModLoaded(String id) { } public static boolean isMixinModLoaded(String id) { - return LoadingModList.get().getModFileById(id) != null; + return FMLLoader.getCurrent().getLoadingModList().getModFileById(id) != null; } @Nullable 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 7f03b29..bf48d5a 100644 --- a/neoforge/src/main/java/com/teamresourceful/resourcefullib/neoforge/NeoForgeResourcePackHandler.java +++ b/neoforge/src/main/java/com/teamresourceful/resourcefullib/neoforge/NeoForgeResourcePackHandler.java @@ -71,7 +71,9 @@ public static void onRegisterPackFinders(AddPackFindersEvent event) { for (ResourcePack resourcePack : RESOURCE_PACKS) { try { Path path = resourcePack.mod().getOwningFile() - .getFile().findResource("resourcepacks/" + resourcePack.name()); + .getFile() + .getFilePath() + .resolve("resourcepacks/" + resourcePack.name()); if (!Files.isDirectory(path.resolve(event.getPackType().getDirectory()))) continue; @@ -92,14 +94,14 @@ public static void onRegisterPackFinders(AddPackFindersEvent event) { event.addRepositorySource((source) -> source.accept(pack)); } catch (Exception ignored) { - Constants.LOGGER.error("Resourceful Lib failed to init resource pack for mod: " + resourcePack.mod().getDisplayName()); + Constants.LOGGER.error("Resourceful Lib failed to init resource pack for mod: {}", resourcePack.mod().getDisplayName()); } } } 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().packVersion(type)); + Pack.Metadata info = Pack.readPackMetadata(locationInfo, supplier, SharedConstants.getCurrentVersion().packVersion(type), type); if (info != null) { return info; } diff --git a/neoforge/src/main/java/com/teamresourceful/resourcefullib/neoforge/ResourcefulLibNeoForge.java b/neoforge/src/main/java/com/teamresourceful/resourcefullib/neoforge/ResourcefulLibNeoForge.java index 0ea1cb6..6f25d04 100644 --- a/neoforge/src/main/java/com/teamresourceful/resourcefullib/neoforge/ResourcefulLibNeoForge.java +++ b/neoforge/src/main/java/com/teamresourceful/resourcefullib/neoforge/ResourcefulLibNeoForge.java @@ -13,7 +13,7 @@ public class ResourcefulLibNeoForge { public ResourcefulLibNeoForge(IEventBus bus) { ResourcefulLib.init(); - if (FMLLoader.getDist().isClient()) { + if (FMLLoader.getCurrent().getDist().isClient()) { ResourcefulLibNeoForgeClient.init(bus); ApiProxy.setInstance(NeoForgeClientApiProxy.INSTANCE); } else { diff --git a/neoforge/src/main/java/com/teamresourceful/resourcefullib/neoforge/ResourcefulLibNeoForgeClient.java b/neoforge/src/main/java/com/teamresourceful/resourcefullib/neoforge/ResourcefulLibNeoForgeClient.java index 016666d..4a6dc3a 100644 --- a/neoforge/src/main/java/com/teamresourceful/resourcefullib/neoforge/ResourcefulLibNeoForgeClient.java +++ b/neoforge/src/main/java/com/teamresourceful/resourcefullib/neoforge/ResourcefulLibNeoForgeClient.java @@ -12,11 +12,10 @@ import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.ARGB; -import net.minecraft.world.level.block.state.BlockState; import net.neoforged.bus.api.IEventBus; import net.neoforged.neoforge.client.event.AddClientReloadListenersEvent; +import net.neoforged.neoforge.client.event.ExtractBlockOutlineRenderStateEvent; import net.neoforged.neoforge.client.event.RegisterClientCommandsEvent; -import net.neoforged.neoforge.client.event.RenderHighlightEvent; import net.neoforged.neoforge.client.extensions.common.RegisterClientExtensionsEvent; import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.registries.NeoForgeRegistries; @@ -36,17 +35,19 @@ public static void onClientReloadListeners(AddClientReloadListenersEvent event) event.addListener(ResourceLocation.fromNamespaceAndPath(ResourcefulLib.MOD_ID, "highlights"), new HighlightHandler()); } - public static void onHighlight(RenderHighlightEvent.Block event) { - BlockState state = event.getCamera().getEntity().level().getBlockState(event.getTarget().getBlockPos()); - int color = Minecraft.getInstance().options.highContrastBlockOutline().get() ? 0xff57ffe1 : ARGB.color(102, 0xff000000); - event.setCanceled(HighlightHandler.onBlockHighlight( + public static void onHighlight(ExtractBlockOutlineRenderStateEvent event) { + final var pos = event.getBlockPos(); + final var state = HighlightHandler.extractState(event.getLevel(), pos, event.getBlockState()); + + if (state == null) return; + + event.addCustomRenderer((outlineState, buffer, stack, pass, levelState) -> HighlightHandler.onBlockHighlight( event.getCamera().getPosition(), - event.getCamera().getEntity(), - event.getPoseStack(), - event.getTarget().getBlockPos(), + stack, + pos, state, - event.getMultiBufferSource().getBuffer(RenderType.lines()), - color + buffer.getBuffer(RenderType.lines()), + outlineState.highContrast() ? 0xff57ffe1 : ARGB.color(102, 0xff000000) )); } diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml index 6570426..e74b285 100644 --- a/neoforge/src/main/resources/META-INF/neoforge.mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -16,13 +16,13 @@ issueTrackerURL="https://github.com/Team-Resourceful/ResourcefulLib/issues/new/c [[dependencies.resourcefullib]] modId = "neoforge" type = "required" - versionRange = "[21.5.0-beta,)" + versionRange = "[21.9.0-beta,)" ordering = "NONE" side = "BOTH" [[dependencies.resourcefullib]] modId = "minecraft" type = "required" - versionRange = "[1.21.5,)" + versionRange = "[1.21.9,)" ordering = "NONE" side = "BOTH" diff --git a/settings.gradle.kts b/settings.gradle.kts index 3944682..4f2916a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -4,7 +4,6 @@ rootProject.name = "ResourcefulLib" pluginManagement { repositories { - maven("https://maven.teamresourceful.com/repository/maven-private/") // TODO remove when arch stops breaking 1.21.5 maven("https://maven.fabricmc.net/") maven("https://maven.architectury.dev/") maven("https://maven.teamresourceful.com/repository/maven-public/") diff --git a/version.properties b/version.properties index a46b185..02d1405 100644 --- a/version.properties +++ b/version.properties @@ -2,6 +2,6 @@ patch=0 buildTime=0 build=0 releaseType=release -currentMCVersion=1.21.6 +currentMCVersion=1.21.9 initialMCVersion=1.19.1 version=3.6.0