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 654815b..a8441e4 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,6 +1,7 @@ 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; @@ -16,21 +17,26 @@ protected BaseCursorScreen(Component component) { @Override public void render(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float f) { - 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(); + 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(); + } } } 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 3104ff0..ddf0f98 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 @@ -2,6 +2,7 @@ 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; @@ -65,4 +66,8 @@ public static void sendClick(int containerId, int buttonId) { Minecraft.getInstance().gameMode.handleInventoryButtonClick(containerId, buttonId); } } + + public static boolean inBounds(ScreenRectangle rectangle, int x, int y) { + return x >= rectangle.left() && x <= rectangle.right() && y >= rectangle.top() && y <= rectangle.bottom(); + } } \ No newline at end of file diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/common/bytecodecs/ExtraByteCodecs.java b/common/src/main/java/com/teamresourceful/resourcefullib/common/bytecodecs/ExtraByteCodecs.java index 487fa35..e0705d8 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/common/bytecodecs/ExtraByteCodecs.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/common/bytecodecs/ExtraByteCodecs.java @@ -3,15 +3,18 @@ import com.teamresourceful.bytecodecs.base.ByteCodec; import com.teamresourceful.bytecodecs.base.object.ObjectByteCodec; import com.teamresourceful.resourcefullib.common.exceptions.UtilityClassException; +import io.netty.buffer.ByteBuf; import net.minecraft.core.*; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.Level; import org.joml.Vector3f; @@ -53,6 +56,10 @@ private ExtraByteCodecs() throws UtilityClassException { public static final ByteCodec ITEM = registry(BuiltInRegistries.ITEM); public static final ByteCodec ITEM_STACK = ItemStackByteCodec.CODEC; + public static final ByteCodec INGREDIENT = ByteCodec.passthrough( + (buf, ingredient) -> ingredient.toNetwork(toFriendly(buf)), + buf -> Ingredient.fromNetwork(toFriendly(buf)) + ); public static > ByteCodec> resourceKey(ResourceKey registry) { @@ -62,4 +69,8 @@ public static > ByteCodec> resourceKey(R public static ByteCodec registry(IdMap map) { return new IdMapByteCodec<>(map); } + + public static FriendlyByteBuf toFriendly(ByteBuf buffer) { + return buffer instanceof FriendlyByteBuf friendlyByteBuf ? friendlyByteBuf : new FriendlyByteBuf(buffer); + } }