diff --git a/build.gradle b/build.gradle index 8bd9e19..f2aef11 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { id 'eclipse' id 'idea' id 'maven-publish' - id 'net.neoforged.gradle.userdev' version '7.0.97' + id 'net.neoforged.gradle.userdev' version '7.0.109' } version = mod_version @@ -17,8 +17,8 @@ base { archivesName = mod_id } -// Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. -java.toolchain.languageVersion = JavaLanguageVersion.of(17) +// Mojang ships Java 21 to end users starting in 1.20.5, so mods should target Java 21. +java.toolchain.languageVersion = JavaLanguageVersion.of(21) //minecraft.accessTransformers.file rootProject.file('src/main/resources/META-INF/accesstransformer.cfg') //minecraft.accessTransformers.entry public net.minecraft.client.Minecraft textureManager # textureManager @@ -132,7 +132,7 @@ tasks.withType(ProcessResources).configureEach { ] inputs.properties replaceProperties - filesMatching(['META-INF/mods.toml']) { + filesMatching(['META-INF/neoforge.mods.toml']) { expand replaceProperties } } diff --git a/gradle.properties b/gradle.properties index 08f6140..939b778 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,20 +5,20 @@ org.gradle.debug=false #read more on this at https://github.com/neoforged/NeoGradle/blob/NG_7.0/README.md#apply-parchment-mappings # you can also find the latest versions at: https://parchmentmc.org/docs/getting-started -neogradle.subsystems.parchment.minecraftVersion=1.20.3 -neogradle.subsystems.parchment.mappingsVersion=2023.12.31 +neogradle.subsystems.parchment.minecraftVersion=1.20.4 +neogradle.subsystems.parchment.mappingsVersion=2024.04.14 # Environment Properties # You can find the latest versions here: https://projects.neoforged.net/neoforged/neoforge # The Minecraft version must agree with the Neo version to get a valid artifact -minecraft_version=1.20.4 +minecraft_version=1.20.5 # The Minecraft version range can use any release version of Minecraft as bounds. # Snapshots, pre-releases, and release candidates are not guaranteed to sort properly # as they do not follow standard versioning conventions. -minecraft_version_range=[1.20.4,1.21) +minecraft_version_range=[1.20.5,1.21) # The Neo version must agree with the Minecraft version to get a valid artifact -neo_version=20.4.147-beta +neo_version=20.5.17-beta # The Neo version range can use any version of Neo as bounds -neo_version_range=[20.4,) +neo_version_range=[20.5,) # The loader version range can only use the major version of FML as bounds loader_version_range=[2,) @@ -32,7 +32,7 @@ mod_name=Nature's Compass # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=CC BY-NC-SA 4.0 # The mod version. See https://semver.org/ -mod_version=1.20.4-3.0.0-neoforge +mod_version=1.20.5-3.0.1-neoforge # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a80b22c..b82aa23 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/java/com/chaosthedude/naturescompass/NaturesCompass.java b/src/main/java/com/chaosthedude/naturescompass/NaturesCompass.java index cd094b0..567000a 100644 --- a/src/main/java/com/chaosthedude/naturescompass/NaturesCompass.java +++ b/src/main/java/com/chaosthedude/naturescompass/NaturesCompass.java @@ -13,7 +13,10 @@ import com.chaosthedude.naturescompass.network.TeleportPacket; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; +import com.mojang.serialization.Codec; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.CreativeModeTabs; import net.minecraft.world.item.ItemStack; @@ -26,8 +29,8 @@ import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent; -import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent; -import net.neoforged.neoforge.network.registration.IPayloadRegistrar; +import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; +import net.neoforged.neoforge.network.registration.PayloadRegistrar; import net.neoforged.neoforge.server.permission.events.PermissionGatherEvent; import net.neoforged.neoforge.server.permission.nodes.PermissionNode; import net.neoforged.neoforge.server.permission.nodes.PermissionTypes; @@ -43,6 +46,14 @@ public class NaturesCompass { public static NaturesCompassItem naturesCompass; + public static final DataComponentType BIOME_ID = DataComponentType.builder().persistent(Codec.STRING).networkSynchronized(ByteBufCodecs.STRING_UTF8).build(); + public static final DataComponentType COMPASS_STATE = DataComponentType.builder().persistent(Codec.INT).networkSynchronized(ByteBufCodecs.VAR_INT).build(); + public static final DataComponentType FOUND_X = DataComponentType.builder().persistent(Codec.INT).networkSynchronized(ByteBufCodecs.VAR_INT).build(); + public static final DataComponentType FOUND_Z = DataComponentType.builder().persistent(Codec.INT).networkSynchronized(ByteBufCodecs.VAR_INT).build(); + public static final DataComponentType SEARCH_RADIUS = DataComponentType.builder().persistent(Codec.INT).networkSynchronized(ByteBufCodecs.VAR_INT).build(); + public static final DataComponentType SAMPLES = DataComponentType.builder().persistent(Codec.INT).networkSynchronized(ByteBufCodecs.VAR_INT).build(); + public static final DataComponentType DISPLAY_COORDS = DataComponentType.builder().persistent(Codec.BOOL).networkSynchronized(ByteBufCodecs.BOOL).build(); + public static boolean canTeleport; public static List allowedBiomes; public static ListMultimap dimensionKeysForAllowedBiomeKeys; @@ -73,11 +84,11 @@ private void buildCreativeTabContents(BuildCreativeModeTabContentsEvent event) { } } - private void registerPayloads(RegisterPayloadHandlerEvent event) { - final IPayloadRegistrar registrar = event.registrar(MODID); - registrar.play(SearchPacket.ID, SearchPacket::read, handler -> handler.server(SearchPacket::handle)); - registrar.play(TeleportPacket.ID, TeleportPacket::read, handler -> handler.server(TeleportPacket::handle)); - registrar.play(SyncPacket.ID, SyncPacket::read, handler -> handler.client(SyncPacket::handle)); + private void registerPayloads(RegisterPayloadHandlersEvent event) { + final PayloadRegistrar registrar = event.registrar(MODID); + registrar.playToServer(SearchPacket.TYPE, SearchPacket.CODEC, SearchPacket::handle); + registrar.playToServer(TeleportPacket.TYPE, TeleportPacket.CODEC, TeleportPacket::handle); + registrar.playToClient(SyncPacket.TYPE, SyncPacket.CODEC, SyncPacket::handle); } @SubscribeEvent diff --git a/src/main/java/com/chaosthedude/naturescompass/client/NaturesCompassClient.java b/src/main/java/com/chaosthedude/naturescompass/client/NaturesCompassClient.java index 636352c..790e7c0 100644 --- a/src/main/java/com/chaosthedude/naturescompass/client/NaturesCompassClient.java +++ b/src/main/java/com/chaosthedude/naturescompass/client/NaturesCompassClient.java @@ -18,12 +18,12 @@ import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.OnlyIn; import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.Mod; +import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; -import net.neoforged.neoforge.client.event.RegisterGuiOverlaysEvent; -import net.neoforged.neoforge.client.gui.overlay.VanillaGuiOverlay; +import net.neoforged.neoforge.client.event.RegisterGuiLayersEvent; +import net.neoforged.neoforge.client.gui.VanillaGuiLayers; -@Mod.EventBusSubscriber(modid = NaturesCompass.MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) +@EventBusSubscriber(modid = NaturesCompass.MODID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) public class NaturesCompassClient { @SubscribeEvent @@ -103,8 +103,8 @@ private double getAngle(ClientLevel world, Entity entity, ItemStack stack) { } @SubscribeEvent - public static void registerOverlay(RegisterGuiOverlaysEvent event) { - event.registerAbove(VanillaGuiOverlay.BOSS_EVENT_PROGRESS.id(), new ResourceLocation(NaturesCompass.MODID, "natures_compass"), new NaturesCompassOverlay()); + public static void registerOverlay(RegisterGuiLayersEvent event) { + event.registerAbove(VanillaGuiLayers.BOSS_OVERLAY, new ResourceLocation(NaturesCompass.MODID, "natures_compass"), new NaturesCompassOverlay()); } } \ No newline at end of file diff --git a/src/main/java/com/chaosthedude/naturescompass/client/NaturesCompassOverlay.java b/src/main/java/com/chaosthedude/naturescompass/client/NaturesCompassOverlay.java index fdc49c8..414248f 100644 --- a/src/main/java/com/chaosthedude/naturescompass/client/NaturesCompassOverlay.java +++ b/src/main/java/com/chaosthedude/naturescompass/client/NaturesCompassOverlay.java @@ -9,22 +9,21 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.LayeredDraw; import net.minecraft.client.gui.screens.ChatScreen; import net.minecraft.client.resources.language.I18n; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.OnlyIn; -import net.neoforged.neoforge.client.gui.overlay.ExtendedGui; -import net.neoforged.neoforge.client.gui.overlay.IGuiOverlay; @OnlyIn(Dist.CLIENT) -public class NaturesCompassOverlay implements IGuiOverlay { +public class NaturesCompassOverlay implements LayeredDraw.Layer { public static final Minecraft mc = Minecraft.getInstance(); @Override - public void render(ExtendedGui gui, GuiGraphics guiGraphics, float partialTick, int screenWidth, int screenHeight) { + public void render(GuiGraphics guiGraphics, float partialTick) { if (mc.player != null && mc.level != null && !mc.options.hideGui && !mc.getDebugOverlay().showDebugScreen() && (mc.screen == null || (ConfigHandler.CLIENT.displayWithChatOpen.get() && mc.screen instanceof ChatScreen))) { final Player player = mc.player; final ItemStack stack = ItemUtils.getHeldNatureCompass(player); diff --git a/src/main/java/com/chaosthedude/naturescompass/gui/BiomeInfoScreen.java b/src/main/java/com/chaosthedude/naturescompass/gui/BiomeInfoScreen.java index 91e53be..7175b8a 100644 --- a/src/main/java/com/chaosthedude/naturescompass/gui/BiomeInfoScreen.java +++ b/src/main/java/com/chaosthedude/naturescompass/gui/BiomeInfoScreen.java @@ -62,6 +62,8 @@ public void init() { @Override public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { + super.render(guiGraphics, mouseX, mouseY, partialTicks); + guiGraphics.drawString(font, Component.literal(BiomeUtils.getBiomeNameForDisplay(parentScreen.level, biome)), (width / 2) - (font.width(BiomeUtils.getBiomeNameForDisplay(parentScreen.level, biome)) / 2), 20, 0xffffff); guiGraphics.drawString(font, Component.translatable("string.naturescompass.source"), width / 2 - 100, 40, 0xffffff); @@ -87,8 +89,6 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partia //guiGraphics.drawString(font, Component.translatable("string.naturescompass.highHumidity"), width / 2 + 40, 100, 0xffffff); //guiGraphics.drawString(font, Component.literal(highHumidity), width / 2 + 40, 110, 0x808080); - - super.render(guiGraphics, mouseX, mouseY, partialTicks); } private void setupWidgets() { diff --git a/src/main/java/com/chaosthedude/naturescompass/gui/BiomeSearchList.java b/src/main/java/com/chaosthedude/naturescompass/gui/BiomeSearchList.java index 5ab6ad2..4878c36 100644 --- a/src/main/java/com/chaosthedude/naturescompass/gui/BiomeSearchList.java +++ b/src/main/java/com/chaosthedude/naturescompass/gui/BiomeSearchList.java @@ -38,11 +38,9 @@ protected boolean isSelectedItem(int slotIndex) { @Override public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { - renderList(guiGraphics, mouseX, mouseY, partialTicks); - } - - @Override - protected void renderList(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { + guiGraphics.fill(getRowLeft() - 4, getY(), getRowLeft() + getRowWidth() + 4, getY() + getHeight() + 4, 255 / 2 << 24); + + enableScissor(guiGraphics); for (int i = 0; i < getItemCount(); ++i) { int top = getRowTop(i); int bottom = getRowBottom(i); @@ -55,6 +53,7 @@ protected void renderList(GuiGraphics guiGraphics, int mouseX, int mouseY, float entry.render(guiGraphics, i, top, getRowLeft(), getRowWidth(), itemHeight - 4, mouseX, mouseY, isMouseOver((double) mouseX, (double) mouseY) && Objects.equals(getEntryAtPosition((double) mouseX, (double) mouseY), entry), partialTicks); } } + guiGraphics.disableScissor(); if (getMaxScroll() > 0) { int left = getScrollbarPosition(); @@ -70,7 +69,13 @@ protected void renderList(GuiGraphics guiGraphics, int mouseX, int mouseY, float guiGraphics.fill(left, top, right, top + height, (int) (1.9F * 255.0F) / 2 << 24); } } + + @Override + protected void enableScissor(GuiGraphics guiGraphics) { + guiGraphics.enableScissor(getX(), getY(), getRight(), getBottom()); + } + @Override protected int getRowBottom(int itemIndex) { return getRowTop(itemIndex) + itemHeight; } diff --git a/src/main/java/com/chaosthedude/naturescompass/gui/NaturesCompassScreen.java b/src/main/java/com/chaosthedude/naturescompass/gui/NaturesCompassScreen.java index c25176e..c114af1 100644 --- a/src/main/java/com/chaosthedude/naturescompass/gui/NaturesCompassScreen.java +++ b/src/main/java/com/chaosthedude/naturescompass/gui/NaturesCompassScreen.java @@ -19,7 +19,6 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.Component; -import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; @@ -86,8 +85,8 @@ public void tick() { @Override public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { - guiGraphics.drawCenteredString(font, I18n.get("string.naturescompass.selectBiome"), 65, 15, 0xffffff); super.render(guiGraphics, mouseX, mouseY, partialTicks); + guiGraphics.drawCenteredString(font, I18n.get("string.naturescompass.selectBiome"), 65, 15, 0xffffff); } @Override @@ -117,13 +116,13 @@ public void selectBiome(BiomeSearchEntry entry) { public void searchForBiome(Biome biome) { if (BiomeUtils.getKeyForBiome(level, biome).isPresent()) { - PacketDistributor.SERVER.noArg().send(new SearchPacket(BiomeUtils.getKeyForBiome(level, biome).get(), player.blockPosition())); + PacketDistributor.sendToServer(new SearchPacket(BiomeUtils.getKeyForBiome(level, biome).get(), player.blockPosition())); } minecraft.setScreen(null); } public void teleport() { - PacketDistributor.SERVER.noArg().send(new TeleportPacket()); + PacketDistributor.sendToServer(new TeleportPacket()); minecraft.setScreen(null); } diff --git a/src/main/java/com/chaosthedude/naturescompass/gui/TransparentTextField.java b/src/main/java/com/chaosthedude/naturescompass/gui/TransparentTextField.java index 4e5aba4..b9fa9b9 100644 --- a/src/main/java/com/chaosthedude/naturescompass/gui/TransparentTextField.java +++ b/src/main/java/com/chaosthedude/naturescompass/gui/TransparentTextField.java @@ -36,8 +36,7 @@ public TransparentTextField(Font font, int x, int y, int width, int height, Comp public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { if (isVisible()) { if (pseudoEnableBackgroundDrawing) { - final int color = (int) (255.0F * 0.55f); - guiGraphics.fill(getX(), getY(), getX() + width, getY() + height, color / 2 << 24); + guiGraphics.fill(getX(), getY(), getX() + width, getY() + height, 255 / 2 << 24); } boolean showLabel = !isFocused() && getValue().isEmpty(); int i = showLabel ? labelColor : (pseudoIsEnabled ? pseudoEnabledColor : pseudoDisabledColor); diff --git a/src/main/java/com/chaosthedude/naturescompass/items/NaturesCompassItem.java b/src/main/java/com/chaosthedude/naturescompass/items/NaturesCompassItem.java index dc472d5..5c68756 100644 --- a/src/main/java/com/chaosthedude/naturescompass/items/NaturesCompassItem.java +++ b/src/main/java/com/chaosthedude/naturescompass/items/NaturesCompassItem.java @@ -3,6 +3,7 @@ import java.util.List; import java.util.Optional; +import com.chaosthedude.naturescompass.NaturesCompass; import com.chaosthedude.naturescompass.config.ConfigHandler; import com.chaosthedude.naturescompass.gui.GuiWrapper; import com.chaosthedude.naturescompass.network.SyncPacket; @@ -13,7 +14,6 @@ import com.chaosthedude.naturescompass.util.PlayerUtils; import net.minecraft.core.BlockPos; -import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; @@ -48,7 +48,7 @@ public InteractionResultHolder use(Level level, Player player, Intera final ServerPlayer serverPlayer = (ServerPlayer) player; final boolean canTeleport = ConfigHandler.GENERAL.allowTeleport.get() && PlayerUtils.canTeleport(serverPlayer.getServer(), player); final List allowedBiomeKeys = BiomeUtils.getAllowedBiomeKeys(level); - PacketDistributor.PLAYER.with(serverPlayer).send(new SyncPacket(canTeleport, allowedBiomeKeys, BiomeUtils.getGeneratingDimensionsForAllowedBiomes(serverLevel))); + PacketDistributor.sendToPlayer(serverPlayer, new SyncPacket(canTeleport, allowedBiomeKeys, BiomeUtils.getGeneratingDimensionsForAllowedBiomes(serverLevel))); } } else { if (worker != null) { @@ -93,7 +93,7 @@ public void fail(ItemStack stack, Player player, int radius, int samples) { } public boolean isActive(ItemStack stack) { - if (ItemUtils.verifyNBT(stack)) { + if (stack.getItem() == NaturesCompass.naturesCompass) { return getState(stack) != CompassState.INACTIVE; } @@ -101,120 +101,120 @@ public boolean isActive(ItemStack stack) { } public void setSearching(ItemStack stack, ResourceLocation biomeKey, Player player) { - if (ItemUtils.verifyNBT(stack)) { - stack.getTag().putString("BiomeKey", biomeKey.toString()); - stack.getTag().putInt("State", CompassState.SEARCHING.getID()); + if (stack.getItem() == NaturesCompass.naturesCompass) { + stack.set(NaturesCompass.BIOME_ID, biomeKey.toString()); + stack.set(NaturesCompass.COMPASS_STATE, CompassState.SEARCHING.getID()); } } public void setFound(ItemStack stack, int x, int z, int samples, Player player) { - if (ItemUtils.verifyNBT(stack)) { - stack.getTag().putInt("State", CompassState.FOUND.getID()); - stack.getTag().putInt("FoundX", x); - stack.getTag().putInt("FoundZ", z); - stack.getTag().putInt("Samples", samples); + if (stack.getItem() == NaturesCompass.naturesCompass) { + stack.set(NaturesCompass.COMPASS_STATE, CompassState.FOUND.getID()); + stack.set(NaturesCompass.FOUND_X, x); + stack.set(NaturesCompass.FOUND_Z, z); + stack.set(NaturesCompass.SAMPLES, samples); } } public void setNotFound(ItemStack stack, Player player, int searchRadius, int samples) { - if (ItemUtils.verifyNBT(stack)) { - stack.getTag().putInt("State", CompassState.NOT_FOUND.getID()); - stack.getTag().putInt("SearchRadius", searchRadius); - stack.getTag().putInt("Samples", samples); + if (stack.getItem() == NaturesCompass.naturesCompass) { + stack.set(NaturesCompass.COMPASS_STATE, CompassState.NOT_FOUND.getID()); + stack.set(NaturesCompass.SEARCH_RADIUS, searchRadius); + stack.set(NaturesCompass.SAMPLES, samples); } } public void setInactive(ItemStack stack, Player player) { - if (ItemUtils.verifyNBT(stack)) { - stack.getTag().putInt("State", CompassState.INACTIVE.getID()); + if (stack.getItem() == NaturesCompass.naturesCompass) { + stack.set(NaturesCompass.COMPASS_STATE, CompassState.INACTIVE.getID()); } } public void setState(ItemStack stack, BlockPos pos, CompassState state, Player player) { - if (ItemUtils.verifyNBT(stack)) { - stack.getTag().putInt("State", state.getID()); + if (stack.getItem() == NaturesCompass.naturesCompass) { + stack.set(NaturesCompass.COMPASS_STATE, state.getID()); } } public void setFoundBiomeX(ItemStack stack, int x, Player player) { - if (ItemUtils.verifyNBT(stack)) { - stack.getTag().putInt("FoundX", x); + if (stack.getItem() == NaturesCompass.naturesCompass) { + stack.set(NaturesCompass.FOUND_X, x); } } public void setFoundBiomeZ(ItemStack stack, int z, Player player) { - if (ItemUtils.verifyNBT(stack)) { - stack.getTag().putInt("FoundZ", z); + if (stack.getItem() == NaturesCompass.naturesCompass) { + stack.set(NaturesCompass.FOUND_Z, z); } } public void setBiomeKey(ItemStack stack, ResourceLocation biomeKey, Player player) { - if (ItemUtils.verifyNBT(stack)) { - stack.getTag().putString("BiomeKey", biomeKey.toString()); + if (stack.getItem() == NaturesCompass.naturesCompass) { + stack.set(NaturesCompass.BIOME_ID, biomeKey.toString()); } } public void setSearchRadius(ItemStack stack, int searchRadius, Player player) { - if (ItemUtils.verifyNBT(stack)) { - stack.getTag().putInt("SearchRadius", searchRadius); + if (stack.getItem() == NaturesCompass.naturesCompass) { + stack.set(NaturesCompass.SEARCH_RADIUS, searchRadius); } } public void setSamples(ItemStack stack, int samples, Player player) { - if (ItemUtils.verifyNBT(stack)) { - stack.getTag().putInt("Samples", samples); + if (stack.getItem() == NaturesCompass.naturesCompass) { + stack.set(NaturesCompass.SAMPLES, samples); } } public CompassState getState(ItemStack stack) { - if (ItemUtils.verifyNBT(stack)) { - return CompassState.fromID(stack.getTag().getInt("State")); + if (stack.getItem() == NaturesCompass.naturesCompass && stack.has(NaturesCompass.COMPASS_STATE)) { + return CompassState.fromID(stack.get(NaturesCompass.COMPASS_STATE)); } return null; } public void setDisplayCoordinates(ItemStack stack, boolean displayPosition) { - if (ItemUtils.verifyNBT(stack)) { - stack.getTag().putBoolean("DisplayCoordinates", displayPosition); + if (stack.getItem() == NaturesCompass.naturesCompass) { + stack.set(NaturesCompass.DISPLAY_COORDS, displayPosition); } } public int getFoundBiomeX(ItemStack stack) { - if (ItemUtils.verifyNBT(stack)) { - return stack.getTag().getInt("FoundX"); + if (stack.getItem() == NaturesCompass.naturesCompass && stack.has(NaturesCompass.FOUND_X)) { + return stack.get(NaturesCompass.FOUND_X); } return 0; } public int getFoundBiomeZ(ItemStack stack) { - if (ItemUtils.verifyNBT(stack)) { - return stack.getTag().getInt("FoundZ"); + if (stack.getItem() == NaturesCompass.naturesCompass && stack.has(NaturesCompass.FOUND_Z)) { + return stack.get(NaturesCompass.FOUND_Z); } return 0; } public ResourceLocation getBiomeKey(ItemStack stack) { - if (ItemUtils.verifyNBT(stack)) { - return new ResourceLocation(stack.getTag().getString("BiomeKey")); + if (stack.getItem() == NaturesCompass.naturesCompass && stack.has(NaturesCompass.BIOME_ID)) { + return new ResourceLocation(stack.get(NaturesCompass.BIOME_ID)); } return new ResourceLocation(""); } public int getSearchRadius(ItemStack stack) { - if (ItemUtils.verifyNBT(stack)) { - return stack.getTag().getInt("SearchRadius"); + if (stack.getItem() == NaturesCompass.naturesCompass && stack.has(NaturesCompass.SEARCH_RADIUS)) { + return stack.get(NaturesCompass.SEARCH_RADIUS); } return -1; } public int getSamples(ItemStack stack) { - if (ItemUtils.verifyNBT(stack)) { - return stack.getTag().getInt("Samples"); + if (stack.getItem() == NaturesCompass.naturesCompass && stack.has(NaturesCompass.SAMPLES)) { + return stack.get(NaturesCompass.SAMPLES); } return -1; @@ -225,8 +225,8 @@ public int getDistanceToBiome(Player player, ItemStack stack) { } public boolean shouldDisplayCoordinates(ItemStack stack) { - if (ItemUtils.verifyNBT(stack) && stack.getTag().contains("DisplayCoordinates")) { - return stack.getTag().getBoolean("DisplayCoordinates"); + if (stack.getItem() == NaturesCompass.naturesCompass && stack.has(NaturesCompass.DISPLAY_COORDS)) { + return stack.get(NaturesCompass.DISPLAY_COORDS); } return true; diff --git a/src/main/java/com/chaosthedude/naturescompass/network/SearchPacket.java b/src/main/java/com/chaosthedude/naturescompass/network/SearchPacket.java index d2c0cb0..22ddd19 100644 --- a/src/main/java/com/chaosthedude/naturescompass/network/SearchPacket.java +++ b/src/main/java/com/chaosthedude/naturescompass/network/SearchPacket.java @@ -6,41 +6,43 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.item.ItemStack; -import net.neoforged.neoforge.network.handling.PlayPayloadContext; +import net.neoforged.neoforge.network.handling.IPayloadContext; public record SearchPacket(ResourceLocation biomeKey, BlockPos pos) implements CustomPacketPayload { - public static final ResourceLocation ID = new ResourceLocation(NaturesCompass.MODID, "search"); + public static final Type TYPE = new Type(new ResourceLocation(NaturesCompass.MODID, "search")); + + public static final StreamCodec CODEC = StreamCodec.ofMember(SearchPacket::write, SearchPacket::read); public static SearchPacket read(FriendlyByteBuf buf) { return new SearchPacket(buf.readResourceLocation(), buf.readBlockPos()); } - @Override public void write(FriendlyByteBuf buf) { buf.writeResourceLocation(biomeKey); buf.writeBlockPos(pos); } - public static void handle(SearchPacket packet, PlayPayloadContext context) { - context.workHandler().submitAsync(() -> { - if (context.player().isPresent() && context.level().isPresent()) { - final ItemStack stack = ItemUtils.getHeldNatureCompass(context.player().get()); + public static void handle(SearchPacket packet, IPayloadContext context) { + if (context.flow().isServerbound()) { + context.enqueueWork(() -> { + final ItemStack stack = ItemUtils.getHeldNatureCompass(context.player()); if (!stack.isEmpty()) { final NaturesCompassItem natureCompass = (NaturesCompassItem) stack.getItem(); - natureCompass.searchForBiome((ServerLevel) context.level().get(), context.player().get(), packet.biomeKey, packet.pos, stack); + natureCompass.searchForBiome((ServerLevel) context.player().level(), context.player(), packet.biomeKey, packet.pos, stack); } - } - }); + }); + } } - + @Override - public ResourceLocation id() { - return ID; + public Type type() { + return TYPE; } } diff --git a/src/main/java/com/chaosthedude/naturescompass/network/SyncPacket.java b/src/main/java/com/chaosthedude/naturescompass/network/SyncPacket.java index 49e1452..ab7344f 100644 --- a/src/main/java/com/chaosthedude/naturescompass/network/SyncPacket.java +++ b/src/main/java/com/chaosthedude/naturescompass/network/SyncPacket.java @@ -8,13 +8,17 @@ import com.google.common.collect.ListMultimap; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; -import net.neoforged.neoforge.network.handling.PlayPayloadContext; +import net.neoforged.neoforge.network.handling.ClientPayloadContext; +import net.neoforged.neoforge.network.handling.IPayloadContext; public record SyncPacket(boolean canTeleport, List allowedBiomes, ListMultimap dimensionKeysForAllowedBiomeKeys) implements CustomPacketPayload { - public static final ResourceLocation ID = new ResourceLocation(NaturesCompass.MODID, "sync"); + public static final Type TYPE = new Type(new ResourceLocation(NaturesCompass.MODID, "sync")); + + public static final StreamCodec CODEC = StreamCodec.ofMember(SyncPacket::write, SyncPacket::read); public static SyncPacket read(FriendlyByteBuf buf) { boolean canTeleport = buf.readBoolean(); @@ -39,7 +43,6 @@ public static SyncPacket read(FriendlyByteBuf buf) { return new SyncPacket(canTeleport, allowedBiomes, dimensionKeysForAllowedBiomeKeys); } - @Override public void write(FriendlyByteBuf buf) { buf.writeBoolean(canTeleport); buf.writeInt(allowedBiomes.size()); @@ -53,17 +56,19 @@ public void write(FriendlyByteBuf buf) { } } - public static void handle(SyncPacket packet, PlayPayloadContext context) { - context.workHandler().submitAsync(() -> { - NaturesCompass.canTeleport = packet.canTeleport; - NaturesCompass.allowedBiomes = packet.allowedBiomes; - NaturesCompass.dimensionKeysForAllowedBiomeKeys = packet.dimensionKeysForAllowedBiomeKeys; - }); + public static void handle(SyncPacket packet, IPayloadContext context) { + if (context.flow().isClientbound()) { + context.enqueueWork(() -> { + NaturesCompass.canTeleport = packet.canTeleport; + NaturesCompass.allowedBiomes = packet.allowedBiomes; + NaturesCompass.dimensionKeysForAllowedBiomeKeys = packet.dimensionKeysForAllowedBiomeKeys; + }); + } } @Override - public ResourceLocation id() { - return ID; + public Type type() { + return TYPE; } } diff --git a/src/main/java/com/chaosthedude/naturescompass/network/TeleportPacket.java b/src/main/java/com/chaosthedude/naturescompass/network/TeleportPacket.java index 06d71eb..7274f28 100644 --- a/src/main/java/com/chaosthedude/naturescompass/network/TeleportPacket.java +++ b/src/main/java/com/chaosthedude/naturescompass/network/TeleportPacket.java @@ -9,37 +9,39 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.tags.BlockTags; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -import net.neoforged.neoforge.network.handling.PlayPayloadContext; +import net.neoforged.neoforge.network.handling.IPayloadContext; public record TeleportPacket() implements CustomPacketPayload { - public static final ResourceLocation ID = new ResourceLocation(NaturesCompass.MODID, "teleport"); + public static final Type TYPE = new Type(new ResourceLocation(NaturesCompass.MODID, "teleport")); + + public static final StreamCodec CODEC = StreamCodec.ofMember(TeleportPacket::write, TeleportPacket::read); public static TeleportPacket read(FriendlyByteBuf buf) { return new TeleportPacket(); } - @Override public void write(FriendlyByteBuf buf) {} - public static void handle(TeleportPacket packet, PlayPayloadContext context) { - context.workHandler().submitAsync(() -> { - if (context.player().isPresent() && context.level().isPresent()) { - final ItemStack stack = ItemUtils.getHeldNatureCompass(context.player().get()); + public static void handle(TeleportPacket packet, IPayloadContext context) { + if (context.flow().isServerbound()) { + context.enqueueWork(() -> { + final ItemStack stack = ItemUtils.getHeldNatureCompass(context.player()); if (!stack.isEmpty()) { final NaturesCompassItem natureCompass = (NaturesCompassItem) stack.getItem(); - final ServerPlayer player = (ServerPlayer) context.player().get(); + final ServerPlayer player = (ServerPlayer) context.player(); if (ConfigHandler.GENERAL.allowTeleport.get() && PlayerUtils.canTeleport(player.getServer(), player)) { if (natureCompass.getState(stack) == CompassState.FOUND) { final int x = natureCompass.getFoundBiomeX(stack); final int z = natureCompass.getFoundBiomeZ(stack); - final int y = packet.findValidTeleportHeight(context.level().get(), x, z); + final int y = packet.findValidTeleportHeight(context.player().level(), x, z); player.stopRiding(); player.connection.teleport(x, y, z, player.getYRot(), player.getXRot()); @@ -53,8 +55,8 @@ public static void handle(TeleportPacket packet, PlayPayloadContext context) { NaturesCompass.LOGGER.warn("Player " + player.getDisplayName().getString() + " tried to teleport but does not have permission."); } } - } - }); + }); + } } private int findValidTeleportHeight(Level level, int x, int z) { @@ -84,8 +86,8 @@ private boolean isFree(Level level, BlockPos pos) { } @Override - public ResourceLocation id() { - return ID; + public Type type() { + return TYPE; } } diff --git a/src/main/java/com/chaosthedude/naturescompass/registry/NaturesCompassRegistry.java b/src/main/java/com/chaosthedude/naturescompass/registry/NaturesCompassRegistry.java index a83c32a..38fb42c 100644 --- a/src/main/java/com/chaosthedude/naturescompass/registry/NaturesCompassRegistry.java +++ b/src/main/java/com/chaosthedude/naturescompass/registry/NaturesCompassRegistry.java @@ -6,7 +6,7 @@ import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.Mod.EventBusSubscriber; +import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.neoforge.registries.RegisterEvent; @EventBusSubscriber(modid = NaturesCompass.MODID, bus = EventBusSubscriber.Bus.MOD) @@ -18,6 +18,16 @@ public static void register(RegisterEvent event) { NaturesCompass.naturesCompass = new NaturesCompassItem(); registry.register(new ResourceLocation(NaturesCompass.MODID, NaturesCompassItem.NAME), NaturesCompass.naturesCompass); }); + + event.register(BuiltInRegistries.DATA_COMPONENT_TYPE.key(), registry -> { + registry.register(new ResourceLocation(NaturesCompass.MODID, "biome_id"), NaturesCompass.BIOME_ID); + registry.register(new ResourceLocation(NaturesCompass.MODID, "compass_state"), NaturesCompass.COMPASS_STATE); + registry.register(new ResourceLocation(NaturesCompass.MODID, "found_x"), NaturesCompass.FOUND_X); + registry.register(new ResourceLocation(NaturesCompass.MODID, "found_z"), NaturesCompass.FOUND_Z); + registry.register(new ResourceLocation(NaturesCompass.MODID, "search_radius"), NaturesCompass.SEARCH_RADIUS); + registry.register(new ResourceLocation(NaturesCompass.MODID, "samples"), NaturesCompass.SAMPLES); + registry.register(new ResourceLocation(NaturesCompass.MODID, "display_coords"), NaturesCompass.DISPLAY_COORDS); + }); } } diff --git a/src/main/java/com/chaosthedude/naturescompass/util/BiomeUtils.java b/src/main/java/com/chaosthedude/naturescompass/util/BiomeUtils.java index 5986e59..a3cb21f 100644 --- a/src/main/java/com/chaosthedude/naturescompass/util/BiomeUtils.java +++ b/src/main/java/com/chaosthedude/naturescompass/util/BiomeUtils.java @@ -55,7 +55,7 @@ public static List getAllowedBiomeKeys(Level level) { Biome biome = entry.getValue(); if (biome != null) { Optional optionalBiomeKey = getKeyForBiome(level, biome); - if (biome != null && optionalBiomeKey.isPresent() && !biomeKeyIsBlacklisted(level, optionalBiomeKey.get())) { + if (biome != null && optionalBiomeKey.isPresent() && !biomeKeyIsBlacklisted(level, optionalBiomeKey.get()) && !biomeKeyIsHidden(level, optionalBiomeKey.get())) { biomeKeys.add(optionalBiomeKey.get()); } } @@ -233,6 +233,18 @@ public static boolean biomeKeyIsBlacklisted(Level level, ResourceLocation biomeK } return false; } + + public static boolean biomeKeyIsHidden(Level level, ResourceLocation biomeKey) { + if (getBiomeRegistry(level).isPresent() && getBiomeForKey(level, biomeKey).isPresent()) { + final Registry biomeRegistry = getBiomeRegistry(level).get(); + final Biome biome = getBiomeForKey(level, biomeKey).get(); + if (biomeRegistry.getResourceKey(biome).isPresent() && biomeRegistry.getHolder(biomeRegistry.getResourceKey(biome).get()).isPresent()) { + final Holder biomeHolder = biomeRegistry.getHolder(biomeRegistry.getResourceKey(biome).get()).get(); + return biomeHolder.tags().anyMatch(tag -> tag.location().getPath().equals("c:hidden_from_locator_selection")); + } + } + return false; + } private static String convertToRegex(String glob) { String regex = "^"; diff --git a/src/main/java/com/chaosthedude/naturescompass/util/ItemUtils.java b/src/main/java/com/chaosthedude/naturescompass/util/ItemUtils.java index 47f8e05..2074602 100644 --- a/src/main/java/com/chaosthedude/naturescompass/util/ItemUtils.java +++ b/src/main/java/com/chaosthedude/naturescompass/util/ItemUtils.java @@ -2,23 +2,12 @@ import com.chaosthedude.naturescompass.NaturesCompass; -import net.minecraft.nbt.CompoundTag; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; public class ItemUtils { - public static boolean verifyNBT(ItemStack stack) { - if (stack.isEmpty() || stack.getItem() != NaturesCompass.naturesCompass) { - return false; - } else if (!stack.hasTag()) { - stack.setTag(new CompoundTag()); - } - - return true; - } - public static ItemStack getHeldNatureCompass(Player player) { return getHeldItem(player, NaturesCompass.naturesCompass); } diff --git a/src/main/java/com/chaosthedude/naturescompass/util/PlayerUtils.java b/src/main/java/com/chaosthedude/naturescompass/util/PlayerUtils.java index cc3e10c..04efd2e 100644 --- a/src/main/java/com/chaosthedude/naturescompass/util/PlayerUtils.java +++ b/src/main/java/com/chaosthedude/naturescompass/util/PlayerUtils.java @@ -20,7 +20,7 @@ public static boolean cheatModeEnabled(MinecraftServer server, Player player) { if (server != null && server.isSingleplayer()) { LevelData levelData = server.getLevel(player.level().dimension()).getLevelData(); if (levelData instanceof ServerLevelData) { - return ((ServerLevelData) levelData).getAllowCommands(); + return ((ServerLevelData) levelData).isAllowCommands(); } } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/neoforge.mods.toml similarity index 95% rename from src/main/resources/META-INF/mods.toml rename to src/main/resources/META-INF/neoforge.mods.toml index 19a7472..e379f44 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/neoforge.mods.toml @@ -5,7 +5,7 @@ license="CC BY-NC-SA 4.0" [[mods]] modId="naturescompass" - version="1.20.4-3.0.0-neoforge" + version="1.20.5-3.0.1-neoforge" displayName="Nature's Compass" displayURL="https://github.com/MattCzyr/NaturesCompass" authors="ChaosTheDude" diff --git a/src/main/resources/data/naturescompass/recipes/natures_compass.json b/src/main/resources/data/naturescompass/recipes/natures_compass.json index 113c859..08681f5 100644 --- a/src/main/resources/data/naturescompass/recipes/natures_compass.json +++ b/src/main/resources/data/naturescompass/recipes/natures_compass.json @@ -18,6 +18,6 @@ } }, "result": { - "item": "naturescompass:naturescompass" + "id": "naturescompass:naturescompass" } } \ No newline at end of file