From 8eb93ff176343d48e1a8c98a61c75e3b4c18646a Mon Sep 17 00:00:00 2001 From: zontreck Date: Tue, 16 Jan 2024 19:35:17 -0700 Subject: [PATCH 1/4] Backport to 1.18.2 --- build.gradle | 21 +-- gradle.properties | 16 +- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 4 - .../zontreck/essentials/AriasEssentials.java | 8 - .../zontreck/essentials/client/AutoWalk.java | 13 +- .../essentials/client/Keybindings.java | 9 +- .../commands/gui/HeartsCommand.java | 17 +- .../commands/homes/DelHomeCommand.java | 8 +- .../commands/homes/HomeCommand.java | 7 +- .../commands/homes/HomesCommand.java | 2 +- .../commands/homes/SetHomeCommand.java | 13 +- .../commands/teleport/BackCommand.java | 20 ++- .../commands/teleport/RTPCommand.java | 10 +- .../commands/teleport/SpawnCommand.java | 12 +- .../commands/teleport/TPACommand.java | 10 +- .../commands/teleport/TPAHereCommand.java | 10 +- .../commands/teleport/TPAcceptCommand.java | 10 +- .../commands/teleport/TPEffectsCommand.java | 8 +- .../commands/teleport/TeleportActioner.java | 16 +- .../commands/warps/DelWarpCommand.java | 8 +- .../commands/warps/RTPWarpCommand.java | 12 +- .../commands/warps/SetWarpCommand.java | 12 +- .../commands/warps/WarpCommand.java | 9 +- .../configs/server/AEServerConfig.java | 2 +- .../essentials/gui/HeartsRenderer.java | 147 ++++++++---------- .../homes/HomesSuggestionProvider.java | 2 +- .../essentials/networking/ModMessages.java | 8 +- .../rtp/RTPCachesEventHandlers.java | 5 +- .../resources/META-INF/accesstransformer.cfg | 5 - src/main/resources/META-INF/mods.toml | 84 +++++----- src/main/resources/pack.mcmeta | 8 +- 32 files changed, 276 insertions(+), 242 deletions(-) diff --git a/build.gradle b/build.gradle index 0305be8..0abcb44 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,6.2)' + id 'net.minecraftforge.gradle' version '5.1+' id 'org.parchmentmc.librarian.forgegradle' version '1.+' } @@ -41,7 +41,6 @@ minecraft { // This property allows configuring Gradle's ProcessResources task(s) to run on IDE output locations before launching the game. // It is REQUIRED to be set to true for this template to function. // See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html - copyIdeResources = true // When true, this property will add the folder name of all declared run configurations to generated IDE run configurations. // The folder name can be set on a run configuration using the "folderName" property. @@ -169,24 +168,6 @@ dependencies { // http://www.gradle.org/docs/current/userguide/dependency_management.html } -// This block of code expands all declared replace properties in the specified resource targets. -// A missing property will result in an error. Properties are expanded using ${} Groovy notation. -// When "copyIdeResources" is enabled, this will also run before the game launches in IDE environments. -// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html -tasks.named('processResources', ProcessResources).configure { - var replaceProperties = [ - minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range, - forge_version: forge_version, forge_version_range: forge_version_range, - loader_version_range: loader_version_range, - mod_id: mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, - mod_authors: mod_authors, mod_description: mod_description, - ] - inputs.properties replaceProperties - - filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) { - expand replaceProperties + [project: project] - } -} // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { diff --git a/gradle.properties b/gradle.properties index 440d6f1..5a12322 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,22 +3,22 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false -libzontreck=1.10.011524.0045 +libzontreck=1.10.011624.1712 ## Environment Properties # The Minecraft version must agree with the Forge version to get a valid artifact -minecraft_version=1.20.1 +minecraft_version=1.18.2 # 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.1,1.21) +minecraft_version_range=[1.18.2,1.19) # The Forge version must agree with the Minecraft version to get a valid artifact -forge_version=47.2.0 +forge_version=40.2.17 # The Forge version range can use any version of Forge as bounds or match the loader version range -forge_version_range=[47,) +forge_version_range=[40,) # The loader version range can only use the major version of Forge/FML as bounds -loader_version_range=[47,) +loader_version_range=[40,) # The mapping channel to use for mappings. # The default set of supported mapping channels are ["official", "snapshot", "snapshot_nodoc", "stable", "stable_nodoc"]. # Additional mapping channels can be registered through the "channelProviders" extension in a Gradle plugin. @@ -36,7 +36,7 @@ loader_version_range=[47,) mapping_channel=parchment # The mapping version to query from the mapping channel. # This must match the format required by the mapping channel. -mapping_version=2023.09.03-1.20.1 +mapping_version=2022.11.06-1.18.2 ## Mod Properties @@ -49,7 +49,7 @@ mod_name=Aria's Essentials # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=GPLv3 # The mod version. See https://semver.org/ -mod_version=1.2.011524.2039 +mod_version=1.2.011624.1834 # 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 37aef8d..81b8f92 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.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index 4e8d059..7f4682f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,8 +3,4 @@ pluginManagement { gradlePluginPortal() maven { url = "https://maven.zontreck.com/repository/internal" } } -} - -plugins { - id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0' } \ No newline at end of file diff --git a/src/main/java/dev/zontreck/essentials/AriasEssentials.java b/src/main/java/dev/zontreck/essentials/AriasEssentials.java index 93825ec..dd077aa 100644 --- a/src/main/java/dev/zontreck/essentials/AriasEssentials.java +++ b/src/main/java/dev/zontreck/essentials/AriasEssentials.java @@ -25,7 +25,6 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.event.RegisterKeyMappingsEvent; import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; @@ -145,13 +144,6 @@ public class AriasEssentials { MinecraftForge.EVENT_BUS.register(new HeartsRenderer()); } - @OnlyIn(Dist.CLIENT) - @SubscribeEvent - public static void onRegisterKeyBinds(RegisterKeyMappingsEvent ev) - { - ev.register(Keybindings.AUTOWALK); - } - } } diff --git a/src/main/java/dev/zontreck/essentials/client/AutoWalk.java b/src/main/java/dev/zontreck/essentials/client/AutoWalk.java index 616feca..1774472 100644 --- a/src/main/java/dev/zontreck/essentials/client/AutoWalk.java +++ b/src/main/java/dev/zontreck/essentials/client/AutoWalk.java @@ -11,6 +11,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import java.time.Instant; +import java.util.UUID; @OnlyIn(Dist.CLIENT) @Mod.EventBusSubscriber(modid = AriasEssentials.MODID, value = Dist.CLIENT) @@ -21,7 +22,7 @@ public class AutoWalk { static long lastPress; @SubscribeEvent - public static void onKeyPress(InputEvent.Key event) { + public static void onKeyPress(InputEvent.KeyInputEvent event) { if(Keybindings.AUTOWALK.matches(event.getKey(), event.getScanCode()) && Minecraft.getInstance().screen == null && Keybindings.AUTOWALK.isDown()) { lastPress = Instant.now().getEpochSecond(); @@ -35,10 +36,10 @@ public class AutoWalk { private static void startWalking() { isWalking=true; - autoJump = Minecraft.getInstance().options.autoJump().get(); - Minecraft.getInstance().options.autoJump().set(true); + autoJump = Minecraft.getInstance().options.autoJump; + Minecraft.getInstance().options.autoJump = true; - Minecraft.getInstance().player.sendSystemMessage(ChatHelpers.macro(Messages.ESSENTIALS_PREFIX + "!Dark_Green!AutoWalking started")); + Minecraft.getInstance().player.sendMessage(ChatHelpers.macro(Messages.ESSENTIALS_PREFIX + "!Dark_Green!AutoWalking started"), new UUID(0,0)); runner = new Thread(()->{ while(AutoWalk.isWalking) @@ -54,10 +55,10 @@ public class AutoWalk { isWalking=false; runner.interrupt(); runner=null; - Minecraft.getInstance().options.autoJump().set(autoJump); + Minecraft.getInstance().options.autoJump = autoJump; Minecraft.getInstance().options.keyUp.setDown(false); - Minecraft.getInstance().player.sendSystemMessage(ChatHelpers.macro(Messages.ESSENTIALS_PREFIX + "!Dark_Green!AutoWalking stopped")); + Minecraft.getInstance().player.sendMessage(ChatHelpers.macro(Messages.ESSENTIALS_PREFIX + "!Dark_Green!AutoWalking stopped"), new UUID(0,0)); } } diff --git a/src/main/java/dev/zontreck/essentials/client/Keybindings.java b/src/main/java/dev/zontreck/essentials/client/Keybindings.java index 612567f..cad9a55 100644 --- a/src/main/java/dev/zontreck/essentials/client/Keybindings.java +++ b/src/main/java/dev/zontreck/essentials/client/Keybindings.java @@ -5,8 +5,9 @@ import com.mojang.blaze3d.platform.InputConstants; import net.minecraft.client.KeyMapping; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.event.RegisterKeyMappingsEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.registries.DeferredRegister; +import net.minecraftforge.registries.ForgeRegistries; @OnlyIn(Dist.CLIENT) public class Keybindings { @@ -19,11 +20,5 @@ public class Keybindings { final KeyMapping key = new KeyMapping(name, keycode, category); return key; } - - @SubscribeEvent - public static void registerKeyMappings(RegisterKeyMappingsEvent event) - { - event.register(AUTOWALK); - } } diff --git a/src/main/java/dev/zontreck/essentials/commands/gui/HeartsCommand.java b/src/main/java/dev/zontreck/essentials/commands/gui/HeartsCommand.java index 9850a6e..cbd8e60 100644 --- a/src/main/java/dev/zontreck/essentials/commands/gui/HeartsCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/gui/HeartsCommand.java @@ -2,6 +2,7 @@ package dev.zontreck.essentials.commands.gui; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.events.CommandExecutionEvent; import dev.zontreck.essentials.networking.ModMessages; @@ -9,6 +10,7 @@ import dev.zontreck.essentials.networking.packets.s2c.S2CUpdateHearts; import dev.zontreck.libzontreck.util.ChatHelpers; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; +import net.minecraft.server.level.ServerPlayer; import net.minecraftforge.common.MinecraftForge; public class HeartsCommand @@ -20,24 +22,31 @@ public class HeartsCommand private static int hearts(CommandSourceStack stack, boolean compressHearts) { - var exec = new CommandExecutionEvent(stack.getPlayer(), "hearts"); + + ServerPlayer player = null; + try { + player = stack.getPlayerOrException(); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } + var exec = new CommandExecutionEvent(player, "hearts"); if(MinecraftForge.EVENT_BUS.post(exec)) { return 0; } // Send the state to the client, then update the config // Send feedback to the user - ChatHelpers.broadcastTo(stack.getPlayer().getUUID(), ChatHelpers.macro(Messages.HEARTS_UPDATED), stack.getServer()); + ChatHelpers.broadcastTo(player.getUUID(), ChatHelpers.macro(Messages.HEARTS_UPDATED), stack.getServer()); S2CUpdateHearts update = new S2CUpdateHearts(compressHearts); - ModMessages.sendToPlayer(update, stack.getPlayer()); + ModMessages.sendToPlayer(update, player); return 0; } private static int usage(CommandSourceStack stack) { - ChatHelpers.broadcastTo(stack.getPlayer().getUUID(), ChatHelpers.macro(Messages.HEARTS_USAGE), stack.getServer()); + ChatHelpers.broadcastTo(stack.getEntity().getUUID(), ChatHelpers.macro(Messages.HEARTS_USAGE), stack.getServer()); return 0; diff --git a/src/main/java/dev/zontreck/essentials/commands/homes/DelHomeCommand.java b/src/main/java/dev/zontreck/essentials/commands/homes/DelHomeCommand.java index 41ba7fa..8e24648 100644 --- a/src/main/java/dev/zontreck/essentials/commands/homes/DelHomeCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/homes/DelHomeCommand.java @@ -3,6 +3,7 @@ package dev.zontreck.essentials.commands.homes; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.zontreck.essentials.AriasEssentials; import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.events.CommandExecutionEvent; @@ -36,7 +37,12 @@ public class DelHomeCommand { private static int rmHome(CommandSourceStack ctx, String homeName) { - var exec = new CommandExecutionEvent(ctx.getPlayer(), "delhome"); + CommandExecutionEvent exec = null; + try { + exec = new CommandExecutionEvent(ctx.getPlayerOrException(), "delhome"); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } if(MinecraftForge.EVENT_BUS.post(exec)) { return 0; diff --git a/src/main/java/dev/zontreck/essentials/commands/homes/HomeCommand.java b/src/main/java/dev/zontreck/essentials/commands/homes/HomeCommand.java index 7ef3328..da9b6cc 100644 --- a/src/main/java/dev/zontreck/essentials/commands/homes/HomeCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/homes/HomeCommand.java @@ -33,7 +33,12 @@ public class HomeCommand { private static int home(CommandSourceStack ctx, String homeName) { - var exec = new CommandExecutionEvent(ctx.getPlayer(), "home"); + CommandExecutionEvent exec = null; + try { + exec = new CommandExecutionEvent(ctx.getPlayerOrException(), "home"); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } if(MinecraftForge.EVENT_BUS.post(exec)) { return 0; diff --git a/src/main/java/dev/zontreck/essentials/commands/homes/HomesCommand.java b/src/main/java/dev/zontreck/essentials/commands/homes/HomesCommand.java index 36dbf9a..b87baa8 100644 --- a/src/main/java/dev/zontreck/essentials/commands/homes/HomesCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/homes/HomesCommand.java @@ -60,7 +60,7 @@ public class HomesCommand { { stack = new ItemStack(Items.GRASS_BLOCK, 1); } - stack.setHoverName(Component.literal(string.homeName)); + stack.setHoverName(ChatHelpers.macro(string.homeName)); ChestGUIButton button = new ChestGUIButton(stack, (stackx, container, lore)-> { diff --git a/src/main/java/dev/zontreck/essentials/commands/homes/SetHomeCommand.java b/src/main/java/dev/zontreck/essentials/commands/homes/SetHomeCommand.java index 47f6ca5..3dc55d7 100644 --- a/src/main/java/dev/zontreck/essentials/commands/homes/SetHomeCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/homes/SetHomeCommand.java @@ -42,7 +42,12 @@ public class SetHomeCommand { private static int setHome(CommandSourceStack ctx, String homeName) { - var exec = new CommandExecutionEvent(ctx.getPlayer(), "sethome"); + CommandExecutionEvent exec = null; + try { + exec = new CommandExecutionEvent(ctx.getPlayerOrException(), "sethome"); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } if(MinecraftForge.EVENT_BUS.post(exec)) { return 0; @@ -58,7 +63,7 @@ public class SetHomeCommand { p = ctx.getPlayerOrException(); - if(TeleportActioner.isBlacklistedDimension(p.serverLevel())) + if(TeleportActioner.isBlacklistedDimension(p.getLevel())) { ChatHelpers.broadcastTo(p, ChatHelpers.macro(Messages.ESSENTIALS_PREFIX + AEServerConfig.getInstance().messages.BlacklistedDimensionError), p.server); @@ -68,9 +73,9 @@ public class SetHomeCommand { Vec3 position = p.position(); Vec2 rot = p.getRotationVector(); - TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.serverLevel()); + TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel()); - Home newhome = new Home(p, homeName, dest, new ItemStack(p.getBlockStateOn().getBlock().asItem())); + Home newhome = new Home(p, homeName, dest, new ItemStack(p.getFeetBlockState().getBlock().asItem())); AriasEssentials.player_homes.get(p.getUUID()).add(newhome); diff --git a/src/main/java/dev/zontreck/essentials/commands/teleport/BackCommand.java b/src/main/java/dev/zontreck/essentials/commands/teleport/BackCommand.java index c513f5a..c5185ac 100644 --- a/src/main/java/dev/zontreck/essentials/commands/teleport/BackCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/teleport/BackCommand.java @@ -1,6 +1,7 @@ package dev.zontreck.essentials.commands.teleport; import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.configs.server.AEServerConfig; import dev.zontreck.essentials.events.CommandExecutionEvent; @@ -20,7 +21,12 @@ public class BackCommand public static int back(CommandSourceStack ctx) { - var exec = new CommandExecutionEvent(ctx.getPlayer(), "back"); + CommandExecutionEvent exec = null; + try { + exec = new CommandExecutionEvent(ctx.getPlayerOrException(), "back"); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } if(MinecraftForge.EVENT_BUS.post(exec)) { return 0; @@ -28,20 +34,20 @@ public class BackCommand try { if(!AEServerConfig.getInstance().back.Enabled && !ctx.hasPermission(ctx.getServer().getOperatorUserPermissionLevel())) { - ChatHelpers.broadcastTo(ctx.getPlayer(), ChatHelpers.macro(Messages.TELEPORT_BACK_DISABLED), ctx.getServer()); + ChatHelpers.broadcastTo(ctx.getPlayerOrException(), ChatHelpers.macro(Messages.TELEPORT_BACK_DISABLED), ctx.getServer()); return 0; } - WorldPosition wp = BackPositionCaches.Pop(ctx.getPlayer().getUUID()); + WorldPosition wp = BackPositionCaches.Pop(ctx.getPlayerOrException().getUUID()); - ChatHelpers.broadcastTo(ctx.getPlayer(), ChatHelpers.macro(Messages.TELEPORT_BACK), ctx.getServer()); + ChatHelpers.broadcastTo(ctx.getPlayerOrException(), ChatHelpers.macro(Messages.TELEPORT_BACK), ctx.getServer()); - TeleportContainer cont = new TeleportContainer(ctx.getPlayer(), wp.Position.asMinecraftVector(), ctx.getRotation(), wp.getActualDimension()); + TeleportContainer cont = new TeleportContainer(ctx.getPlayerOrException(), wp.Position.asMinecraftVector(), ctx.getRotation(), wp.getActualDimension()); - TeleportActioner.ApplyTeleportEffect(ctx.getPlayer()); + TeleportActioner.ApplyTeleportEffect(ctx.getPlayerOrException()); TeleportActioner.PerformTeleport(cont, true); } catch (Exception e) { - ChatHelpers.broadcastTo(ctx.getPlayer(), ChatHelpers.macro(Messages.NO_BACK), ctx.getServer()); + ChatHelpers.broadcastTo(ctx.getEntity().getUUID(), ChatHelpers.macro(Messages.NO_BACK), ctx.getServer()); } return 0; } diff --git a/src/main/java/dev/zontreck/essentials/commands/teleport/RTPCommand.java b/src/main/java/dev/zontreck/essentials/commands/teleport/RTPCommand.java index bbaeee0..d27174b 100644 --- a/src/main/java/dev/zontreck/essentials/commands/teleport/RTPCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/teleport/RTPCommand.java @@ -2,6 +2,7 @@ package dev.zontreck.essentials.commands.teleport; import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.zontreck.essentials.events.CommandExecutionEvent; import dev.zontreck.essentials.rtp.RandomPositionFactory; import net.minecraft.commands.CommandSourceStack; @@ -27,7 +28,12 @@ public class RTPCommand { private static int rtp(CommandSourceStack source) { - var exec = new CommandExecutionEvent(source.getPlayer(), "rtp"); + CommandExecutionEvent exec = null; + try { + exec = new CommandExecutionEvent(source.getPlayerOrException(), "rtp"); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } if(MinecraftForge.EVENT_BUS.post(exec)) { return 0; @@ -58,7 +64,7 @@ public class RTPCommand { Vec3 pos = pla.position(); //boolean found_place= false; - RandomPositionFactory.beginRTP(pla, pla.serverLevel()); + RandomPositionFactory.beginRTP(pla, pla.getLevel()); } diff --git a/src/main/java/dev/zontreck/essentials/commands/teleport/SpawnCommand.java b/src/main/java/dev/zontreck/essentials/commands/teleport/SpawnCommand.java index 009a381..a17f712 100644 --- a/src/main/java/dev/zontreck/essentials/commands/teleport/SpawnCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/teleport/SpawnCommand.java @@ -2,6 +2,7 @@ package dev.zontreck.essentials.commands.teleport; import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.events.CommandExecutionEvent; import dev.zontreck.libzontreck.util.ChatHelpers; @@ -27,7 +28,12 @@ public class SpawnCommand { private static int respawn(CommandSourceStack source) { - var exec = new CommandExecutionEvent(source.getPlayer(), "spawn"); + CommandExecutionEvent exec = null; + try { + exec = new CommandExecutionEvent(source.getPlayerOrException(), "spawn"); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } if(MinecraftForge.EVENT_BUS.post(exec)) { return 0; @@ -36,10 +42,10 @@ public class SpawnCommand { ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(Messages.RESPAWNING), p.server); - BlockPos spawn = p.serverLevel().getSharedSpawnPos(); + BlockPos spawn = p.getLevel().getSharedSpawnPos(); TeleportActioner.ApplyTeleportEffect(p); - TeleportContainer cont = new TeleportContainer(p, new Vec3(spawn.getX(), spawn.getY(), spawn.getZ()), Vec2.ZERO, p.serverLevel()); + TeleportContainer cont = new TeleportContainer(p, new Vec3(spawn.getX(), spawn.getY(), spawn.getZ()), Vec2.ZERO, p.getLevel()); TeleportActioner.PerformTeleport(cont, false); diff --git a/src/main/java/dev/zontreck/essentials/commands/teleport/TPACommand.java b/src/main/java/dev/zontreck/essentials/commands/teleport/TPACommand.java index e2bf5d4..ebe30fe 100644 --- a/src/main/java/dev/zontreck/essentials/commands/teleport/TPACommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/teleport/TPACommand.java @@ -2,6 +2,7 @@ package dev.zontreck.essentials.commands.teleport; import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.zontreck.ariaslib.terminal.Task; import dev.zontreck.ariaslib.util.DelayedExecutorService; import dev.zontreck.essentials.Messages; @@ -37,7 +38,12 @@ public class TPACommand { private static int tpa(CommandSourceStack source, ServerPlayer serverPlayer) { - var exec = new CommandExecutionEvent(source.getPlayer(), "tpa"); + CommandExecutionEvent exec = null; + try { + exec = new CommandExecutionEvent(source.getPlayerOrException(), "tpa"); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } if(MinecraftForge.EVENT_BUS.post(exec)) { return 0; @@ -118,7 +124,7 @@ public class TPACommand { private static int usage(CommandSourceStack source) { - source.sendSystemMessage(ChatHelpers.macro("/tpa USAGE\n\n "+ChatColor.BOLD + ChatColor.DARK_GRAY+"/tpa "+ChatColor.DARK_RED+"target_player\n")); + ChatHelpers.broadcastTo(source.getEntity().getUUID(), ChatHelpers.macro("/tpa USAGE\n\n "+ChatColor.BOLD + ChatColor.DARK_GRAY+"/tpa "+ChatColor.DARK_RED+"target_player\n"), source.getServer()); return 0; } } diff --git a/src/main/java/dev/zontreck/essentials/commands/teleport/TPAHereCommand.java b/src/main/java/dev/zontreck/essentials/commands/teleport/TPAHereCommand.java index 0c95e0b..0305739 100644 --- a/src/main/java/dev/zontreck/essentials/commands/teleport/TPAHereCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/teleport/TPAHereCommand.java @@ -2,6 +2,7 @@ package dev.zontreck.essentials.commands.teleport; import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.zontreck.ariaslib.terminal.Task; import dev.zontreck.ariaslib.util.DelayedExecutorService; import dev.zontreck.essentials.Messages; @@ -33,7 +34,12 @@ public class TPAHereCommand { private static int tpa(CommandSourceStack source, ServerPlayer serverPlayer) { - var exec = new CommandExecutionEvent(source.getPlayer(), "tpahere"); + CommandExecutionEvent exec = null; + try { + exec = new CommandExecutionEvent(source.getPlayerOrException(), "tpahere"); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } if(MinecraftForge.EVENT_BUS.post(exec)) { return 0; @@ -114,7 +120,7 @@ public class TPAHereCommand { } private static int usage(CommandSourceStack source) { - source.sendSystemMessage(ChatHelpers.macro("/tpahere USAGE\n\n !Bold!!Dark_Gray!/tpahere !Dark_Red!target_player\n")); + ChatHelpers.broadcastTo(source.getEntity().getUUID(), ChatHelpers.macro("/tpahere USAGE\n\n !Bold!!Dark_Gray!/tpahere !Dark_Red!target_player\n"), source.getServer()); return 0; } } diff --git a/src/main/java/dev/zontreck/essentials/commands/teleport/TPAcceptCommand.java b/src/main/java/dev/zontreck/essentials/commands/teleport/TPAcceptCommand.java index 1748496..685d320 100644 --- a/src/main/java/dev/zontreck/essentials/commands/teleport/TPAcceptCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/teleport/TPAcceptCommand.java @@ -6,6 +6,7 @@ import java.util.UUID; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.events.CommandExecutionEvent; import dev.zontreck.libzontreck.chat.ChatColor; @@ -25,7 +26,12 @@ public class TPAcceptCommand { private static int doAccept(CommandSourceStack source, String TPID) { - var exec = new CommandExecutionEvent(source.getPlayer(), "tpaccept"); + CommandExecutionEvent exec = null; + try { + exec = new CommandExecutionEvent(source.getPlayerOrException(), "tpaccept"); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } if(MinecraftForge.EVENT_BUS.post(exec)) { return 0; @@ -54,7 +60,7 @@ public class TPAcceptCommand { cont.PlayerInst = from; cont.Position = to.position(); cont.Rotation = to.getRotationVector(); - cont.Dimension = to.serverLevel(); + cont.Dimension = to.getLevel(); TeleportActioner.ApplyTeleportEffect(from); TeleportActioner.PerformTeleport(cont, false); diff --git a/src/main/java/dev/zontreck/essentials/commands/teleport/TPEffectsCommand.java b/src/main/java/dev/zontreck/essentials/commands/teleport/TPEffectsCommand.java index a5b9651..2120ba8 100644 --- a/src/main/java/dev/zontreck/essentials/commands/teleport/TPEffectsCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/teleport/TPEffectsCommand.java @@ -2,6 +2,7 @@ package dev.zontreck.essentials.commands.teleport; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.zontreck.libzontreck.chestgui.ChestGUI; import dev.zontreck.libzontreck.chestgui.ChestGUIButton; import dev.zontreck.libzontreck.chestgui.ChestGUIIdentifier; @@ -25,7 +26,12 @@ public class TPEffectsCommand public static int tpeffects(CommandSourceStack source, boolean enabled) { - ServerPlayer player = source.getPlayer(); + ServerPlayer player = null; + try { + player = source.getPlayerOrException(); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } try { Profile prof = Profile.get_profile_of(player.getStringUUID()); diff --git a/src/main/java/dev/zontreck/essentials/commands/teleport/TeleportActioner.java b/src/main/java/dev/zontreck/essentials/commands/teleport/TeleportActioner.java index e4a0546..479af41 100644 --- a/src/main/java/dev/zontreck/essentials/commands/teleport/TeleportActioner.java +++ b/src/main/java/dev/zontreck/essentials/commands/teleport/TeleportActioner.java @@ -3,9 +3,10 @@ package dev.zontreck.essentials.commands.teleport; import dev.zontreck.ariaslib.util.DelayedExecutorService; import dev.zontreck.essentials.AriasEssentials; import dev.zontreck.essentials.configs.server.AEServerConfig; +import dev.zontreck.libzontreck.profiles.Profile; +import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException; import dev.zontreck.libzontreck.vectors.Vector3; import dev.zontreck.libzontreck.vectors.WorldPosition; -import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.commands.EffectCommands; import net.minecraft.server.level.ServerLevel; @@ -30,7 +31,16 @@ public class TeleportActioner } public static void ApplyTeleportEffect(ServerPlayer player){ - if(isBlacklistedDimension(player.serverLevel())){ + try { + Profile prof = Profile.get_profile_of(player.getStringUUID()); + if(!prof.NBT.getBoolean("tpeffects")) + { + return; + } + } catch (UserProfileNotYetExistsException e) { + throw new RuntimeException(e); + } + if(isBlacklistedDimension(player.getLevel())){ return; } // 10/05/2022 - Thinking ahead here to future proof it so i can do things in threads safely @@ -43,7 +53,7 @@ public class TeleportActioner for(int i = 0; i < effects.size(); i++) { RegistryObject effect = RegistryObject.create(new ResourceLocation(effects.get(i)), ForgeRegistries.MOB_EFFECTS); - int duration = AriasEssentials.random.nextInt(5, 10) * 20; + int duration = AriasEssentials.random.nextInt(2, 5) * 20; int amplifier = AriasEssentials.random.nextInt(1, 3); if (effects.get(i).equals("minecraft:slow_falling")) diff --git a/src/main/java/dev/zontreck/essentials/commands/warps/DelWarpCommand.java b/src/main/java/dev/zontreck/essentials/commands/warps/DelWarpCommand.java index f5a6b56..7a4abab 100644 --- a/src/main/java/dev/zontreck/essentials/commands/warps/DelWarpCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/warps/DelWarpCommand.java @@ -3,6 +3,7 @@ package dev.zontreck.essentials.commands.warps; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.events.CommandExecutionEvent; import dev.zontreck.essentials.warps.NoSuchWarpException; @@ -29,7 +30,12 @@ public class DelWarpCommand { private static int setWarp(CommandSourceStack source, String string) { - var exec = new CommandExecutionEvent(source.getPlayer(), "delwarp"); + CommandExecutionEvent exec = null; + try { + exec = new CommandExecutionEvent(source.getPlayerOrException(), "delwarp"); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } if(MinecraftForge.EVENT_BUS.post(exec)) { return 0; diff --git a/src/main/java/dev/zontreck/essentials/commands/warps/RTPWarpCommand.java b/src/main/java/dev/zontreck/essentials/commands/warps/RTPWarpCommand.java index 56ca832..b314014 100644 --- a/src/main/java/dev/zontreck/essentials/commands/warps/RTPWarpCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/warps/RTPWarpCommand.java @@ -7,6 +7,7 @@ import java.sql.SQLException; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.commands.teleport.TeleportDestination; import dev.zontreck.essentials.events.CommandExecutionEvent; @@ -40,7 +41,12 @@ public class RTPWarpCommand { private static int setWarp(CommandSourceStack source, String string) { - var exec = new CommandExecutionEvent(source.getPlayer(), "setwarp"); + CommandExecutionEvent exec = null; + try { + exec = new CommandExecutionEvent(source.getPlayerOrException(), "setwarp"); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } if(MinecraftForge.EVENT_BUS.post(exec)) { return 0; @@ -50,8 +56,8 @@ public class RTPWarpCommand { Vec3 position = p.position(); Vec2 rot = p.getRotationVector(); - TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.serverLevel()); - Warp warp = new Warp(p.getUUID(), string, true, true, dest, new ItemStack(p.getBlockStateOn().getBlock().asItem())); + TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel()); + Warp warp = new Warp(p.getUUID(), string, true, true, dest, new ItemStack(p.getFeetBlockState().getBlock().asItem())); WarpCreatedEvent event = new WarpCreatedEvent(warp); if(MinecraftForge.EVENT_BUS.post(event)) { diff --git a/src/main/java/dev/zontreck/essentials/commands/warps/SetWarpCommand.java b/src/main/java/dev/zontreck/essentials/commands/warps/SetWarpCommand.java index c6efdac..85ab64d 100644 --- a/src/main/java/dev/zontreck/essentials/commands/warps/SetWarpCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/warps/SetWarpCommand.java @@ -7,6 +7,7 @@ import java.sql.SQLException; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.commands.teleport.TeleportDestination; import dev.zontreck.essentials.events.CommandExecutionEvent; @@ -40,7 +41,12 @@ public class SetWarpCommand { private static int setWarp(CommandSourceStack source, String string) { - var exec = new CommandExecutionEvent(source.getPlayer(), "setwarp"); + CommandExecutionEvent exec = null; + try { + exec = new CommandExecutionEvent(source.getPlayerOrException(), "setwarp"); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } if(MinecraftForge.EVENT_BUS.post(exec)) { return 0; @@ -51,8 +57,8 @@ public class SetWarpCommand { Vec3 position = p.position(); Vec2 rot = p.getRotationVector(); - TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.serverLevel()); - Warp w = new Warp(p.getUUID(), string, false, true, dest, new ItemStack(p.getBlockStateOn().getBlock().asItem())); + TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel()); + Warp w = new Warp(p.getUUID(), string, false, true, dest, new ItemStack(p.getFeetBlockState().getBlock().asItem())); WarpCreatedEvent event = new WarpCreatedEvent(w); if(MinecraftForge.EVENT_BUS.post(event)){ ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(Messages.WARP_CREATE_ERROR, event.denyReason), p.server); diff --git a/src/main/java/dev/zontreck/essentials/commands/warps/WarpCommand.java b/src/main/java/dev/zontreck/essentials/commands/warps/WarpCommand.java index ffc3d39..604bf83 100644 --- a/src/main/java/dev/zontreck/essentials/commands/warps/WarpCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/warps/WarpCommand.java @@ -64,7 +64,7 @@ public class WarpCommand { if(type==1){ try { - var exec = new CommandExecutionEvent(source.getPlayer(), "rtp"); + var exec = new CommandExecutionEvent(source.getPlayerOrException(), "rtp"); if(MinecraftForge.EVENT_BUS.post(exec)) { return; @@ -78,7 +78,12 @@ public class WarpCommand { } } - var exec = new CommandExecutionEvent(source.getPlayer(), "warp"); + CommandExecutionEvent exec = null; + try { + exec = new CommandExecutionEvent(source.getPlayerOrException(), "warp"); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } if(MinecraftForge.EVENT_BUS.post(exec)) { return; diff --git a/src/main/java/dev/zontreck/essentials/configs/server/AEServerConfig.java b/src/main/java/dev/zontreck/essentials/configs/server/AEServerConfig.java index eccbca5..db386ce 100644 --- a/src/main/java/dev/zontreck/essentials/configs/server/AEServerConfig.java +++ b/src/main/java/dev/zontreck/essentials/configs/server/AEServerConfig.java @@ -87,7 +87,7 @@ public class AEServerConfig back = new Back(); teleport = new Teleportation(); teleport.Effects = Lists.of( - "minecraft:darkness", + "minecraft:blindness", "minecraft:levitation", "minecraft:slow_falling", "minecraft:hunger" diff --git a/src/main/java/dev/zontreck/essentials/gui/HeartsRenderer.java b/src/main/java/dev/zontreck/essentials/gui/HeartsRenderer.java index d8df687..9854b7d 100644 --- a/src/main/java/dev/zontreck/essentials/gui/HeartsRenderer.java +++ b/src/main/java/dev/zontreck/essentials/gui/HeartsRenderer.java @@ -17,7 +17,7 @@ import dev.zontreck.essentials.configs.client.AEClientConfig; import net.minecraft.Util; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.GuiComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import net.minecraft.world.effect.MobEffectInstance; @@ -28,10 +28,8 @@ import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.player.Player; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.event.RenderGuiOverlayEvent; -import net.minecraftforge.client.gui.overlay.ForgeGui; -import net.minecraftforge.client.gui.overlay.GuiOverlayManager; -import net.minecraftforge.client.gui.overlay.NamedGuiOverlay; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.client.gui.ForgeIngameGui; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -44,7 +42,7 @@ public class HeartsRenderer { "textures/gui/hearts.png"); private static final ResourceLocation ICON_ABSORB = new ResourceLocation(AriasEssentials.MODID, "textures/gui/absorb.png"); - private static final ResourceLocation ICON_VANILLA = Gui.GUI_ICONS_LOCATION; + private static final ResourceLocation ICON_VANILLA = GuiComponent.GUI_ICONS_LOCATION; private final Minecraft mc = Minecraft.getInstance(); @@ -67,8 +65,8 @@ public class HeartsRenderer { * @param width Width to draw * @param height Height to draw */ - private void blit(GuiGraphics matrixStack, int x, int y, int textureX, int textureY, int width, int height, ResourceLocation resource) { - matrixStack.blit(resource, x, y, textureX, textureY, width, height); + private void blit(PoseStack matrixStack, int x, int y, int textureX, int textureY, int width, int height) { + Minecraft.getInstance().gui.blit(matrixStack, x, y, textureX, textureY, width, height); } /* HUD */ @@ -79,28 +77,12 @@ public class HeartsRenderer { * @param event Event instance */ @SubscribeEvent(priority = EventPriority.LOW) - public void renderHealthbar(RenderGuiOverlayEvent.Pre event) { - NamedGuiOverlay ActualOverlay = GuiOverlayManager.findOverlay(new ResourceLocation("minecraft:player_health")); - - if (ActualOverlay == null) { - if (GuiOverlayManager.getOverlays() == null) { - AriasEssentials.LOGGER.info("Overlays non existent?!"); - } - for (NamedGuiOverlay overlay : GuiOverlayManager.getOverlays()) { - // Next print - // LibZontreck.LOGGER.info("GUI OVERLAY: "+overlay.id().getPath()); - - if (overlay.id().getPath().equals("player_health")) { - ActualOverlay = overlay; - break; - } - } - } - if (event.isCanceled() || !AEClientConfig.getInstance().EnableHearts || event.getOverlay() != ActualOverlay) { + public void renderHealthbar(RenderGameOverlayEvent.PreLayer event) { + if (event.isCanceled() || !AEClientConfig.getInstance().EnableHearts || event.getOverlay() != ForgeIngameGui.PLAYER_HEALTH_ELEMENT) { return; } // ensure its visible - if (!(mc.gui instanceof ForgeGui gui) || mc.options.hideGui || !gui.shouldDrawSurvivalElements()) { + if (!(mc.gui instanceof ForgeIngameGui gui) || mc.options.hideGui || !gui.shouldDrawSurvivalElements()) { return; } Entity renderViewEnity = this.mc.getCameraEntity(); @@ -112,7 +94,7 @@ public class HeartsRenderer { this.mc.getProfiler().push("health"); // extra setup stuff from us - int left_height = gui.leftHeight; + int left_height = gui.left_height; int width = this.mc.getWindow().getGuiScaledWidth(); int height = this.mc.getWindow().getGuiScaledHeight(); int updateCounter = this.mc.gui.getGuiTicks(); @@ -121,13 +103,13 @@ public class HeartsRenderer { // changes are indicated by comment int health = Mth.ceil(player.getHealth()); - boolean highlight = this.healthUpdateCounter > (long) updateCounter - && (this.healthUpdateCounter - (long) updateCounter) / 3L % 2L == 1L; + boolean highlight = this.healthUpdateCounter > (long) updateCounter && (this.healthUpdateCounter - (long) updateCounter) / 3L % 2L == 1L; if (health < this.playerHealth && player.invulnerableTime > 0) { this.lastSystemTime = Util.getMillis(); this.healthUpdateCounter = (updateCounter + 20); - } else if (health > this.playerHealth && player.invulnerableTime > 0) { + } + else if (health > this.playerHealth && player.invulnerableTime > 0) { this.lastSystemTime = Util.getMillis(); this.healthUpdateCounter = (updateCounter + 10); } @@ -145,8 +127,7 @@ public class HeartsRenderer { float healthMax = attrMaxHealth == null ? 0 : (float) attrMaxHealth.getValue(); float absorb = Mth.ceil(player.getAbsorptionAmount()); - // CHANGE: simulate 10 hearts max if there's more, so vanilla only renders one - // row max + // CHANGE: simulate 10 hearts max if there's more, so vanilla only renders one row max healthMax = Math.min(healthMax, 20f); health = Math.min(health, 20); absorb = Math.min(absorb, 20); @@ -158,10 +139,9 @@ public class HeartsRenderer { int left = width / 2 - 91; int top = height - left_height; - // change: these are unused below, unneeded? should these adjust the Forge - // variable? - // left_height += (healthRows * rowHeight); - // if (rowHeight != 10) left_height += 10 - rowHeight; + // change: these are unused below, unneeded? should these adjust the Forge variable? + //left_height += (healthRows * rowHeight); + //if (rowHeight != 10) left_height += 10 - rowHeight; this.regen = -1; if (player.hasEffect(MobEffects.REGENERATION)) { @@ -172,46 +152,46 @@ public class HeartsRenderer { final int TOP = 9 * (this.mc.level.getLevelData().isHardcore() ? 5 : 0); final int BACKGROUND = (highlight ? 25 : 16); int MARGIN = 16; - if (player.hasEffect(MobEffects.POISON)) - MARGIN += 36; - else if (player.hasEffect(MobEffects.WITHER)) - MARGIN += 72; + if (player.hasEffect(MobEffects.POISON)) MARGIN += 36; + else if (player.hasEffect(MobEffects.WITHER)) MARGIN += 72; float absorbRemaining = absorb; - GuiGraphics matrixStack = event.getGuiGraphics(); + PoseStack matrixStack = event.getMatrixStack(); for (int i = Mth.ceil((healthMax + absorb) / 2.0F) - 1; i >= 0; --i) { int row = Mth.ceil((float) (i + 1) / 10.0F) - 1; int x = left + i % 10 * 8; int y = top - row * rowHeight; - if (health <= 4) - y += this.rand.nextInt(2); - if (i == this.regen) - y -= 2; + if (health <= 4) y += this.rand.nextInt(2); + if (i == this.regen) y -= 2; - this.blit(matrixStack, x, y, BACKGROUND, TOP, 9, 9, ICON_VANILLA); + this.blit(matrixStack, x, y, BACKGROUND, TOP, 9, 9); if (highlight) { if (i * 2 + 1 < healthLast) { - this.blit(matrixStack, x, y, MARGIN + 54, TOP, 9, 9, ICON_VANILLA); // 6 - } else if (i * 2 + 1 == healthLast) { - this.blit(matrixStack, x, y, MARGIN + 63, TOP, 9, 9, ICON_VANILLA); // 7 + this.blit(matrixStack, x, y, MARGIN + 54, TOP, 9, 9); //6 + } + else if (i * 2 + 1 == healthLast) { + this.blit(matrixStack, x, y, MARGIN + 63, TOP, 9, 9); //7 } } if (absorbRemaining > 0.0F) { if (absorbRemaining == absorb && absorb % 2.0F == 1.0F) { - this.blit(matrixStack, x, y, MARGIN + 153, TOP, 9, 9, ICON_VANILLA); // 17 + this.blit(matrixStack, x, y, MARGIN + 153, TOP, 9, 9); //17 absorbRemaining -= 1.0F; - } else { - this.blit(matrixStack, x, y, MARGIN + 144, TOP, 9, 9, ICON_VANILLA); // 16 + } + else { + this.blit(matrixStack, x, y, MARGIN + 144, TOP, 9, 9); //16 absorbRemaining -= 2.0F; } - } else { + } + else { if (i * 2 + 1 < health) { - this.blit(matrixStack, x, y, MARGIN + 36, TOP, 9, 9, ICON_VANILLA); // 4 - } else if (i * 2 + 1 == health) { - this.blit(matrixStack, x, y, MARGIN + 45, TOP, 9, 9, ICON_VANILLA); // 5 + this.blit(matrixStack, x, y, MARGIN + 36, TOP, 9, 9); //4 + } + else if (i * 2 + 1 == health) { + this.blit(matrixStack, x, y, MARGIN + 45, TOP, 9, 9); //5 } } } @@ -220,23 +200,22 @@ public class HeartsRenderer { this.renderExtraAbsorption(matrixStack, left, top - rowHeight, player); RenderSystem.setShaderTexture(0, ICON_VANILLA); - gui.leftHeight += 10; + gui.left_height += 10; if (absorb > 0) { - gui.leftHeight += 10; + gui.left_height += 10; } event.setCanceled(true); RenderSystem.disableBlend(); this.mc.getProfiler().pop(); - MinecraftForge.EVENT_BUS - .post(new RenderGuiOverlayEvent.Post(mc.getWindow(), event.getGuiGraphics(), event.getPartialTick(), ActualOverlay)); + MinecraftForge.EVENT_BUS.post(new RenderGameOverlayEvent.PostLayer(matrixStack, event, ForgeIngameGui.PLAYER_HEALTH_ELEMENT)); } + /** * Gets the texture from potion effects - * - * @param player Player instance - * @return Texture offset for potion effects + * @param player Player instance + * @return Texture offset for potion effects */ private int getPotionOffset(Player player) { int potionOffset = 0; @@ -257,13 +236,12 @@ public class HeartsRenderer { /** * Renders the health above 10 hearts - * - * @param matrixStack Matrix stack instance - * @param xBasePos Health bar top corner - * @param yBasePos Health bar top corner - * @param player Player instance + * @param matrixStack Matrix stack instance + * @param xBasePos Health bar top corner + * @param yBasePos Health bar top corner + * @param player Player instance */ - private void renderExtraHearts(GuiGraphics matrixStack, int xBasePos, int yBasePos, Player player) { + private void renderExtraHearts(PoseStack matrixStack, int xBasePos, int yBasePos, Player player) { int potionOffset = this.getPotionOffset(player); // Extra hearts @@ -272,15 +250,15 @@ public class HeartsRenderer { this.renderCustomHearts(matrixStack, xBasePos, yBasePos, potionOffset, hp, false); } + /** * Renders the absorption health above 10 hearts - * - * @param matrixStack Matrix stack instance - * @param xBasePos Health bar top corner - * @param yBasePos Health bar top corner - * @param player Player instance + * @param matrixStack Matrix stack instance + * @param xBasePos Health bar top corner + * @param yBasePos Health bar top corner + * @param player Player instance */ - private void renderExtraAbsorption(GuiGraphics matrixStack, int xBasePos, int yBasePos, Player player) { + private void renderExtraAbsorption(PoseStack matrixStack, int xBasePos, int yBasePos, Player player) { int potionOffset = this.getPotionOffset(player); // Extra hearts @@ -291,9 +269,8 @@ public class HeartsRenderer { /** * Gets the texture offset from the regen effect - * - * @param i Heart index - * @param offset Current offset + * @param i Heart index + * @param offset Current offset */ private int getYRegenOffset(int i, int offset) { return i + offset == this.regen ? -2 : 0; @@ -301,7 +278,6 @@ public class HeartsRenderer { /** * Shared logic to render custom hearts - * * @param matrixStack Matrix stack instance * @param xBasePos Health bar top corner * @param yBasePos Health bar top corner @@ -309,8 +285,7 @@ public class HeartsRenderer { * @param count Number to render * @param absorb If true, render absorption hearts */ - private void renderCustomHearts(GuiGraphics matrixStack, int xBasePos, int yBasePos, int potionOffset, int count, - boolean absorb) { + private void renderCustomHearts(PoseStack matrixStack, int xBasePos, int yBasePos, int potionOffset, int count, boolean absorb) { int regenOffset = absorb ? 10 : 0; for (int iter = 0; iter < count / 20; iter++) { int renderHearts = (count - 20 * (iter + 1)) / 2; @@ -321,16 +296,16 @@ public class HeartsRenderer { for (int i = 0; i < renderHearts; i++) { int y = this.getYRegenOffset(i, regenOffset); if (absorb) { - this.blit(matrixStack, xBasePos + 8 * i, yBasePos + y, 0, 54, 9, 9, ICON_ABSORB); + this.blit(matrixStack, xBasePos + 8 * i, yBasePos + y, 0, 54, 9, 9); } - this.blit(matrixStack, xBasePos + 8 * i, yBasePos + y, 18 * heartIndex, potionOffset, 9, 9, ICON_HEARTS); + this.blit(matrixStack, xBasePos + 8 * i, yBasePos + y, 18 * heartIndex, potionOffset, 9, 9); } if (count % 2 == 1 && renderHearts < 10) { int y = this.getYRegenOffset(renderHearts, regenOffset); if (absorb) { - this.blit(matrixStack, xBasePos + 8 * renderHearts, yBasePos + y, 0, 54, 9, 9, ICON_ABSORB); + this.blit(matrixStack, xBasePos + 8 * renderHearts, yBasePos + y, 0, 54, 9, 9); } - this.blit(matrixStack, xBasePos + 8 * renderHearts, yBasePos + y, 9 + 18 * heartIndex, potionOffset, 9, 9, ICON_HEARTS); + this.blit(matrixStack, xBasePos + 8 * renderHearts, yBasePos + y, 9 + 18 * heartIndex, potionOffset, 9, 9); } } } diff --git a/src/main/java/dev/zontreck/essentials/homes/HomesSuggestionProvider.java b/src/main/java/dev/zontreck/essentials/homes/HomesSuggestionProvider.java index 63629d9..e7f098a 100644 --- a/src/main/java/dev/zontreck/essentials/homes/HomesSuggestionProvider.java +++ b/src/main/java/dev/zontreck/essentials/homes/HomesSuggestionProvider.java @@ -16,7 +16,7 @@ import java.util.concurrent.CompletableFuture; public class HomesSuggestionProvider { public static SuggestionProvider PROVIDER = (ctx,suggestionsBuilder)->{ - Homes homes = HomesProvider.getHomesForPlayer(ctx.getSource().getPlayer().getUUID().toString()); + Homes homes = HomesProvider.getHomesForPlayer(ctx.getSource().getPlayerOrException().getUUID().toString()); List homesList = new ArrayList<>(); diff --git a/src/main/java/dev/zontreck/essentials/networking/ModMessages.java b/src/main/java/dev/zontreck/essentials/networking/ModMessages.java index 410904f..dd3a5ef 100644 --- a/src/main/java/dev/zontreck/essentials/networking/ModMessages.java +++ b/src/main/java/dev/zontreck/essentials/networking/ModMessages.java @@ -30,10 +30,10 @@ public class ModMessages { net.messageBuilder(S2CUpdateHearts.class, id(), NetworkDirection.PLAY_TO_CLIENT) - .decoder(S2CUpdateHearts::new) - .encoder(S2CUpdateHearts::toBytes) - .consumerMainThread(S2CUpdateHearts::handle) - .add(); + .decoder(S2CUpdateHearts::new) + .encoder(S2CUpdateHearts::toBytes) + .consumer(S2CUpdateHearts::handle) + .add(); } diff --git a/src/main/java/dev/zontreck/essentials/rtp/RTPCachesEventHandlers.java b/src/main/java/dev/zontreck/essentials/rtp/RTPCachesEventHandlers.java index 68a5260..a837ebd 100644 --- a/src/main/java/dev/zontreck/essentials/rtp/RTPCachesEventHandlers.java +++ b/src/main/java/dev/zontreck/essentials/rtp/RTPCachesEventHandlers.java @@ -4,7 +4,9 @@ import dev.zontreck.essentials.AriasEssentials; import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.commands.teleport.TeleportActioner; import dev.zontreck.essentials.events.RTPFoundEvent; +import dev.zontreck.libzontreck.LibZontreck; import dev.zontreck.libzontreck.util.ChatHelpers; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.TickEvent; @@ -19,6 +21,7 @@ public class RTPCachesEventHandlers { if(!AriasEssentials.ALIVE) return; lastTick++; + MinecraftServer server = LibZontreck.THE_SERVER; if(lastTick>=400) { lastTick=0; @@ -31,7 +34,7 @@ public class RTPCachesEventHandlers firstRun=false; AriasEssentials.LOGGER.info("Aria's Essentials startup is running. Scanning for initial RTP locations"); - for(ServerLevel level : event.getServer().getAllLevels()) + for(ServerLevel level : server.getAllLevels()) { if(AriasEssentials.DEBUG) { diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index b4796c8..e69de29 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -1,5 +0,0 @@ -public net.minecraft.client.gui.Gui -public net.minecraft.client.gui.Gui f_279580_ # GUI_ICONS_LOCATION -public net.minecraft.client.gui.Gui f_92974_ # displayHealth -public net.minecraft.client.gui.Gui f_92973_ # lastHealth -public net.minecraft.client.gui.Gui f_92976_ # healthBlinkTime \ No newline at end of file diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index fd59e36..f71a626 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -6,71 +6,67 @@ # The name of the mod loader type to load - for regular FML @Mod mods it should be javafml modLoader="javafml" #mandatory # A version range to match for said mod loader - for regular FML @Mod it will be the forge version -loaderVersion="${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. +loaderVersion="[40,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. # The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties. # Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here. -license="${mod_license}" +license="GPLv3" # A URL to refer people to when problems occur with this mod -issueTrackerURL="https://github.com/zontreck/Arias-Essentials/issues/" #optional +#issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional # A list of mods - how many allowed here is determined by the individual mod loader [[mods]] #mandatory # The modid of the mod -modId="${mod_id}" #mandatory -# The version number of the mod -version="${mod_version}" #mandatory +modId="ariasessentials" #mandatory +# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it +# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata +# see the associated build.gradle script for how to populate this completely automatically during a build +version="${file.jarVersion}" #mandatory # A display name for the mod -displayName="${mod_name}" #mandatory -# A URL to query for updates for this mod. See the JSON update specification https://docs.minecraftforge.net/en/latest/misc/updatechecker/ +displayName="Aria's Essentials" #mandatory +# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/ #updateJSONURL="https://change.me.example.invalid/updates.json" #optional # A URL for the "homepage" for this mod, displayed in the mod UI #displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional # A file name (in the root of the mod JAR) containing a logo for display logoFile="ariasessentials.png" #optional # A text field displayed in the mod UI -#credits="" #optional +credits="Thanks for this example mod goes to Java" #optional # A text field displayed in the mod UI -authors="${mod_authors}" #optional +authors="Love, Cheese and small house plants" #optional # Display Test controls the display for your mod in the server connection screen # MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod. # IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod. # IGNORE_ALL_VERSION means that your mod will not cause a red X if it's present on the client or the server. This is a special case and should only be used if your mod has no server component. # NONE means that no display test is set on your mod. You need to do this yourself, see IExtensionPoint.DisplayTest for more information. You can define any scheme you wish with this value. # IMPORTANT NOTE: this is NOT an instruction as to which environments (CLIENT or DEDICATED SERVER) your mod loads on. Your mod should load (and maybe do nothing!) whereever it finds itself. -#displayTest="MATCH_VERSION" # MATCH_VERSION is the default if nothing is specified (#optional) +displayTest="MATCH_VERSION" # MATCH_VERSION is the default if nothing is specified (#optional) # The description text for the mod (multi line!) (#mandatory) -description='''${mod_description}''' +description=''' +Aria's Essentials mod. This provides a bunch of essential functions and commands +''' # A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. -[[dependencies.${mod_id}]] #optional - # the modid of the dependency - modId="forge" #mandatory - # Does this dependency have to exist - if not, ordering below must be specified - mandatory=true #mandatory - # The version range of the dependency - versionRange="${forge_version_range}" #mandatory - # An ordering relationship for the dependency - BEFORE or AFTER required if the dependency is not mandatory - # BEFORE - This mod is loaded BEFORE the dependency - # AFTER - This mod is loaded AFTER the dependency - ordering="NONE" - # Side this dependency is applied on - BOTH, CLIENT, or SERVER - side="BOTH" +[[dependencies.ariasessentials]] #optional +# the modid of the dependency +modId="forge" #mandatory +# Does this dependency have to exist - if not, ordering below must be specified +mandatory=true #mandatory +# The version range of the dependency +versionRange="[40,)" #mandatory +# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory +ordering="NONE" +# Side this dependency is applied on - BOTH, CLIENT or SERVER +side="BOTH" # Here's another dependency -[[dependencies.${mod_id}]] - modId="minecraft" - mandatory=true - # This version range declares a minimum of the current minecraft version up to but not including the next major version - versionRange="${minecraft_version_range}" - ordering="NONE" - side="BOTH" -[[dependencies.${mod_id}]] - modId="libzontreck" - mandatory=true - versionRange="[1.10,1.11)" - ordering="NONE" - side="BOTH" - -# Features are specific properties of the game environment, that you may want to declare you require. This example declares -# that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't -# stop your mod loading on the server for example. -#[features.${mod_id}] -#openGLVersion="[3.2,)" \ No newline at end of file +[[dependencies.ariasessentials]] +modId="minecraft" +mandatory=true +# This version range declares a minimum of the current minecraft version up to but not including the next major version +versionRange="[1.18.2,1.19)" +ordering="NONE" +side="BOTH" +[[dependencies.libzontreck]] +modId="libzontreck" +mandatory=true +versionRange="[1.10,1.11)" +ordering="NONE" +side="BOTH" \ No newline at end of file diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta index eca79ae..d60a22f 100644 --- a/src/main/resources/pack.mcmeta +++ b/src/main/resources/pack.mcmeta @@ -1,8 +1,8 @@ { "pack": { - "description": { - "text": "${mod_id} resources" - }, - "pack_format": 15 + "description": "Aria's Essentials resources", + "pack_format": 9, + "forge:resource_pack_format": 8, + "forge:data_pack_format": 9 } } \ No newline at end of file From 11864385e4662fbf9bf3225dbdbfd113927b8f03 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sun, 21 Jan 2024 23:57:03 -0700 Subject: [PATCH 2/4] Attempt to fix rtp --- gradle.properties | 4 +- .../commands/homes/SetHomeCommand.java | 5 +- .../commands/teleport/TPEffectsCommand.java | 10 +- .../commands/teleport/TeleportActioner.java | 2 +- .../commands/warps/SetWarpCommand.java | 6 +- .../configs/client/AEClientConfig.java | 17 +- .../configs/server/AEServerConfig.java | 19 +- .../java/dev/zontreck/essentials/rtp/RTP.java | 190 ++++++------------ .../zontreck/essentials/util/FileHandler.java | 24 --- 9 files changed, 93 insertions(+), 184 deletions(-) delete mode 100644 src/main/java/dev/zontreck/essentials/util/FileHandler.java diff --git a/gradle.properties b/gradle.properties index 5a12322..15ccab3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false -libzontreck=1.10.011624.1712 +libzontreck=1.10.012124.1709 ## Environment Properties @@ -49,7 +49,7 @@ mod_name=Aria's Essentials # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=GPLv3 # The mod version. See https://semver.org/ -mod_version=1.2.011624.1834 +mod_version=1.2.012124.2356 # 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/src/main/java/dev/zontreck/essentials/commands/homes/SetHomeCommand.java b/src/main/java/dev/zontreck/essentials/commands/homes/SetHomeCommand.java index 3dc55d7..cafb06a 100644 --- a/src/main/java/dev/zontreck/essentials/commands/homes/SetHomeCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/homes/SetHomeCommand.java @@ -24,6 +24,7 @@ import net.minecraft.commands.Commands; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; import net.minecraftforge.common.MinecraftForge; @@ -74,8 +75,10 @@ public class SetHomeCommand { Vec2 rot = p.getRotationVector(); TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel()); + + BlockState bs = p.getLevel().getBlockState(dest.Position.moveDown().asBlockPos()); - Home newhome = new Home(p, homeName, dest, new ItemStack(p.getFeetBlockState().getBlock().asItem())); + Home newhome = new Home(p, homeName, dest, new ItemStack(bs.getBlock().asItem())); AriasEssentials.player_homes.get(p.getUUID()).add(newhome); diff --git a/src/main/java/dev/zontreck/essentials/commands/teleport/TPEffectsCommand.java b/src/main/java/dev/zontreck/essentials/commands/teleport/TPEffectsCommand.java index 2120ba8..4aec495 100644 --- a/src/main/java/dev/zontreck/essentials/commands/teleport/TPEffectsCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/teleport/TPEffectsCommand.java @@ -3,11 +3,13 @@ package dev.zontreck.essentials.commands.teleport; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.BoolArgumentType; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.zontreck.essentials.Messages; import dev.zontreck.libzontreck.chestgui.ChestGUI; import dev.zontreck.libzontreck.chestgui.ChestGUIButton; import dev.zontreck.libzontreck.chestgui.ChestGUIIdentifier; import dev.zontreck.libzontreck.profiles.Profile; import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException; +import dev.zontreck.libzontreck.util.ChatHelpers; import dev.zontreck.libzontreck.util.ServerUtilities; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; @@ -21,10 +23,10 @@ public class TPEffectsCommand { public static void register(CommandDispatcher dispatcher) { - dispatcher.register(Commands.literal("tpeffects").then(Commands.argument("enable", BoolArgumentType.bool()).executes(x->tpeffects(x.getSource(), BoolArgumentType.getBool(x, "enable"))))); + dispatcher.register(Commands.literal("tpeffects_disable").then(Commands.argument("disabled", BoolArgumentType.bool()).executes(x->tpeffects(x.getSource(), BoolArgumentType.getBool(x, "disabled"))))); } - public static int tpeffects(CommandSourceStack source, boolean enabled) + public static int tpeffects(CommandSourceStack source, boolean disabled) { ServerPlayer player = null; try { @@ -35,7 +37,9 @@ public class TPEffectsCommand try { Profile prof = Profile.get_profile_of(player.getStringUUID()); - prof.NBT.putBoolean("tpeffects", enabled); + prof.NBT.putBoolean("tpeffects", disabled); + + ChatHelpers.broadcastTo(player.getUUID(), ChatHelpers.macro(Messages.TP_EFFECTS_TOGGLED, disabled ? "disabled" : "enabled"), player.server); return 0; } catch (UserProfileNotYetExistsException e) { diff --git a/src/main/java/dev/zontreck/essentials/commands/teleport/TeleportActioner.java b/src/main/java/dev/zontreck/essentials/commands/teleport/TeleportActioner.java index 479af41..a09d710 100644 --- a/src/main/java/dev/zontreck/essentials/commands/teleport/TeleportActioner.java +++ b/src/main/java/dev/zontreck/essentials/commands/teleport/TeleportActioner.java @@ -33,7 +33,7 @@ public class TeleportActioner public static void ApplyTeleportEffect(ServerPlayer player){ try { Profile prof = Profile.get_profile_of(player.getStringUUID()); - if(!prof.NBT.getBoolean("tpeffects")) + if(prof.NBT.getBoolean("tpeffects")) { return; } diff --git a/src/main/java/dev/zontreck/essentials/commands/warps/SetWarpCommand.java b/src/main/java/dev/zontreck/essentials/commands/warps/SetWarpCommand.java index 85ab64d..ba59fb8 100644 --- a/src/main/java/dev/zontreck/essentials/commands/warps/SetWarpCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/warps/SetWarpCommand.java @@ -23,6 +23,7 @@ import net.minecraft.commands.Commands; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; import net.minecraftforge.common.MinecraftForge; @@ -58,7 +59,10 @@ public class SetWarpCommand { Vec2 rot = p.getRotationVector(); TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel()); - Warp w = new Warp(p.getUUID(), string, false, true, dest, new ItemStack(p.getFeetBlockState().getBlock().asItem())); + + BlockState bs = p.getLevel().getBlockState(dest.Position.moveDown().asBlockPos()); + + Warp w = new Warp(p.getUUID(), string, false, true, dest, new ItemStack(bs.getBlock().asItem())); WarpCreatedEvent event = new WarpCreatedEvent(w); if(MinecraftForge.EVENT_BUS.post(event)){ ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(Messages.WARP_CREATE_ERROR, event.denyReason), p.server); diff --git a/src/main/java/dev/zontreck/essentials/configs/client/AEClientConfig.java b/src/main/java/dev/zontreck/essentials/configs/client/AEClientConfig.java index f8a5ef6..00d3782 100644 --- a/src/main/java/dev/zontreck/essentials/configs/client/AEClientConfig.java +++ b/src/main/java/dev/zontreck/essentials/configs/client/AEClientConfig.java @@ -1,8 +1,9 @@ package dev.zontreck.essentials.configs.client; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.zontreck.ariaslib.util.FileIO; import dev.zontreck.essentials.util.EssentialsDatastore; -import dev.zontreck.essentials.util.FileHandler; +import dev.zontreck.libzontreck.util.SNbtIo; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtUtils; @@ -30,16 +31,7 @@ public class AEClientConfig Path serverConfig = EssentialsDatastore.of("client.snbt"); if(serverConfig.toFile().exists()) { - - try { - String snbt = FileHandler.readFile(serverConfig.toFile().getAbsolutePath()); - - inst = deserialize(NbtUtils.snbtToStructure(snbt)); - - - } catch (CommandSyntaxException e) { - throw new RuntimeException(e); - } + inst = deserialize(SNbtIo.loadSnbt(serverConfig)); }else { initNewConfig(); } @@ -68,9 +60,8 @@ public class AEClientConfig CompoundTag tag = inst.serialize(); - var snbt = NbtUtils.structureToSnbt(tag); - FileHandler.writeFile(serverConfig.toFile().getAbsolutePath(), snbt); + SNbtIo.writeSnbt(serverConfig, tag); } public CompoundTag serialize() diff --git a/src/main/java/dev/zontreck/essentials/configs/server/AEServerConfig.java b/src/main/java/dev/zontreck/essentials/configs/server/AEServerConfig.java index db386ce..e5e1637 100644 --- a/src/main/java/dev/zontreck/essentials/configs/server/AEServerConfig.java +++ b/src/main/java/dev/zontreck/essentials/configs/server/AEServerConfig.java @@ -1,17 +1,14 @@ package dev.zontreck.essentials.configs.server; -import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.zontreck.ariaslib.util.Lists; import dev.zontreck.essentials.configs.server.sections.*; import dev.zontreck.essentials.util.EssentialsDatastore; -import dev.zontreck.essentials.util.FileHandler; import dev.zontreck.essentials.util.Maps; +import dev.zontreck.libzontreck.util.SNbtIo; import net.minecraft.nbt.*; -import java.io.*; import java.nio.file.Path; import java.util.HashMap; -import java.util.List; import java.util.Map; public class AEServerConfig @@ -52,15 +49,7 @@ public class AEServerConfig if(serverConfig.toFile().exists()) { - try { - String snbt = FileHandler.readFile(serverConfig.toFile().getAbsolutePath()); - - inst = deserialize(NbtUtils.snbtToStructure(snbt)); - - - } catch (CommandSyntaxException e) { - throw new RuntimeException(e); - } + inst = deserialize(SNbtIo.loadSnbt(serverConfig)); }else { initNewConfig(); } @@ -112,9 +101,7 @@ public class AEServerConfig CompoundTag tag = inst.serialize(); - var snbt = NbtUtils.structureToSnbt(tag); - - FileHandler.writeFile(serverConfig.toFile().getAbsolutePath(), snbt); + SNbtIo.writeSnbt(serverConfig, tag); } public CompoundTag serialize() diff --git a/src/main/java/dev/zontreck/essentials/rtp/RTP.java b/src/main/java/dev/zontreck/essentials/rtp/RTP.java index 186a81b..a535c16 100644 --- a/src/main/java/dev/zontreck/essentials/rtp/RTP.java +++ b/src/main/java/dev/zontreck/essentials/rtp/RTP.java @@ -8,6 +8,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Vec3i; import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; @@ -20,124 +21,87 @@ import java.util.Iterator; import java.util.List; import java.util.Random; -/** - * As of v1.1.121823.x, this is now used for RTP - *

- * This ensures that RTP is only scanned once every so often. This is because RTP lags the server when it is having to check block positions. - *

- * If the RTP system scans each dimension (Not blacklisted), then it can build a list of safe locations that will be rotated out every 2 hours. - *

- * Every 10 minutes, a new RTP location is scanned. This ensures sufficiently semi-random locations. Eventually old locations will be removed from the list. - *

- * At server start, it will scan 10 RTP locations per dimension while there are no players. - */ -public class RTP -{ - public RTP(ServerLevel level) - { - position = new WorldPosition(new Vector3(0,500,0), WorldPosition.getDim(level)); +public class RTP { + private static final List BLACKLIST = Lists.of(Blocks.LAVA, Blocks.WATER, Blocks.BEDROCK); + private final int SEARCH_DIRECTION; + private final Heightmap.Types heightMapType; + private final WorldPosition position; + private final ServerLevel dimension; + private int tries; - if(position.getActualDimension().dimensionType().hasCeiling()) - { + public RTP(ServerLevel level) { + position = new WorldPosition(new Vector3(0, -60, 0), WorldPosition.getDim(level)); + dimension = position.getActualDimension(); + + if (position.getActualDimension().dimensionType().hasCeiling()) { heightMapType = Heightmap.Types.MOTION_BLOCKING_NO_LEAVES; - SearchDirection=-1; - }else { + SEARCH_DIRECTION = -1; + } else { heightMapType = Heightmap.Types.MOTION_BLOCKING_NO_LEAVES; - SearchDirection=1; + SEARCH_DIRECTION = 1; } } - private final int SearchDirection; - private Thread containingThread; - private final Heightmap.Types heightMapType; - public WorldPosition position; - private final List BLACKLIST = Lists.of(Blocks.LAVA, Blocks.WATER, Blocks.BEDROCK); - protected int tries; - protected int lastThreadDelay = 15; - protected RTP withThreadDelay(int delay) - { - lastThreadDelay=delay; - if(lastThreadDelay >= 60) lastThreadDelay = 60; - return this; - } - - public boolean isDimension(ServerLevel level) - { + public boolean isDimension(ServerLevel level) { String dim = WorldPosition.getDim(level); return dim.equals(position.Dimension); } - /** - * Searches for, and finds, a valid RTP location - * @param level The level to scan - * @return RTP data - */ - public static void find(ServerLevel level) - { - RandomPositionFactory.beginRTPSearch(level); - } + public BlockPos findSafeLandingLocation() { + BlockPos targetPos = position.Position.asBlockPos(); - public static List slicedByDimension(ServerLevel lvl) - { - List slice = new ArrayList<>(); - - Iterator it = RTPCaches.Locations.iterator(); - while(it.hasNext()) - { - RTP nxt = it.next(); - if(nxt.isDimension(lvl)) - { - slice.add(nxt); - } + // Search upward for a safe landing location + while (!isSafe(targetPos) || !isSafe(targetPos.above())) { + targetPos = targetPos.above(); } - return slice; + return targetPos; } - public static RTP getRTP(ServerLevel level) - { + private boolean isSafe(BlockPos blockPos) { + BlockState blockState = dimension.getBlockState(blockPos); + BlockState blockStateAbove = dimension.getBlockState(blockPos.above()); + BlockState blockStateBelow = dimension.getBlockState(blockPos.below()); + + if (blockState.isAir() && blockStateAbove.isAir()) { + if (!blockStateBelow.isAir()) { + return !BLACKLIST.contains(blockStateBelow.getBlock()); + } else { + return false; + } + } else { + return false; + } + } + + public static RTP getRTP(ServerLevel level) { List slice = slicedByDimension(level); - if(slice.size()>0) - { - RTP ret = slice.get(AriasEssentials.random.nextInt(0, slice.size())); + if (!slice.isEmpty()) { + RTP ret = slice.get(AriasEssentials.random.nextInt(slice.size())); RTPCaches.Locations.remove(ret); RandomPositionFactory.beginRTPSearch(ret.position.getActualDimension()); return ret; - } else return null; - } - - - public void moveDown() { - position.Position = position.Position.moveDown(); - } - - public void moveUp() { - position.Position = position.Position.moveUp(); - } - - public void move() - { - if(SearchDirection==1){ - moveUp(); - }else if(SearchDirection==0) - { - moveDown(); + } else { + return null; } } - public void moveOpposite() - { - if(SearchDirection==1){ - moveDown(); - }else if(SearchDirection==0) - { - moveUp(); + + public void move() { + if (SEARCH_DIRECTION == 1) { + position.Position = position.Position.moveUp(); + } else if (SEARCH_DIRECTION == -1) { + position.Position = position.Position.moveDown(); } } + + public void moveOpposite() { + move(); + } + public void newPosition() { if (!AriasEssentials.ALIVE || tries >= 25) return; - containingThread = Thread.currentThread(); - AriasEssentials.LOGGER.info("RTP starts looking for new position"); + AriasEssentials.LOGGER.info("RTP starts looking for a new position"); Random rng = new Random(Instant.now().getEpochSecond()); @@ -152,30 +116,25 @@ public class RTP bpos = pos.asBlockPos(); } while (!isValidPosition(bpos)); - if (pos.y < -30 || pos.y >= position.getActualDimension().getLogicalHeight()) { newPosition(); return; } tries++; - AriasEssentials.LOGGER.info("RTP returns new position"); + AriasEssentials.LOGGER.info("RTP returns a new position"); } private boolean isValidPosition(BlockPos bpos) { - ServerLevel dimension = position.getActualDimension(); ChunkStatus status = ChunkStatus.SPAWN; - dimension.getChunk(bpos.getX() >> 4, bpos.getZ() >> 4, status); Vector3 pos = new Vector3(dimension.getHeightmapPos(heightMapType, bpos)); return dimension.getWorldBorder().isWithinBounds(pos.asBlockPos()); } - private Vector3 spiralPositions(Vector3 position) { Vec3i posi = position.asMinecraftVec3i(); - ServerLevel dimension = this.position.getActualDimension(); BlockPos startBlockPos = new BlockPos(posi.getX(), dimension.getSeaLevel(), posi.getZ()); for (BlockPos pos : BlockPos.spiralAround(startBlockPos, 16, Direction.WEST, Direction.NORTH)) { @@ -188,32 +147,17 @@ public class RTP return position; } + public static List slicedByDimension(ServerLevel lvl) { + List slice = new ArrayList<>(); - private boolean safe(BlockPos blockPos) - { - containingThread=Thread.currentThread(); - BlockState b = position.getActualDimension().getBlockState(blockPos); - BlockState b2 = position.getActualDimension().getBlockState(blockPos.above()); - BlockState b3 = position.getActualDimension().getBlockState(blockPos.below()); + Iterator it = RTPCaches.Locations.iterator(); + while (it.hasNext()) { + RTP nxt = it.next(); + if (nxt.isDimension(lvl)) { + slice.add(nxt); + } + } - if (b.isAir() && b2.isAir()) { - if (!b3.isAir()) { - return !BLACKLIST.contains(b3.getBlock()); - } else - return false; - } else - return false; - - } - public boolean isSafe(BlockPos blockPos) { - return safe(blockPos); - /* - boolean s = safe(blockPos); - if(s) - { - AriasEssentials.LOGGER.info("/!\\ SAFE /!\\"); - }else AriasEssentials.LOGGER.info("/!\\ NOT SAFE /!\\"); - - return s;*/ + return slice; } } diff --git a/src/main/java/dev/zontreck/essentials/util/FileHandler.java b/src/main/java/dev/zontreck/essentials/util/FileHandler.java deleted file mode 100644 index abc95b2..0000000 --- a/src/main/java/dev/zontreck/essentials/util/FileHandler.java +++ /dev/null @@ -1,24 +0,0 @@ -package dev.zontreck.essentials.util; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; - -public class FileHandler -{ - - public static String readFile(String filePath) { - try { - byte[] fileBytes = Files.readAllBytes(Paths.get(filePath)); - return new String(fileBytes); - } catch (IOException e) { - return "An error occurred: " + e.getMessage(); - } - } - public static void writeFile(String filePath, String newContent) { - try { - Files.write(Paths.get(filePath), newContent.getBytes()); - } catch (IOException e) { - } - } -} From e713101f59a67d13c10589867f4efbbb128596b4 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 22 Jan 2024 00:15:36 -0700 Subject: [PATCH 3/4] Reduce max tries in RTP Search to fix it --- src/main/java/dev/zontreck/essentials/rtp/RTP.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main/java/dev/zontreck/essentials/rtp/RTP.java b/src/main/java/dev/zontreck/essentials/rtp/RTP.java index a535c16..8311708 100644 --- a/src/main/java/dev/zontreck/essentials/rtp/RTP.java +++ b/src/main/java/dev/zontreck/essentials/rtp/RTP.java @@ -25,7 +25,7 @@ public class RTP { private static final List BLACKLIST = Lists.of(Blocks.LAVA, Blocks.WATER, Blocks.BEDROCK); private final int SEARCH_DIRECTION; private final Heightmap.Types heightMapType; - private final WorldPosition position; + public WorldPosition position; private final ServerLevel dimension; private int tries; @@ -99,7 +99,7 @@ public class RTP { } public void newPosition() { - if (!AriasEssentials.ALIVE || tries >= 25) return; + if (!AriasEssentials.ALIVE || tries >= 5) return; AriasEssentials.LOGGER.info("RTP starts looking for a new position"); @@ -109,18 +109,13 @@ public class RTP { BlockPos bpos; do { - pos = new Vector3(rng.nextDouble(0xFFFF), 150, rng.nextDouble(0xFFFF)); + pos = new Vector3(rng.nextDouble(0xFFFF), -60, rng.nextDouble(0xFFFF)); pos = spiralPositions(pos); position.Position = pos; bpos = pos.asBlockPos(); } while (!isValidPosition(bpos)); - if (pos.y < -30 || pos.y >= position.getActualDimension().getLogicalHeight()) { - newPosition(); - return; - } - tries++; AriasEssentials.LOGGER.info("RTP returns a new position"); } From ce4667b6b42cb2979249ed815cc57d22b68d9fc8 Mon Sep 17 00:00:00 2001 From: Tara Piccari Date: Sun, 28 Jan 2024 16:36:34 -0700 Subject: [PATCH 4/4] Adjust the warps command --- gradle.properties | 2 +- .../zontreck/essentials/commands/warps/WarpsCommand.java | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index 15ccab3..f249bd8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,7 +14,7 @@ minecraft_version=1.18.2 # as they do not follow standard versioning conventions. minecraft_version_range=[1.18.2,1.19) # The Forge version must agree with the Minecraft version to get a valid artifact -forge_version=40.2.17 +forge_version=40.2.1 # The Forge version range can use any version of Forge as bounds or match the loader version range forge_version_range=[40,) # The loader version range can only use the major version of Forge/FML as bounds diff --git a/src/main/java/dev/zontreck/essentials/commands/warps/WarpsCommand.java b/src/main/java/dev/zontreck/essentials/commands/warps/WarpsCommand.java index 425253f..4d8a020 100644 --- a/src/main/java/dev/zontreck/essentials/commands/warps/WarpsCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/warps/WarpsCommand.java @@ -140,11 +140,8 @@ public class WarpsCommand { ) .withInfo(new LoreEntry.Builder().text(ChatHelpers.macro(appendType, warp.destination.Dimension).getString()).build()); - if(warps.size() > (2*9)) - { - // Say to person - ChatHelpers.broadcastTo(p, warpMsg, p.server); - }else + ChatHelpers.broadcastTo(p, warpMsg, p.server); + if(!(warps.size() > (2*9))) chestGui.withButton(button); iconY++;