diff --git a/build.gradle b/build.gradle index cb52d32..dd06981 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ plugins { id 'eclipse' id 'idea' id 'maven-publish' - id 'net.minecraftforge.gradle' version '[6.0.16,6.2)' + id 'net.minecraftforge.gradle' version '[6.0.24,6.2)' } version = mod_version @@ -12,8 +12,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 in 1.20.5+, so your mod should target Java 21. +java.toolchain.languageVersion = JavaLanguageVersion.of(21) println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { @@ -31,6 +31,9 @@ minecraft { // Use non-default mappings at your own risk. They may not always work. // Simply re-run your setup task after changing the mappings to update your workspace. mappings channel: mapping_channel, version: mapping_version + + // Tell FG to not automtically create the reobf tasks, as we now use Official mappings at runtime, If you don't use them at dev time then you'll have to fix your reobf yourself. + reobf = false // When true, this property will have all Eclipse/IntelliJ IDEA run configurations run the "prepareX" task for the given run configuration before launching the game. // In most cases, it is not necessary to enable. @@ -124,11 +127,11 @@ dependencies { // then special handling is done to allow a setup of a vanilla dependency without the use of an external repository. minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" - // Example mod dependency with JEI - using fg.deobf() ensures the dependency is remapped to your development mappings + // Example mod dependency with JEI // The JEI API is declared for compile time use, while the full JEI artifact is used at runtime - // compileOnly fg.deobf("mezz.jei:jei-${mc_version}-common-api:${jei_version}") - // compileOnly fg.deobf("mezz.jei:jei-${mc_version}-forge-api:${jei_version}") - // runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}-forge:${jei_version}") + // compileOnly "mezz.jei:jei-${mc_version}-common-api:${jei_version}" + // compileOnly "mezz.jei:jei-${mc_version}-forge-api:${jei_version}" + // runtimeOnly "mezz.jei:jei-${mc_version}-forge:${jei_version}" // Example mod dependency using a mod jar from ./libs with a flat dir repository // This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar @@ -138,6 +141,9 @@ dependencies { // For more info: // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html // http://www.gradle.org/docs/current/userguide/dependency_management.html + + // Hack fix for now, force jopt-simple to be exactly 5.0.4 because Mojang ships that version, but some transtive dependencies request 6.0+ + implementation('net.sf.jopt-simple:jopt-simple:5.0.4') { version { strictly '5.0.4' } } } // This block of code expands all declared replace properties in the specified resource targets. @@ -171,16 +177,8 @@ tasks.named('jar', Jar).configure { 'Implementation-Vendor' : mod_authors ]) } - - // This is the preferred method to reobfuscate your jar file - finalizedBy 'reobfJar' } -// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing: -// tasks.named('publish').configure { -// dependsOn 'reobfJar' -// } - // Example configuration to allow publishing using the maven-publish plugin publishing { publications { diff --git a/gradle.properties b/gradle.properties index 45c0945..34d572c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,13 +7,13 @@ org.gradle.daemon=false ## Environment Properties # The Minecraft version must agree with the Forge version to get a valid artifact -minecraft_version=1.20.4 +minecraft_version=1.20.6 # 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.6,1.21) # The Forge version must agree with the Minecraft version to get a valid artifact -forge_version=49.0.11 +forge_version=50.0.13 # The Forge version range can use any version of Forge as bounds or match the loader version range forge_version_range=[0,) # The loader version range can only use the major version of Forge/FML as bounds @@ -35,7 +35,7 @@ loader_version_range=[0,) mapping_channel=official # The mapping version to query from the mapping channel. # This must match the format required by the mapping channel. -mapping_version=1.20.4 +mapping_version=1.20.6 ## Mod Properties @@ -48,7 +48,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-1.11.5-forge +mod_version=1.20.6-1.11.5-forge # 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 309b4e1..bb6c191 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.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/com/chaosthedude/naturescompass/NaturesCompass.java b/src/main/java/com/chaosthedude/naturescompass/NaturesCompass.java index 635930a..1382e90 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; @@ -43,6 +46,14 @@ public class NaturesCompass { public static SimpleChannel network; 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; @@ -66,11 +77,11 @@ private void preInit(FMLCommonSetupEvent event) { network = ChannelBuilder.named(new ResourceLocation(NaturesCompass.MODID, NaturesCompass.MODID)).networkProtocolVersion(1).optionalClient().clientAcceptedVersions(Channel.VersionTest.exact(1)).simpleChannel(); // Server packets - network.messageBuilder(CompassSearchPacket.class).encoder(CompassSearchPacket::toBytes).decoder(CompassSearchPacket::new).consumerMainThread(CompassSearchPacket::handle).add(); - network.messageBuilder(TeleportPacket.class).encoder(TeleportPacket::toBytes).decoder(TeleportPacket::new).consumerMainThread(TeleportPacket::handle).add(); + network.messageBuilder(CompassSearchPacket.class).encoder(CompassSearchPacket::encode).decoder(CompassSearchPacket::new).consumerMainThread(CompassSearchPacket::handle).add(); + network.messageBuilder(TeleportPacket.class).encoder(TeleportPacket::encode).decoder(TeleportPacket::new).consumerMainThread(TeleportPacket::handle).add(); // Client packet - network.messageBuilder(SyncPacket.class).encoder(SyncPacket::toBytes).decoder(SyncPacket::new).consumerMainThread(SyncPacket::handle).add(); + network.messageBuilder(SyncPacket.class).encoder(SyncPacket::encode).decoder(SyncPacket::new).consumerMainThread(SyncPacket::handle).add(); allowedBiomes = new ArrayList(); dimensionKeysForAllowedBiomeKeys = ArrayListMultimap.create(); diff --git a/src/main/java/com/chaosthedude/naturescompass/client/NaturesCompassClient.java b/src/main/java/com/chaosthedude/naturescompass/client/NaturesCompassClient.java index df73698..b05faef 100644 --- a/src/main/java/com/chaosthedude/naturescompass/client/NaturesCompassClient.java +++ b/src/main/java/com/chaosthedude/naturescompass/client/NaturesCompassClient.java @@ -1,9 +1,14 @@ package com.chaosthedude.naturescompass.client; +import java.lang.reflect.Field; + import com.chaosthedude.naturescompass.NaturesCompass; import com.chaosthedude.naturescompass.items.NaturesCompassItem; import com.chaosthedude.naturescompass.util.CompassState; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.LayeredDraw; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.item.ClampedItemPropertyFunction; import net.minecraft.client.renderer.item.ItemProperties; @@ -17,15 +22,16 @@ import net.minecraft.world.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.event.RegisterGuiOverlaysEvent; -import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; +import net.minecraftforge.fml.util.ObfuscationReflectionHelper; @Mod.EventBusSubscriber(modid = NaturesCompass.MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) public class NaturesCompassClient { + private static final Field LAYERS = ObfuscationReflectionHelper.findField(Gui.class, "layers"); + @SubscribeEvent public static void clientInit(FMLClientSetupEvent event) { event.enqueueWork(() -> { @@ -100,11 +106,17 @@ private double getAngle(ClientLevel world, Entity entity, ItemStack stack) { } }); }); + + event.enqueueWork(() -> { + Minecraft mc = Minecraft.getInstance(); + try { + LayeredDraw layers = (LayeredDraw) LAYERS.get(mc.gui); + layers.add(new NaturesCompassOverlay()); + } catch (IllegalAccessException e) { + NaturesCompass.LOGGER.error("Failed to add Nature's Compass GUI layer"); + throw new RuntimeException("Failed to add layer"); + } + }); } - - @SubscribeEvent - public static void registerOverlay(RegisterGuiOverlaysEvent event) { - event.registerAbove(VanillaGuiOverlay.BOSS_EVENT_PROGRESS.id(), "natures_compass", new NaturesCompassOverlay()); - } } diff --git a/src/main/java/com/chaosthedude/naturescompass/client/NaturesCompassOverlay.java b/src/main/java/com/chaosthedude/naturescompass/client/NaturesCompassOverlay.java index 32e9812..a746d64 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.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.gui.overlay.ForgeGui; -import net.minecraftforge.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(ForgeGui 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 abc57e1..e183156 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 83aecfd..c65fdec 100644 --- a/src/main/java/com/chaosthedude/naturescompass/gui/BiomeSearchList.java +++ b/src/main/java/com/chaosthedude/naturescompass/gui/BiomeSearchList.java @@ -38,11 +38,14 @@ protected boolean isSelectedItem(int slotIndex) { @Override public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { - renderList(guiGraphics, mouseX, mouseY, partialTicks); + renderListItems(guiGraphics, mouseX, mouseY, partialTicks); } @Override - protected void renderList(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { + protected void renderListItems(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 +58,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 +74,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 5737e94..fce4f84 100644 --- a/src/main/java/com/chaosthedude/naturescompass/gui/NaturesCompassScreen.java +++ b/src/main/java/com/chaosthedude/naturescompass/gui/NaturesCompassScreen.java @@ -85,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 diff --git a/src/main/java/com/chaosthedude/naturescompass/gui/TransparentTextField.java b/src/main/java/com/chaosthedude/naturescompass/gui/TransparentTextField.java index bc9eafd..c66bb9b 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 cb91795..1f2288c 100644 --- a/src/main/java/com/chaosthedude/naturescompass/items/NaturesCompassItem.java +++ b/src/main/java/com/chaosthedude/naturescompass/items/NaturesCompassItem.java @@ -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 (ItemUtils.isCompass(stack)) { 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 (ItemUtils.isCompass(stack)) { + 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 (ItemUtils.isCompass(stack)) { + 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 (ItemUtils.isCompass(stack)) { + 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 (ItemUtils.isCompass(stack)) { + 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 (ItemUtils.isCompass(stack)) { + 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 (ItemUtils.isCompass(stack)) { + 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 (ItemUtils.isCompass(stack)) { + 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 (ItemUtils.isCompass(stack)) { + 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 (ItemUtils.isCompass(stack)) { + 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 (ItemUtils.isCompass(stack)) { + stack.set(NaturesCompass.SAMPLES, samples); } } public CompassState getState(ItemStack stack) { - if (ItemUtils.verifyNBT(stack)) { - return CompassState.fromID(stack.getTag().getInt("State")); + if (ItemUtils.isCompass(stack) && 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 (ItemUtils.isCompass(stack) && stack.has(NaturesCompass.DISPLAY_COORDS)) { + stack.set(NaturesCompass.DISPLAY_COORDS, displayPosition); } } public int getFoundBiomeX(ItemStack stack) { - if (ItemUtils.verifyNBT(stack)) { - return stack.getTag().getInt("FoundX"); + if (ItemUtils.isCompass(stack) && 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 (ItemUtils.isCompass(stack) && 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 (ItemUtils.isCompass(stack) && 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 (ItemUtils.isCompass(stack) && 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 (ItemUtils.isCompass(stack) && 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 (ItemUtils.isCompass(stack) && stack.has(NaturesCompass.DISPLAY_COORDS)) { + return stack.get(NaturesCompass.DISPLAY_COORDS); } return true; diff --git a/src/main/java/com/chaosthedude/naturescompass/network/CompassSearchPacket.java b/src/main/java/com/chaosthedude/naturescompass/network/CompassSearchPacket.java index dbbb061..9c28d3b 100644 --- a/src/main/java/com/chaosthedude/naturescompass/network/CompassSearchPacket.java +++ b/src/main/java/com/chaosthedude/naturescompass/network/CompassSearchPacket.java @@ -1,7 +1,5 @@ package com.chaosthedude.naturescompass.network; -import java.util.function.Supplier; - import com.chaosthedude.naturescompass.items.NaturesCompassItem; import com.chaosthedude.naturescompass.util.ItemUtils; @@ -14,34 +12,23 @@ public class CompassSearchPacket { private ResourceLocation biomeKey; - private int x; - private int y; - private int z; + private BlockPos pos; public CompassSearchPacket() {} public CompassSearchPacket(ResourceLocation biomeKey, BlockPos pos) { this.biomeKey = biomeKey; - - this.x = pos.getX(); - this.y = pos.getY(); - this.z = pos.getZ(); + this.pos = pos; } public CompassSearchPacket(FriendlyByteBuf buf) { biomeKey = buf.readResourceLocation(); - - x = buf.readInt(); - y = buf.readInt(); - z = buf.readInt(); + pos = buf.readBlockPos(); } - public void toBytes(FriendlyByteBuf buf) { + public void encode(FriendlyByteBuf buf) { buf.writeResourceLocation(biomeKey); - - buf.writeInt(x); - buf.writeInt(y); - buf.writeInt(z); + buf.writeBlockPos(pos); } public static void handle(CompassSearchPacket packet, CustomPayloadEvent.Context ctx) { @@ -49,7 +36,7 @@ public static void handle(CompassSearchPacket packet, CustomPayloadEvent.Context final ItemStack stack = ItemUtils.getHeldNatureCompass(ctx.getSender()); if (!stack.isEmpty()) { final NaturesCompassItem natureCompass = (NaturesCompassItem) stack.getItem(); - natureCompass.searchForBiome(ctx.getSender().serverLevel(), ctx.getSender(), packet.biomeKey, new BlockPos(packet.x, packet.y, packet.z), stack); + natureCompass.searchForBiome(ctx.getSender().serverLevel(), ctx.getSender(), packet.biomeKey, packet.pos, stack); } }); ctx.setPacketHandled(true); diff --git a/src/main/java/com/chaosthedude/naturescompass/network/SyncPacket.java b/src/main/java/com/chaosthedude/naturescompass/network/SyncPacket.java index 18a2e1d..775e682 100644 --- a/src/main/java/com/chaosthedude/naturescompass/network/SyncPacket.java +++ b/src/main/java/com/chaosthedude/naturescompass/network/SyncPacket.java @@ -46,7 +46,7 @@ public SyncPacket(FriendlyByteBuf buf) { } } - public void toBytes(FriendlyByteBuf buf) { + public void encode(FriendlyByteBuf buf) { buf.writeBoolean(canTeleport); buf.writeInt(allowedBiomes.size()); for (ResourceLocation biomeKey : allowedBiomes) { diff --git a/src/main/java/com/chaosthedude/naturescompass/network/TeleportPacket.java b/src/main/java/com/chaosthedude/naturescompass/network/TeleportPacket.java index 14478da..5338529 100644 --- a/src/main/java/com/chaosthedude/naturescompass/network/TeleportPacket.java +++ b/src/main/java/com/chaosthedude/naturescompass/network/TeleportPacket.java @@ -21,9 +21,7 @@ public TeleportPacket() {} public TeleportPacket(FriendlyByteBuf buf) {} - public void fromBytes(FriendlyByteBuf buf) {} - - public void toBytes(FriendlyByteBuf buf) {} + public void encode(FriendlyByteBuf buf) {} public static void handle(TeleportPacket packet, CustomPayloadEvent.Context ctx) { ctx.enqueueWork(() -> { diff --git a/src/main/java/com/chaosthedude/naturescompass/registry/NaturesCompassRegistry.java b/src/main/java/com/chaosthedude/naturescompass/registry/NaturesCompassRegistry.java index 7fca983..3591276 100644 --- a/src/main/java/com/chaosthedude/naturescompass/registry/NaturesCompassRegistry.java +++ b/src/main/java/com/chaosthedude/naturescompass/registry/NaturesCompassRegistry.java @@ -3,6 +3,7 @@ import com.chaosthedude.naturescompass.NaturesCompass; import com.chaosthedude.naturescompass.items.NaturesCompassItem; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; @@ -18,6 +19,16 @@ public static void registerItems(RegisterEvent e) { NaturesCompass.naturesCompass = new NaturesCompassItem(); helper.register(new ResourceLocation(NaturesCompass.MODID, NaturesCompassItem.NAME), NaturesCompass.naturesCompass); }); + + e.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 a670bba..732f668 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..9210908 100644 --- a/src/main/java/com/chaosthedude/naturescompass/util/ItemUtils.java +++ b/src/main/java/com/chaosthedude/naturescompass/util/ItemUtils.java @@ -2,21 +2,14 @@ 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 boolean isCompass(ItemStack stack) { + return !stack.isEmpty() && stack.getItem() == NaturesCompass.naturesCompass; } public static ItemStack getHeldNatureCompass(Player player) { diff --git a/src/main/java/com/chaosthedude/naturescompass/util/PlayerUtils.java b/src/main/java/com/chaosthedude/naturescompass/util/PlayerUtils.java index 70a8e4a..200ed62 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/mods.toml index 26eca87..1b3c3ba 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,11 +1,11 @@ modLoader="javafml" -loaderVersion="[49,)" +loaderVersion="[50,)" issueTrackerURL="https://github.com/MattCzyr/NaturesCompass/issues" license="CC BY-NC-SA 4.0" [[mods]] modId="naturescompass" - version="1.20.4-1.11.5-forge" + version="1.20.6-1.11.5-forge" displayName="Nature's Compass" displayURL="https://github.com/MattCzyr/NaturesCompass" authors="ChaosTheDude" @@ -16,12 +16,12 @@ license="CC BY-NC-SA 4.0" [[dependencies.naturescompass]] modId="forge" mandatory=true - versionRange="[49,)" + versionRange="[50,)" ordering="NONE" side="BOTH" [[dependencies.naturescompass]] modId="minecraft" mandatory=true - versionRange="[1.20.4,)" + versionRange="[1.20.6,)" ordering="NONE" side="BOTH" 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