Compare commits

..

No commits in common. "1.18.2" and "main" have entirely different histories.
1.18.2 ... main

36 changed files with 431 additions and 366 deletions

View file

@ -2,7 +2,7 @@ plugins {
id 'eclipse' id 'eclipse'
id 'idea' id 'idea'
id 'maven-publish' id 'maven-publish'
id 'net.minecraftforge.gradle' version '5.1+' id 'net.minecraftforge.gradle' version '[6.0,6.2)'
id 'org.parchmentmc.librarian.forgegradle' version '1.+' id 'org.parchmentmc.librarian.forgegradle' version '1.+'
} }
@ -41,6 +41,7 @@ minecraft {
// This property allows configuring Gradle's ProcessResources task(s) to run on IDE output locations before launching the game. // 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. // 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 // 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. // 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. // The folder name can be set on a run configuration using the "folderName" property.
@ -168,6 +169,24 @@ dependencies {
// http://www.gradle.org/docs/current/userguide/dependency_management.html // 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. // Example for how to get properties into the manifest for reading at runtime.
tasks.named('jar', Jar).configure { tasks.named('jar', Jar).configure {

View file

@ -3,22 +3,22 @@
org.gradle.jvmargs=-Xmx3G org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false org.gradle.daemon=false
libzontreck=1.10.012124.1709 libzontreck=1.10.011524.0045
## Environment Properties ## Environment Properties
# The Minecraft version must agree with the Forge version to get a valid artifact # The Minecraft version must agree with the Forge version to get a valid artifact
minecraft_version=1.18.2 minecraft_version=1.20.1
# The Minecraft version range can use any release version of Minecraft as bounds. # 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 # Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
# as they do not follow standard versioning conventions. # as they do not follow standard versioning conventions.
minecraft_version_range=[1.18.2,1.19) minecraft_version_range=[1.20.1,1.21)
# The Forge version must agree with the Minecraft version to get a valid artifact # The Forge version must agree with the Minecraft version to get a valid artifact
forge_version=40.2.1 forge_version=47.2.0
# The Forge version range can use any version of Forge as bounds or match the loader version range # The Forge version range can use any version of Forge as bounds or match the loader version range
forge_version_range=[40,) forge_version_range=[47,)
# The loader version range can only use the major version of Forge/FML as bounds # The loader version range can only use the major version of Forge/FML as bounds
loader_version_range=[40,) loader_version_range=[47,)
# The mapping channel to use for mappings. # The mapping channel to use for mappings.
# The default set of supported mapping channels are ["official", "snapshot", "snapshot_nodoc", "stable", "stable_nodoc"]. # 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. # Additional mapping channels can be registered through the "channelProviders" extension in a Gradle plugin.
@ -36,7 +36,7 @@ loader_version_range=[40,)
mapping_channel=parchment mapping_channel=parchment
# The mapping version to query from the mapping channel. # The mapping version to query from the mapping channel.
# This must match the format required by the mapping channel. # This must match the format required by the mapping channel.
mapping_version=2022.11.06-1.18.2 mapping_version=2023.09.03-1.20.1
## Mod Properties ## 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. # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=GPLv3 mod_license=GPLv3
# The mod version. See https://semver.org/ # The mod version. See https://semver.org/
mod_version=1.2.012124.2356 mod_version=1.2.011524.2039
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # 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. # This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html # See https://maven.apache.org/guides/mini/guide-naming-conventions.html

View file

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000 networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View file

@ -3,4 +3,8 @@ pluginManagement {
gradlePluginPortal() gradlePluginPortal()
maven { url = "https://maven.zontreck.com/repository/internal" } maven { url = "https://maven.zontreck.com/repository/internal" }
} }
}
plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0'
} }

View file

@ -25,6 +25,7 @@ import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
@ -144,6 +145,13 @@ public class AriasEssentials {
MinecraftForge.EVENT_BUS.register(new HeartsRenderer()); MinecraftForge.EVENT_BUS.register(new HeartsRenderer());
} }
@OnlyIn(Dist.CLIENT)
@SubscribeEvent
public static void onRegisterKeyBinds(RegisterKeyMappingsEvent ev)
{
ev.register(Keybindings.AUTOWALK);
}
} }
} }

View file

@ -11,7 +11,6 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import java.time.Instant; import java.time.Instant;
import java.util.UUID;
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
@Mod.EventBusSubscriber(modid = AriasEssentials.MODID, value = Dist.CLIENT) @Mod.EventBusSubscriber(modid = AriasEssentials.MODID, value = Dist.CLIENT)
@ -22,7 +21,7 @@ public class AutoWalk {
static long lastPress; static long lastPress;
@SubscribeEvent @SubscribeEvent
public static void onKeyPress(InputEvent.KeyInputEvent event) { public static void onKeyPress(InputEvent.Key event) {
if(Keybindings.AUTOWALK.matches(event.getKey(), event.getScanCode()) && Minecraft.getInstance().screen == null && Keybindings.AUTOWALK.isDown()) if(Keybindings.AUTOWALK.matches(event.getKey(), event.getScanCode()) && Minecraft.getInstance().screen == null && Keybindings.AUTOWALK.isDown())
{ {
lastPress = Instant.now().getEpochSecond(); lastPress = Instant.now().getEpochSecond();
@ -36,10 +35,10 @@ public class AutoWalk {
private static void startWalking() { private static void startWalking() {
isWalking=true; isWalking=true;
autoJump = Minecraft.getInstance().options.autoJump; autoJump = Minecraft.getInstance().options.autoJump().get();
Minecraft.getInstance().options.autoJump = true; Minecraft.getInstance().options.autoJump().set(true);
Minecraft.getInstance().player.sendMessage(ChatHelpers.macro(Messages.ESSENTIALS_PREFIX + "!Dark_Green!AutoWalking started"), new UUID(0,0)); Minecraft.getInstance().player.sendSystemMessage(ChatHelpers.macro(Messages.ESSENTIALS_PREFIX + "!Dark_Green!AutoWalking started"));
runner = new Thread(()->{ runner = new Thread(()->{
while(AutoWalk.isWalking) while(AutoWalk.isWalking)
@ -55,10 +54,10 @@ public class AutoWalk {
isWalking=false; isWalking=false;
runner.interrupt(); runner.interrupt();
runner=null; runner=null;
Minecraft.getInstance().options.autoJump = autoJump; Minecraft.getInstance().options.autoJump().set(autoJump);
Minecraft.getInstance().options.keyUp.setDown(false); Minecraft.getInstance().options.keyUp.setDown(false);
Minecraft.getInstance().player.sendMessage(ChatHelpers.macro(Messages.ESSENTIALS_PREFIX + "!Dark_Green!AutoWalking stopped"), new UUID(0,0)); Minecraft.getInstance().player.sendSystemMessage(ChatHelpers.macro(Messages.ESSENTIALS_PREFIX + "!Dark_Green!AutoWalking stopped"));
} }
} }

View file

@ -5,9 +5,8 @@ import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.client.KeyMapping; import net.minecraft.client.KeyMapping;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public class Keybindings { public class Keybindings {
@ -20,5 +19,11 @@ public class Keybindings {
final KeyMapping key = new KeyMapping(name, keycode, category); final KeyMapping key = new KeyMapping(name, keycode, category);
return key; return key;
} }
@SubscribeEvent
public static void registerKeyMappings(RegisterKeyMappingsEvent event)
{
event.register(AUTOWALK);
}
} }

View file

@ -2,7 +2,6 @@ package dev.zontreck.essentials.commands.gui;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType; import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.Messages;
import dev.zontreck.essentials.events.CommandExecutionEvent; import dev.zontreck.essentials.events.CommandExecutionEvent;
import dev.zontreck.essentials.networking.ModMessages; import dev.zontreck.essentials.networking.ModMessages;
@ -10,7 +9,6 @@ import dev.zontreck.essentials.networking.packets.s2c.S2CUpdateHearts;
import dev.zontreck.libzontreck.util.ChatHelpers; import dev.zontreck.libzontreck.util.ChatHelpers;
import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands; import net.minecraft.commands.Commands;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
public class HeartsCommand public class HeartsCommand
@ -22,31 +20,24 @@ public class HeartsCommand
private static int hearts(CommandSourceStack stack, boolean compressHearts) 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)) if(MinecraftForge.EVENT_BUS.post(exec))
{ {
return 0; return 0;
} }
// Send the state to the client, then update the config // Send the state to the client, then update the config
// Send feedback to the user // Send feedback to the user
ChatHelpers.broadcastTo(player.getUUID(), ChatHelpers.macro(Messages.HEARTS_UPDATED), stack.getServer()); ChatHelpers.broadcastTo(stack.getPlayer().getUUID(), ChatHelpers.macro(Messages.HEARTS_UPDATED), stack.getServer());
S2CUpdateHearts update = new S2CUpdateHearts(compressHearts); S2CUpdateHearts update = new S2CUpdateHearts(compressHearts);
ModMessages.sendToPlayer(update, player); ModMessages.sendToPlayer(update, stack.getPlayer());
return 0; return 0;
} }
private static int usage(CommandSourceStack stack) private static int usage(CommandSourceStack stack)
{ {
ChatHelpers.broadcastTo(stack.getEntity().getUUID(), ChatHelpers.macro(Messages.HEARTS_USAGE), stack.getServer()); ChatHelpers.broadcastTo(stack.getPlayer().getUUID(), ChatHelpers.macro(Messages.HEARTS_USAGE), stack.getServer());
return 0; return 0;

View file

@ -3,7 +3,6 @@ package dev.zontreck.essentials.commands.homes;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.essentials.AriasEssentials; import dev.zontreck.essentials.AriasEssentials;
import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.Messages;
import dev.zontreck.essentials.events.CommandExecutionEvent; import dev.zontreck.essentials.events.CommandExecutionEvent;
@ -37,12 +36,7 @@ public class DelHomeCommand {
private static int rmHome(CommandSourceStack ctx, String homeName) private static int rmHome(CommandSourceStack ctx, String homeName)
{ {
CommandExecutionEvent exec = null; var exec = new CommandExecutionEvent(ctx.getPlayer(), "delhome");
try {
exec = new CommandExecutionEvent(ctx.getPlayerOrException(), "delhome");
} catch (CommandSyntaxException e) {
throw new RuntimeException(e);
}
if(MinecraftForge.EVENT_BUS.post(exec)) if(MinecraftForge.EVENT_BUS.post(exec))
{ {
return 0; return 0;

View file

@ -33,12 +33,7 @@ public class HomeCommand {
private static int home(CommandSourceStack ctx, String homeName) private static int home(CommandSourceStack ctx, String homeName)
{ {
CommandExecutionEvent exec = null; var exec = new CommandExecutionEvent(ctx.getPlayer(), "home");
try {
exec = new CommandExecutionEvent(ctx.getPlayerOrException(), "home");
} catch (CommandSyntaxException e) {
throw new RuntimeException(e);
}
if(MinecraftForge.EVENT_BUS.post(exec)) if(MinecraftForge.EVENT_BUS.post(exec))
{ {
return 0; return 0;

View file

@ -60,7 +60,7 @@ public class HomesCommand {
{ {
stack = new ItemStack(Items.GRASS_BLOCK, 1); stack = new ItemStack(Items.GRASS_BLOCK, 1);
} }
stack.setHoverName(ChatHelpers.macro(string.homeName)); stack.setHoverName(Component.literal(string.homeName));
ChestGUIButton button = new ChestGUIButton(stack, (stackx, container, lore)-> { ChestGUIButton button = new ChestGUIButton(stack, (stackx, container, lore)-> {

View file

@ -24,7 +24,6 @@ import net.minecraft.commands.Commands;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; 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.Vec2;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
@ -43,12 +42,7 @@ public class SetHomeCommand {
private static int setHome(CommandSourceStack ctx, String homeName) private static int setHome(CommandSourceStack ctx, String homeName)
{ {
CommandExecutionEvent exec = null; var exec = new CommandExecutionEvent(ctx.getPlayer(), "sethome");
try {
exec = new CommandExecutionEvent(ctx.getPlayerOrException(), "sethome");
} catch (CommandSyntaxException e) {
throw new RuntimeException(e);
}
if(MinecraftForge.EVENT_BUS.post(exec)) if(MinecraftForge.EVENT_BUS.post(exec))
{ {
return 0; return 0;
@ -64,7 +58,7 @@ public class SetHomeCommand {
p = ctx.getPlayerOrException(); p = ctx.getPlayerOrException();
if(TeleportActioner.isBlacklistedDimension(p.getLevel())) if(TeleportActioner.isBlacklistedDimension(p.serverLevel()))
{ {
ChatHelpers.broadcastTo(p, ChatHelpers.macro(Messages.ESSENTIALS_PREFIX + AEServerConfig.getInstance().messages.BlacklistedDimensionError), p.server); ChatHelpers.broadcastTo(p, ChatHelpers.macro(Messages.ESSENTIALS_PREFIX + AEServerConfig.getInstance().messages.BlacklistedDimensionError), p.server);
@ -74,11 +68,9 @@ public class SetHomeCommand {
Vec3 position = p.position(); Vec3 position = p.position();
Vec2 rot = p.getRotationVector(); Vec2 rot = p.getRotationVector();
TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel()); TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.serverLevel());
BlockState bs = p.getLevel().getBlockState(dest.Position.moveDown().asBlockPos());
Home newhome = new Home(p, homeName, dest, new ItemStack(bs.getBlock().asItem())); Home newhome = new Home(p, homeName, dest, new ItemStack(p.getBlockStateOn().getBlock().asItem()));
AriasEssentials.player_homes.get(p.getUUID()).add(newhome); AriasEssentials.player_homes.get(p.getUUID()).add(newhome);

View file

@ -1,7 +1,6 @@
package dev.zontreck.essentials.commands.teleport; package dev.zontreck.essentials.commands.teleport;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.Messages;
import dev.zontreck.essentials.configs.server.AEServerConfig; import dev.zontreck.essentials.configs.server.AEServerConfig;
import dev.zontreck.essentials.events.CommandExecutionEvent; import dev.zontreck.essentials.events.CommandExecutionEvent;
@ -21,12 +20,7 @@ public class BackCommand
public static int back(CommandSourceStack ctx) public static int back(CommandSourceStack ctx)
{ {
CommandExecutionEvent exec = null; var exec = new CommandExecutionEvent(ctx.getPlayer(), "back");
try {
exec = new CommandExecutionEvent(ctx.getPlayerOrException(), "back");
} catch (CommandSyntaxException e) {
throw new RuntimeException(e);
}
if(MinecraftForge.EVENT_BUS.post(exec)) if(MinecraftForge.EVENT_BUS.post(exec))
{ {
return 0; return 0;
@ -34,20 +28,20 @@ public class BackCommand
try { try {
if(!AEServerConfig.getInstance().back.Enabled && !ctx.hasPermission(ctx.getServer().getOperatorUserPermissionLevel())) if(!AEServerConfig.getInstance().back.Enabled && !ctx.hasPermission(ctx.getServer().getOperatorUserPermissionLevel()))
{ {
ChatHelpers.broadcastTo(ctx.getPlayerOrException(), ChatHelpers.macro(Messages.TELEPORT_BACK_DISABLED), ctx.getServer()); ChatHelpers.broadcastTo(ctx.getPlayer(), ChatHelpers.macro(Messages.TELEPORT_BACK_DISABLED), ctx.getServer());
return 0; return 0;
} }
WorldPosition wp = BackPositionCaches.Pop(ctx.getPlayerOrException().getUUID()); WorldPosition wp = BackPositionCaches.Pop(ctx.getPlayer().getUUID());
ChatHelpers.broadcastTo(ctx.getPlayerOrException(), ChatHelpers.macro(Messages.TELEPORT_BACK), ctx.getServer()); ChatHelpers.broadcastTo(ctx.getPlayer(), ChatHelpers.macro(Messages.TELEPORT_BACK), ctx.getServer());
TeleportContainer cont = new TeleportContainer(ctx.getPlayerOrException(), wp.Position.asMinecraftVector(), ctx.getRotation(), wp.getActualDimension()); TeleportContainer cont = new TeleportContainer(ctx.getPlayer(), wp.Position.asMinecraftVector(), ctx.getRotation(), wp.getActualDimension());
TeleportActioner.ApplyTeleportEffect(ctx.getPlayerOrException()); TeleportActioner.ApplyTeleportEffect(ctx.getPlayer());
TeleportActioner.PerformTeleport(cont, true); TeleportActioner.PerformTeleport(cont, true);
} catch (Exception e) { } catch (Exception e) {
ChatHelpers.broadcastTo(ctx.getEntity().getUUID(), ChatHelpers.macro(Messages.NO_BACK), ctx.getServer()); ChatHelpers.broadcastTo(ctx.getPlayer(), ChatHelpers.macro(Messages.NO_BACK), ctx.getServer());
} }
return 0; return 0;
} }

View file

@ -2,7 +2,6 @@ package dev.zontreck.essentials.commands.teleport;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.essentials.events.CommandExecutionEvent; import dev.zontreck.essentials.events.CommandExecutionEvent;
import dev.zontreck.essentials.rtp.RandomPositionFactory; import dev.zontreck.essentials.rtp.RandomPositionFactory;
import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.CommandSourceStack;
@ -28,12 +27,7 @@ public class RTPCommand {
private static int rtp(CommandSourceStack source) { private static int rtp(CommandSourceStack source) {
CommandExecutionEvent exec = null; var exec = new CommandExecutionEvent(source.getPlayer(), "rtp");
try {
exec = new CommandExecutionEvent(source.getPlayerOrException(), "rtp");
} catch (CommandSyntaxException e) {
throw new RuntimeException(e);
}
if(MinecraftForge.EVENT_BUS.post(exec)) if(MinecraftForge.EVENT_BUS.post(exec))
{ {
return 0; return 0;
@ -64,7 +58,7 @@ public class RTPCommand {
Vec3 pos = pla.position(); Vec3 pos = pla.position();
//boolean found_place= false; //boolean found_place= false;
RandomPositionFactory.beginRTP(pla, pla.getLevel()); RandomPositionFactory.beginRTP(pla, pla.serverLevel());
} }

View file

@ -2,7 +2,6 @@ package dev.zontreck.essentials.commands.teleport;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.Messages;
import dev.zontreck.essentials.events.CommandExecutionEvent; import dev.zontreck.essentials.events.CommandExecutionEvent;
import dev.zontreck.libzontreck.util.ChatHelpers; import dev.zontreck.libzontreck.util.ChatHelpers;
@ -28,12 +27,7 @@ public class SpawnCommand {
private static int respawn(CommandSourceStack source) { private static int respawn(CommandSourceStack source) {
CommandExecutionEvent exec = null; var exec = new CommandExecutionEvent(source.getPlayer(), "spawn");
try {
exec = new CommandExecutionEvent(source.getPlayerOrException(), "spawn");
} catch (CommandSyntaxException e) {
throw new RuntimeException(e);
}
if(MinecraftForge.EVENT_BUS.post(exec)) if(MinecraftForge.EVENT_BUS.post(exec))
{ {
return 0; return 0;
@ -42,10 +36,10 @@ public class SpawnCommand {
ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(Messages.RESPAWNING), p.server); ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(Messages.RESPAWNING), p.server);
BlockPos spawn = p.getLevel().getSharedSpawnPos(); BlockPos spawn = p.serverLevel().getSharedSpawnPos();
TeleportActioner.ApplyTeleportEffect(p); TeleportActioner.ApplyTeleportEffect(p);
TeleportContainer cont = new TeleportContainer(p, new Vec3(spawn.getX(), spawn.getY(), spawn.getZ()), Vec2.ZERO, p.getLevel()); TeleportContainer cont = new TeleportContainer(p, new Vec3(spawn.getX(), spawn.getY(), spawn.getZ()), Vec2.ZERO, p.serverLevel());
TeleportActioner.PerformTeleport(cont, false); TeleportActioner.PerformTeleport(cont, false);

View file

@ -2,7 +2,6 @@ package dev.zontreck.essentials.commands.teleport;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.ariaslib.terminal.Task; import dev.zontreck.ariaslib.terminal.Task;
import dev.zontreck.ariaslib.util.DelayedExecutorService; import dev.zontreck.ariaslib.util.DelayedExecutorService;
import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.Messages;
@ -38,12 +37,7 @@ public class TPACommand {
private static int tpa(CommandSourceStack source, ServerPlayer serverPlayer) { private static int tpa(CommandSourceStack source, ServerPlayer serverPlayer) {
CommandExecutionEvent exec = null; var exec = new CommandExecutionEvent(source.getPlayer(), "tpa");
try {
exec = new CommandExecutionEvent(source.getPlayerOrException(), "tpa");
} catch (CommandSyntaxException e) {
throw new RuntimeException(e);
}
if(MinecraftForge.EVENT_BUS.post(exec)) if(MinecraftForge.EVENT_BUS.post(exec))
{ {
return 0; return 0;
@ -124,7 +118,7 @@ public class TPACommand {
private static int usage(CommandSourceStack source) { private static int usage(CommandSourceStack source) {
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()); source.sendSystemMessage(ChatHelpers.macro("/tpa USAGE\n\n "+ChatColor.BOLD + ChatColor.DARK_GRAY+"/tpa "+ChatColor.DARK_RED+"target_player\n"));
return 0; return 0;
} }
} }

View file

@ -2,7 +2,6 @@ package dev.zontreck.essentials.commands.teleport;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.ariaslib.terminal.Task; import dev.zontreck.ariaslib.terminal.Task;
import dev.zontreck.ariaslib.util.DelayedExecutorService; import dev.zontreck.ariaslib.util.DelayedExecutorService;
import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.Messages;
@ -34,12 +33,7 @@ public class TPAHereCommand {
private static int tpa(CommandSourceStack source, ServerPlayer serverPlayer) { private static int tpa(CommandSourceStack source, ServerPlayer serverPlayer) {
CommandExecutionEvent exec = null; var exec = new CommandExecutionEvent(source.getPlayer(), "tpahere");
try {
exec = new CommandExecutionEvent(source.getPlayerOrException(), "tpahere");
} catch (CommandSyntaxException e) {
throw new RuntimeException(e);
}
if(MinecraftForge.EVENT_BUS.post(exec)) if(MinecraftForge.EVENT_BUS.post(exec))
{ {
return 0; return 0;
@ -120,7 +114,7 @@ public class TPAHereCommand {
} }
private static int usage(CommandSourceStack source) { private static int usage(CommandSourceStack source) {
ChatHelpers.broadcastTo(source.getEntity().getUUID(), ChatHelpers.macro("/tpahere USAGE\n\n !Bold!!Dark_Gray!/tpahere !Dark_Red!target_player\n"), source.getServer()); source.sendSystemMessage(ChatHelpers.macro("/tpahere USAGE\n\n !Bold!!Dark_Gray!/tpahere !Dark_Red!target_player\n"));
return 0; return 0;
} }
} }

View file

@ -6,7 +6,6 @@ import java.util.UUID;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.Messages;
import dev.zontreck.essentials.events.CommandExecutionEvent; import dev.zontreck.essentials.events.CommandExecutionEvent;
import dev.zontreck.libzontreck.chat.ChatColor; import dev.zontreck.libzontreck.chat.ChatColor;
@ -26,12 +25,7 @@ public class TPAcceptCommand {
private static int doAccept(CommandSourceStack source, String TPID) { private static int doAccept(CommandSourceStack source, String TPID) {
CommandExecutionEvent exec = null; var exec = new CommandExecutionEvent(source.getPlayer(), "tpaccept");
try {
exec = new CommandExecutionEvent(source.getPlayerOrException(), "tpaccept");
} catch (CommandSyntaxException e) {
throw new RuntimeException(e);
}
if(MinecraftForge.EVENT_BUS.post(exec)) if(MinecraftForge.EVENT_BUS.post(exec))
{ {
return 0; return 0;
@ -60,7 +54,7 @@ public class TPAcceptCommand {
cont.PlayerInst = from; cont.PlayerInst = from;
cont.Position = to.position(); cont.Position = to.position();
cont.Rotation = to.getRotationVector(); cont.Rotation = to.getRotationVector();
cont.Dimension = to.getLevel(); cont.Dimension = to.serverLevel();
TeleportActioner.ApplyTeleportEffect(from); TeleportActioner.ApplyTeleportEffect(from);
TeleportActioner.PerformTeleport(cont, false); TeleportActioner.PerformTeleport(cont, false);

View file

@ -2,14 +2,11 @@ package dev.zontreck.essentials.commands.teleport;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType; 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.ChestGUI;
import dev.zontreck.libzontreck.chestgui.ChestGUIButton; import dev.zontreck.libzontreck.chestgui.ChestGUIButton;
import dev.zontreck.libzontreck.chestgui.ChestGUIIdentifier; import dev.zontreck.libzontreck.chestgui.ChestGUIIdentifier;
import dev.zontreck.libzontreck.profiles.Profile; import dev.zontreck.libzontreck.profiles.Profile;
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException; import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
import dev.zontreck.libzontreck.util.ChatHelpers;
import dev.zontreck.libzontreck.util.ServerUtilities; import dev.zontreck.libzontreck.util.ServerUtilities;
import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands; import net.minecraft.commands.Commands;
@ -23,23 +20,16 @@ public class TPEffectsCommand
{ {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{ {
dispatcher.register(Commands.literal("tpeffects_disable").then(Commands.argument("disabled", BoolArgumentType.bool()).executes(x->tpeffects(x.getSource(), BoolArgumentType.getBool(x, "disabled"))))); dispatcher.register(Commands.literal("tpeffects").then(Commands.argument("enable", BoolArgumentType.bool()).executes(x->tpeffects(x.getSource(), BoolArgumentType.getBool(x, "enable")))));
} }
public static int tpeffects(CommandSourceStack source, boolean disabled) public static int tpeffects(CommandSourceStack source, boolean enabled)
{ {
ServerPlayer player = null; ServerPlayer player = source.getPlayer();
try {
player = source.getPlayerOrException();
} catch (CommandSyntaxException e) {
throw new RuntimeException(e);
}
try { try {
Profile prof = Profile.get_profile_of(player.getStringUUID()); Profile prof = Profile.get_profile_of(player.getStringUUID());
prof.NBT.putBoolean("tpeffects", disabled); prof.NBT.putBoolean("tpeffects", enabled);
ChatHelpers.broadcastTo(player.getUUID(), ChatHelpers.macro(Messages.TP_EFFECTS_TOGGLED, disabled ? "disabled" : "enabled"), player.server);
return 0; return 0;
} catch (UserProfileNotYetExistsException e) { } catch (UserProfileNotYetExistsException e) {

View file

@ -3,10 +3,9 @@ package dev.zontreck.essentials.commands.teleport;
import dev.zontreck.ariaslib.util.DelayedExecutorService; import dev.zontreck.ariaslib.util.DelayedExecutorService;
import dev.zontreck.essentials.AriasEssentials; import dev.zontreck.essentials.AriasEssentials;
import dev.zontreck.essentials.configs.server.AEServerConfig; 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.Vector3;
import dev.zontreck.libzontreck.vectors.WorldPosition; import dev.zontreck.libzontreck.vectors.WorldPosition;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.commands.EffectCommands; import net.minecraft.server.commands.EffectCommands;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@ -31,16 +30,7 @@ public class TeleportActioner
} }
public static void ApplyTeleportEffect(ServerPlayer player){ public static void ApplyTeleportEffect(ServerPlayer player){
try { if(isBlacklistedDimension(player.serverLevel())){
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; return;
} }
// 10/05/2022 - Thinking ahead here to future proof it so i can do things in threads safely // 10/05/2022 - Thinking ahead here to future proof it so i can do things in threads safely
@ -53,7 +43,7 @@ public class TeleportActioner
for(int i = 0; i < effects.size(); i++) { for(int i = 0; i < effects.size(); i++) {
RegistryObject<MobEffect> effect = RegistryObject.create(new ResourceLocation(effects.get(i)), ForgeRegistries.MOB_EFFECTS); RegistryObject<MobEffect> effect = RegistryObject.create(new ResourceLocation(effects.get(i)), ForgeRegistries.MOB_EFFECTS);
int duration = AriasEssentials.random.nextInt(2, 5) * 20; int duration = AriasEssentials.random.nextInt(5, 10) * 20;
int amplifier = AriasEssentials.random.nextInt(1, 3); int amplifier = AriasEssentials.random.nextInt(1, 3);
if (effects.get(i).equals("minecraft:slow_falling")) if (effects.get(i).equals("minecraft:slow_falling"))

View file

@ -3,7 +3,6 @@ package dev.zontreck.essentials.commands.warps;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.Messages;
import dev.zontreck.essentials.events.CommandExecutionEvent; import dev.zontreck.essentials.events.CommandExecutionEvent;
import dev.zontreck.essentials.warps.NoSuchWarpException; import dev.zontreck.essentials.warps.NoSuchWarpException;
@ -30,12 +29,7 @@ public class DelWarpCommand {
private static int setWarp(CommandSourceStack source, String string) { private static int setWarp(CommandSourceStack source, String string) {
CommandExecutionEvent exec = null; var exec = new CommandExecutionEvent(source.getPlayer(), "delwarp");
try {
exec = new CommandExecutionEvent(source.getPlayerOrException(), "delwarp");
} catch (CommandSyntaxException e) {
throw new RuntimeException(e);
}
if(MinecraftForge.EVENT_BUS.post(exec)) if(MinecraftForge.EVENT_BUS.post(exec))
{ {
return 0; return 0;

View file

@ -7,7 +7,6 @@ import java.sql.SQLException;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.Messages;
import dev.zontreck.essentials.commands.teleport.TeleportDestination; import dev.zontreck.essentials.commands.teleport.TeleportDestination;
import dev.zontreck.essentials.events.CommandExecutionEvent; import dev.zontreck.essentials.events.CommandExecutionEvent;
@ -41,12 +40,7 @@ public class RTPWarpCommand {
private static int setWarp(CommandSourceStack source, String string) { private static int setWarp(CommandSourceStack source, String string) {
CommandExecutionEvent exec = null; var exec = new CommandExecutionEvent(source.getPlayer(), "setwarp");
try {
exec = new CommandExecutionEvent(source.getPlayerOrException(), "setwarp");
} catch (CommandSyntaxException e) {
throw new RuntimeException(e);
}
if(MinecraftForge.EVENT_BUS.post(exec)) if(MinecraftForge.EVENT_BUS.post(exec))
{ {
return 0; return 0;
@ -56,8 +50,8 @@ public class RTPWarpCommand {
Vec3 position = p.position(); Vec3 position = p.position();
Vec2 rot = p.getRotationVector(); Vec2 rot = p.getRotationVector();
TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel()); 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.getFeetBlockState().getBlock().asItem())); Warp warp = new Warp(p.getUUID(), string, true, true, dest, new ItemStack(p.getBlockStateOn().getBlock().asItem()));
WarpCreatedEvent event = new WarpCreatedEvent(warp); WarpCreatedEvent event = new WarpCreatedEvent(warp);
if(MinecraftForge.EVENT_BUS.post(event)) if(MinecraftForge.EVENT_BUS.post(event))
{ {

View file

@ -7,7 +7,6 @@ import java.sql.SQLException;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.Messages;
import dev.zontreck.essentials.commands.teleport.TeleportDestination; import dev.zontreck.essentials.commands.teleport.TeleportDestination;
import dev.zontreck.essentials.events.CommandExecutionEvent; import dev.zontreck.essentials.events.CommandExecutionEvent;
@ -23,7 +22,6 @@ import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.ItemStack; 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.Vec2;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
@ -42,12 +40,7 @@ public class SetWarpCommand {
private static int setWarp(CommandSourceStack source, String string) { private static int setWarp(CommandSourceStack source, String string) {
CommandExecutionEvent exec = null; var exec = new CommandExecutionEvent(source.getPlayer(), "setwarp");
try {
exec = new CommandExecutionEvent(source.getPlayerOrException(), "setwarp");
} catch (CommandSyntaxException e) {
throw new RuntimeException(e);
}
if(MinecraftForge.EVENT_BUS.post(exec)) if(MinecraftForge.EVENT_BUS.post(exec))
{ {
return 0; return 0;
@ -58,11 +51,8 @@ public class SetWarpCommand {
Vec3 position = p.position(); Vec3 position = p.position();
Vec2 rot = p.getRotationVector(); Vec2 rot = p.getRotationVector();
TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel()); 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()));
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); WarpCreatedEvent event = new WarpCreatedEvent(w);
if(MinecraftForge.EVENT_BUS.post(event)){ if(MinecraftForge.EVENT_BUS.post(event)){
ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(Messages.WARP_CREATE_ERROR, event.denyReason), p.server); ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(Messages.WARP_CREATE_ERROR, event.denyReason), p.server);

View file

@ -64,7 +64,7 @@ public class WarpCommand {
if(type==1){ if(type==1){
try { try {
var exec = new CommandExecutionEvent(source.getPlayerOrException(), "rtp"); var exec = new CommandExecutionEvent(source.getPlayer(), "rtp");
if(MinecraftForge.EVENT_BUS.post(exec)) if(MinecraftForge.EVENT_BUS.post(exec))
{ {
return; return;
@ -78,12 +78,7 @@ public class WarpCommand {
} }
} }
CommandExecutionEvent exec = null; var exec = new CommandExecutionEvent(source.getPlayer(), "warp");
try {
exec = new CommandExecutionEvent(source.getPlayerOrException(), "warp");
} catch (CommandSyntaxException e) {
throw new RuntimeException(e);
}
if(MinecraftForge.EVENT_BUS.post(exec)) if(MinecraftForge.EVENT_BUS.post(exec))
{ {
return; return;

View file

@ -140,8 +140,11 @@ public class WarpsCommand {
) )
.withInfo(new LoreEntry.Builder().text(ChatHelpers.macro(appendType, warp.destination.Dimension).getString()).build()); .withInfo(new LoreEntry.Builder().text(ChatHelpers.macro(appendType, warp.destination.Dimension).getString()).build());
ChatHelpers.broadcastTo(p, warpMsg, p.server); if(warps.size() > (2*9))
if(!(warps.size() > (2*9))) {
// Say to person
ChatHelpers.broadcastTo(p, warpMsg, p.server);
}else
chestGui.withButton(button); chestGui.withButton(button);
iconY++; iconY++;

View file

@ -1,9 +1,8 @@
package dev.zontreck.essentials.configs.client; package dev.zontreck.essentials.configs.client;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.ariaslib.util.FileIO;
import dev.zontreck.essentials.util.EssentialsDatastore; import dev.zontreck.essentials.util.EssentialsDatastore;
import dev.zontreck.libzontreck.util.SNbtIo; import dev.zontreck.essentials.util.FileHandler;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils; import net.minecraft.nbt.NbtUtils;
@ -31,7 +30,16 @@ public class AEClientConfig
Path serverConfig = EssentialsDatastore.of("client.snbt"); Path serverConfig = EssentialsDatastore.of("client.snbt");
if(serverConfig.toFile().exists()) if(serverConfig.toFile().exists())
{ {
inst = deserialize(SNbtIo.loadSnbt(serverConfig));
try {
String snbt = FileHandler.readFile(serverConfig.toFile().getAbsolutePath());
inst = deserialize(NbtUtils.snbtToStructure(snbt));
} catch (CommandSyntaxException e) {
throw new RuntimeException(e);
}
}else { }else {
initNewConfig(); initNewConfig();
} }
@ -60,8 +68,9 @@ public class AEClientConfig
CompoundTag tag = inst.serialize(); CompoundTag tag = inst.serialize();
var snbt = NbtUtils.structureToSnbt(tag);
SNbtIo.writeSnbt(serverConfig, tag); FileHandler.writeFile(serverConfig.toFile().getAbsolutePath(), snbt);
} }
public CompoundTag serialize() public CompoundTag serialize()

View file

@ -1,14 +1,17 @@
package dev.zontreck.essentials.configs.server; package dev.zontreck.essentials.configs.server;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.ariaslib.util.Lists; import dev.zontreck.ariaslib.util.Lists;
import dev.zontreck.essentials.configs.server.sections.*; import dev.zontreck.essentials.configs.server.sections.*;
import dev.zontreck.essentials.util.EssentialsDatastore; import dev.zontreck.essentials.util.EssentialsDatastore;
import dev.zontreck.essentials.util.FileHandler;
import dev.zontreck.essentials.util.Maps; import dev.zontreck.essentials.util.Maps;
import dev.zontreck.libzontreck.util.SNbtIo;
import net.minecraft.nbt.*; import net.minecraft.nbt.*;
import java.io.*;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
public class AEServerConfig public class AEServerConfig
@ -49,7 +52,15 @@ public class AEServerConfig
if(serverConfig.toFile().exists()) if(serverConfig.toFile().exists())
{ {
inst = deserialize(SNbtIo.loadSnbt(serverConfig)); try {
String snbt = FileHandler.readFile(serverConfig.toFile().getAbsolutePath());
inst = deserialize(NbtUtils.snbtToStructure(snbt));
} catch (CommandSyntaxException e) {
throw new RuntimeException(e);
}
}else { }else {
initNewConfig(); initNewConfig();
} }
@ -76,7 +87,7 @@ public class AEServerConfig
back = new Back(); back = new Back();
teleport = new Teleportation(); teleport = new Teleportation();
teleport.Effects = Lists.of( teleport.Effects = Lists.of(
"minecraft:blindness", "minecraft:darkness",
"minecraft:levitation", "minecraft:levitation",
"minecraft:slow_falling", "minecraft:slow_falling",
"minecraft:hunger" "minecraft:hunger"
@ -101,7 +112,9 @@ public class AEServerConfig
CompoundTag tag = inst.serialize(); CompoundTag tag = inst.serialize();
SNbtIo.writeSnbt(serverConfig, tag); var snbt = NbtUtils.structureToSnbt(tag);
FileHandler.writeFile(serverConfig.toFile().getAbsolutePath(), snbt);
} }
public CompoundTag serialize() public CompoundTag serialize()

View file

@ -17,7 +17,7 @@ import dev.zontreck.essentials.configs.client.AEClientConfig;
import net.minecraft.Util; import net.minecraft.Util;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiComponent; import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffectInstance;
@ -28,8 +28,10 @@ import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGuiOverlayEvent;
import net.minecraftforge.client.gui.ForgeIngameGui; import net.minecraftforge.client.gui.overlay.ForgeGui;
import net.minecraftforge.client.gui.overlay.GuiOverlayManager;
import net.minecraftforge.client.gui.overlay.NamedGuiOverlay;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -42,7 +44,7 @@ public class HeartsRenderer {
"textures/gui/hearts.png"); "textures/gui/hearts.png");
private static final ResourceLocation ICON_ABSORB = new ResourceLocation(AriasEssentials.MODID, private static final ResourceLocation ICON_ABSORB = new ResourceLocation(AriasEssentials.MODID,
"textures/gui/absorb.png"); "textures/gui/absorb.png");
private static final ResourceLocation ICON_VANILLA = GuiComponent.GUI_ICONS_LOCATION; private static final ResourceLocation ICON_VANILLA = Gui.GUI_ICONS_LOCATION;
private final Minecraft mc = Minecraft.getInstance(); private final Minecraft mc = Minecraft.getInstance();
@ -65,8 +67,8 @@ public class HeartsRenderer {
* @param width Width to draw * @param width Width to draw
* @param height Height to draw * @param height Height to draw
*/ */
private void blit(PoseStack matrixStack, int x, int y, int textureX, int textureY, int width, int height) { private void blit(GuiGraphics matrixStack, int x, int y, int textureX, int textureY, int width, int height, ResourceLocation resource) {
Minecraft.getInstance().gui.blit(matrixStack, x, y, textureX, textureY, width, height); matrixStack.blit(resource, x, y, textureX, textureY, width, height);
} }
/* HUD */ /* HUD */
@ -77,12 +79,28 @@ public class HeartsRenderer {
* @param event Event instance * @param event Event instance
*/ */
@SubscribeEvent(priority = EventPriority.LOW) @SubscribeEvent(priority = EventPriority.LOW)
public void renderHealthbar(RenderGameOverlayEvent.PreLayer event) { public void renderHealthbar(RenderGuiOverlayEvent.Pre event) {
if (event.isCanceled() || !AEClientConfig.getInstance().EnableHearts || event.getOverlay() != ForgeIngameGui.PLAYER_HEALTH_ELEMENT) { 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) {
return; return;
} }
// ensure its visible // ensure its visible
if (!(mc.gui instanceof ForgeIngameGui gui) || mc.options.hideGui || !gui.shouldDrawSurvivalElements()) { if (!(mc.gui instanceof ForgeGui gui) || mc.options.hideGui || !gui.shouldDrawSurvivalElements()) {
return; return;
} }
Entity renderViewEnity = this.mc.getCameraEntity(); Entity renderViewEnity = this.mc.getCameraEntity();
@ -94,7 +112,7 @@ public class HeartsRenderer {
this.mc.getProfiler().push("health"); this.mc.getProfiler().push("health");
// extra setup stuff from us // extra setup stuff from us
int left_height = gui.left_height; int left_height = gui.leftHeight;
int width = this.mc.getWindow().getGuiScaledWidth(); int width = this.mc.getWindow().getGuiScaledWidth();
int height = this.mc.getWindow().getGuiScaledHeight(); int height = this.mc.getWindow().getGuiScaledHeight();
int updateCounter = this.mc.gui.getGuiTicks(); int updateCounter = this.mc.gui.getGuiTicks();
@ -103,13 +121,13 @@ public class HeartsRenderer {
// changes are indicated by comment // changes are indicated by comment
int health = Mth.ceil(player.getHealth()); 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) { if (health < this.playerHealth && player.invulnerableTime > 0) {
this.lastSystemTime = Util.getMillis(); this.lastSystemTime = Util.getMillis();
this.healthUpdateCounter = (updateCounter + 20); 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.lastSystemTime = Util.getMillis();
this.healthUpdateCounter = (updateCounter + 10); this.healthUpdateCounter = (updateCounter + 10);
} }
@ -127,7 +145,8 @@ public class HeartsRenderer {
float healthMax = attrMaxHealth == null ? 0 : (float) attrMaxHealth.getValue(); float healthMax = attrMaxHealth == null ? 0 : (float) attrMaxHealth.getValue();
float absorb = Mth.ceil(player.getAbsorptionAmount()); 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); healthMax = Math.min(healthMax, 20f);
health = Math.min(health, 20); health = Math.min(health, 20);
absorb = Math.min(absorb, 20); absorb = Math.min(absorb, 20);
@ -139,9 +158,10 @@ public class HeartsRenderer {
int left = width / 2 - 91; int left = width / 2 - 91;
int top = height - left_height; int top = height - left_height;
// change: these are unused below, unneeded? should these adjust the Forge variable? // change: these are unused below, unneeded? should these adjust the Forge
//left_height += (healthRows * rowHeight); // variable?
//if (rowHeight != 10) left_height += 10 - rowHeight; // left_height += (healthRows * rowHeight);
// if (rowHeight != 10) left_height += 10 - rowHeight;
this.regen = -1; this.regen = -1;
if (player.hasEffect(MobEffects.REGENERATION)) { if (player.hasEffect(MobEffects.REGENERATION)) {
@ -152,46 +172,46 @@ public class HeartsRenderer {
final int TOP = 9 * (this.mc.level.getLevelData().isHardcore() ? 5 : 0); final int TOP = 9 * (this.mc.level.getLevelData().isHardcore() ? 5 : 0);
final int BACKGROUND = (highlight ? 25 : 16); final int BACKGROUND = (highlight ? 25 : 16);
int MARGIN = 16; int MARGIN = 16;
if (player.hasEffect(MobEffects.POISON)) MARGIN += 36; if (player.hasEffect(MobEffects.POISON))
else if (player.hasEffect(MobEffects.WITHER)) MARGIN += 72; MARGIN += 36;
else if (player.hasEffect(MobEffects.WITHER))
MARGIN += 72;
float absorbRemaining = absorb; float absorbRemaining = absorb;
PoseStack matrixStack = event.getMatrixStack(); GuiGraphics matrixStack = event.getGuiGraphics();
for (int i = Mth.ceil((healthMax + absorb) / 2.0F) - 1; i >= 0; --i) { for (int i = Mth.ceil((healthMax + absorb) / 2.0F) - 1; i >= 0; --i) {
int row = Mth.ceil((float) (i + 1) / 10.0F) - 1; int row = Mth.ceil((float) (i + 1) / 10.0F) - 1;
int x = left + i % 10 * 8; int x = left + i % 10 * 8;
int y = top - row * rowHeight; int y = top - row * rowHeight;
if (health <= 4) y += this.rand.nextInt(2); if (health <= 4)
if (i == this.regen) y -= 2; y += this.rand.nextInt(2);
if (i == this.regen)
y -= 2;
this.blit(matrixStack, x, y, BACKGROUND, TOP, 9, 9); this.blit(matrixStack, x, y, BACKGROUND, TOP, 9, 9, ICON_VANILLA);
if (highlight) { if (highlight) {
if (i * 2 + 1 < healthLast) { if (i * 2 + 1 < healthLast) {
this.blit(matrixStack, x, y, MARGIN + 54, TOP, 9, 9); //6 this.blit(matrixStack, x, y, MARGIN + 54, TOP, 9, 9, ICON_VANILLA); // 6
} } else if (i * 2 + 1 == healthLast) {
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 + 63, TOP, 9, 9); //7
} }
} }
if (absorbRemaining > 0.0F) { if (absorbRemaining > 0.0F) {
if (absorbRemaining == absorb && absorb % 2.0F == 1.0F) { if (absorbRemaining == absorb && absorb % 2.0F == 1.0F) {
this.blit(matrixStack, x, y, MARGIN + 153, TOP, 9, 9); //17 this.blit(matrixStack, x, y, MARGIN + 153, TOP, 9, 9, ICON_VANILLA); // 17
absorbRemaining -= 1.0F; absorbRemaining -= 1.0F;
} } else {
else { this.blit(matrixStack, x, y, MARGIN + 144, TOP, 9, 9, ICON_VANILLA); // 16
this.blit(matrixStack, x, y, MARGIN + 144, TOP, 9, 9); //16
absorbRemaining -= 2.0F; absorbRemaining -= 2.0F;
} }
} } else {
else {
if (i * 2 + 1 < health) { if (i * 2 + 1 < health) {
this.blit(matrixStack, x, y, MARGIN + 36, TOP, 9, 9); //4 this.blit(matrixStack, x, y, MARGIN + 36, TOP, 9, 9, ICON_VANILLA); // 4
} } else if (i * 2 + 1 == health) {
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 + 45, TOP, 9, 9); //5
} }
} }
} }
@ -200,22 +220,23 @@ public class HeartsRenderer {
this.renderExtraAbsorption(matrixStack, left, top - rowHeight, player); this.renderExtraAbsorption(matrixStack, left, top - rowHeight, player);
RenderSystem.setShaderTexture(0, ICON_VANILLA); RenderSystem.setShaderTexture(0, ICON_VANILLA);
gui.left_height += 10; gui.leftHeight += 10;
if (absorb > 0) { if (absorb > 0) {
gui.left_height += 10; gui.leftHeight += 10;
} }
event.setCanceled(true); event.setCanceled(true);
RenderSystem.disableBlend(); RenderSystem.disableBlend();
this.mc.getProfiler().pop(); this.mc.getProfiler().pop();
MinecraftForge.EVENT_BUS.post(new RenderGameOverlayEvent.PostLayer(matrixStack, event, ForgeIngameGui.PLAYER_HEALTH_ELEMENT)); MinecraftForge.EVENT_BUS
.post(new RenderGuiOverlayEvent.Post(mc.getWindow(), event.getGuiGraphics(), event.getPartialTick(), ActualOverlay));
} }
/** /**
* Gets the texture from potion effects * 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) { private int getPotionOffset(Player player) {
int potionOffset = 0; int potionOffset = 0;
@ -236,12 +257,13 @@ public class HeartsRenderer {
/** /**
* Renders the health above 10 hearts * Renders the health above 10 hearts
* @param matrixStack Matrix stack instance *
* @param xBasePos Health bar top corner * @param matrixStack Matrix stack instance
* @param yBasePos Health bar top corner * @param xBasePos Health bar top corner
* @param player Player instance * @param yBasePos Health bar top corner
* @param player Player instance
*/ */
private void renderExtraHearts(PoseStack matrixStack, int xBasePos, int yBasePos, Player player) { private void renderExtraHearts(GuiGraphics matrixStack, int xBasePos, int yBasePos, Player player) {
int potionOffset = this.getPotionOffset(player); int potionOffset = this.getPotionOffset(player);
// Extra hearts // Extra hearts
@ -250,15 +272,15 @@ public class HeartsRenderer {
this.renderCustomHearts(matrixStack, xBasePos, yBasePos, potionOffset, hp, false); this.renderCustomHearts(matrixStack, xBasePos, yBasePos, potionOffset, hp, false);
} }
/** /**
* Renders the absorption health above 10 hearts * Renders the absorption health above 10 hearts
* @param matrixStack Matrix stack instance *
* @param xBasePos Health bar top corner * @param matrixStack Matrix stack instance
* @param yBasePos Health bar top corner * @param xBasePos Health bar top corner
* @param player Player instance * @param yBasePos Health bar top corner
* @param player Player instance
*/ */
private void renderExtraAbsorption(PoseStack matrixStack, int xBasePos, int yBasePos, Player player) { private void renderExtraAbsorption(GuiGraphics matrixStack, int xBasePos, int yBasePos, Player player) {
int potionOffset = this.getPotionOffset(player); int potionOffset = this.getPotionOffset(player);
// Extra hearts // Extra hearts
@ -269,8 +291,9 @@ public class HeartsRenderer {
/** /**
* Gets the texture offset from the regen effect * 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) { private int getYRegenOffset(int i, int offset) {
return i + offset == this.regen ? -2 : 0; return i + offset == this.regen ? -2 : 0;
@ -278,6 +301,7 @@ public class HeartsRenderer {
/** /**
* Shared logic to render custom hearts * Shared logic to render custom hearts
*
* @param matrixStack Matrix stack instance * @param matrixStack Matrix stack instance
* @param xBasePos Health bar top corner * @param xBasePos Health bar top corner
* @param yBasePos Health bar top corner * @param yBasePos Health bar top corner
@ -285,7 +309,8 @@ public class HeartsRenderer {
* @param count Number to render * @param count Number to render
* @param absorb If true, render absorption hearts * @param absorb If true, render absorption hearts
*/ */
private void renderCustomHearts(PoseStack matrixStack, int xBasePos, int yBasePos, int potionOffset, int count, boolean absorb) { private void renderCustomHearts(GuiGraphics matrixStack, int xBasePos, int yBasePos, int potionOffset, int count,
boolean absorb) {
int regenOffset = absorb ? 10 : 0; int regenOffset = absorb ? 10 : 0;
for (int iter = 0; iter < count / 20; iter++) { for (int iter = 0; iter < count / 20; iter++) {
int renderHearts = (count - 20 * (iter + 1)) / 2; int renderHearts = (count - 20 * (iter + 1)) / 2;
@ -296,16 +321,16 @@ public class HeartsRenderer {
for (int i = 0; i < renderHearts; i++) { for (int i = 0; i < renderHearts; i++) {
int y = this.getYRegenOffset(i, regenOffset); int y = this.getYRegenOffset(i, regenOffset);
if (absorb) { if (absorb) {
this.blit(matrixStack, xBasePos + 8 * i, yBasePos + y, 0, 54, 9, 9); this.blit(matrixStack, xBasePos + 8 * i, yBasePos + y, 0, 54, 9, 9, ICON_ABSORB);
} }
this.blit(matrixStack, xBasePos + 8 * i, yBasePos + y, 18 * heartIndex, potionOffset, 9, 9); this.blit(matrixStack, xBasePos + 8 * i, yBasePos + y, 18 * heartIndex, potionOffset, 9, 9, ICON_HEARTS);
} }
if (count % 2 == 1 && renderHearts < 10) { if (count % 2 == 1 && renderHearts < 10) {
int y = this.getYRegenOffset(renderHearts, regenOffset); int y = this.getYRegenOffset(renderHearts, regenOffset);
if (absorb) { if (absorb) {
this.blit(matrixStack, xBasePos + 8 * renderHearts, yBasePos + y, 0, 54, 9, 9); this.blit(matrixStack, xBasePos + 8 * renderHearts, yBasePos + y, 0, 54, 9, 9, ICON_ABSORB);
} }
this.blit(matrixStack, xBasePos + 8 * renderHearts, yBasePos + y, 9 + 18 * heartIndex, potionOffset, 9, 9); this.blit(matrixStack, xBasePos + 8 * renderHearts, yBasePos + y, 9 + 18 * heartIndex, potionOffset, 9, 9, ICON_HEARTS);
} }
} }
} }

View file

@ -16,7 +16,7 @@ import java.util.concurrent.CompletableFuture;
public class HomesSuggestionProvider { public class HomesSuggestionProvider {
public static SuggestionProvider<CommandSourceStack> PROVIDER = (ctx,suggestionsBuilder)->{ public static SuggestionProvider<CommandSourceStack> PROVIDER = (ctx,suggestionsBuilder)->{
Homes homes = HomesProvider.getHomesForPlayer(ctx.getSource().getPlayerOrException().getUUID().toString()); Homes homes = HomesProvider.getHomesForPlayer(ctx.getSource().getPlayer().getUUID().toString());
List<String> homesList = new ArrayList<>(); List<String> homesList = new ArrayList<>();

View file

@ -30,10 +30,10 @@ public class ModMessages {
net.messageBuilder(S2CUpdateHearts.class, id(), NetworkDirection.PLAY_TO_CLIENT) net.messageBuilder(S2CUpdateHearts.class, id(), NetworkDirection.PLAY_TO_CLIENT)
.decoder(S2CUpdateHearts::new) .decoder(S2CUpdateHearts::new)
.encoder(S2CUpdateHearts::toBytes) .encoder(S2CUpdateHearts::toBytes)
.consumer(S2CUpdateHearts::handle) .consumerMainThread(S2CUpdateHearts::handle)
.add(); .add();
} }

View file

@ -8,7 +8,6 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.Vec3i; import net.minecraft.core.Vec3i;
import net.minecraft.server.level.ServerLevel; 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.Block;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
@ -21,87 +20,124 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
public class RTP { /**
private static final List<Block> BLACKLIST = Lists.of(Blocks.LAVA, Blocks.WATER, Blocks.BEDROCK); * As of v1.1.121823.x, this is now used for RTP
private final int SEARCH_DIRECTION; * <p>
private final Heightmap.Types heightMapType; * 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.
public WorldPosition position; * <p>
private final ServerLevel dimension; * 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.
private int tries; * <p>
* Every 10 minutes, a new RTP location is scanned. This ensures sufficiently semi-random locations. Eventually old locations will be removed from the list.
* <p>
* 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 RTP(ServerLevel level) { if(position.getActualDimension().dimensionType().hasCeiling())
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; heightMapType = Heightmap.Types.MOTION_BLOCKING_NO_LEAVES;
SEARCH_DIRECTION = -1; SearchDirection=-1;
} else { }else {
heightMapType = Heightmap.Types.MOTION_BLOCKING_NO_LEAVES; heightMapType = Heightmap.Types.MOTION_BLOCKING_NO_LEAVES;
SEARCH_DIRECTION = 1; SearchDirection=1;
} }
} }
private final int SearchDirection;
private Thread containingThread;
private final Heightmap.Types heightMapType;
public WorldPosition position;
private final List<Block> BLACKLIST = Lists.of(Blocks.LAVA, Blocks.WATER, Blocks.BEDROCK);
protected int tries;
protected int lastThreadDelay = 15;
public boolean isDimension(ServerLevel level) { protected RTP withThreadDelay(int delay)
{
lastThreadDelay=delay;
if(lastThreadDelay >= 60) lastThreadDelay = 60;
return this;
}
public boolean isDimension(ServerLevel level)
{
String dim = WorldPosition.getDim(level); String dim = WorldPosition.getDim(level);
return dim.equals(position.Dimension); return dim.equals(position.Dimension);
} }
public BlockPos findSafeLandingLocation() { /**
BlockPos targetPos = position.Position.asBlockPos(); * Searches for, and finds, a valid RTP location
* @param level The level to scan
// Search upward for a safe landing location * @return RTP data
while (!isSafe(targetPos) || !isSafe(targetPos.above())) { */
targetPos = targetPos.above(); public static void find(ServerLevel level)
} {
RandomPositionFactory.beginRTPSearch(level);
return targetPos;
} }
private boolean isSafe(BlockPos blockPos) { public static List<RTP> slicedByDimension(ServerLevel lvl)
BlockState blockState = dimension.getBlockState(blockPos); {
BlockState blockStateAbove = dimension.getBlockState(blockPos.above()); List<RTP> slice = new ArrayList<>();
BlockState blockStateBelow = dimension.getBlockState(blockPos.below());
if (blockState.isAir() && blockStateAbove.isAir()) { Iterator<RTP> it = RTPCaches.Locations.iterator();
if (!blockStateBelow.isAir()) { while(it.hasNext())
return !BLACKLIST.contains(blockStateBelow.getBlock()); {
} else { RTP nxt = it.next();
return false; if(nxt.isDimension(lvl))
{
slice.add(nxt);
} }
} else {
return false;
} }
return slice;
} }
public static RTP getRTP(ServerLevel level) { public static RTP getRTP(ServerLevel level)
{
List<RTP> slice = slicedByDimension(level); List<RTP> slice = slicedByDimension(level);
if (!slice.isEmpty()) { if(slice.size()>0)
RTP ret = slice.get(AriasEssentials.random.nextInt(slice.size())); {
RTP ret = slice.get(AriasEssentials.random.nextInt(0, slice.size()));
RTPCaches.Locations.remove(ret); RTPCaches.Locations.remove(ret);
RandomPositionFactory.beginRTPSearch(ret.position.getActualDimension()); RandomPositionFactory.beginRTPSearch(ret.position.getActualDimension());
return ret; return ret;
} else { } else return null;
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();
} }
} }
public void moveOpposite()
public void move() { {
if (SEARCH_DIRECTION == 1) { if(SearchDirection==1){
position.Position = position.Position.moveUp(); moveDown();
} else if (SEARCH_DIRECTION == -1) { }else if(SearchDirection==0)
position.Position = position.Position.moveDown(); {
moveUp();
} }
} }
public void moveOpposite() {
move();
}
public void newPosition() { public void newPosition() {
if (!AriasEssentials.ALIVE || tries >= 5) return; if (!AriasEssentials.ALIVE || tries >= 25) return;
AriasEssentials.LOGGER.info("RTP starts looking for a new position"); containingThread = Thread.currentThread();
AriasEssentials.LOGGER.info("RTP starts looking for new position");
Random rng = new Random(Instant.now().getEpochSecond()); Random rng = new Random(Instant.now().getEpochSecond());
@ -109,27 +145,37 @@ public class RTP {
BlockPos bpos; BlockPos bpos;
do { do {
pos = new Vector3(rng.nextDouble(0xFFFF), -60, rng.nextDouble(0xFFFF)); pos = new Vector3(rng.nextDouble(0xFFFF), 150, rng.nextDouble(0xFFFF));
pos = spiralPositions(pos); pos = spiralPositions(pos);
position.Position = pos; position.Position = pos;
bpos = pos.asBlockPos(); bpos = pos.asBlockPos();
} while (!isValidPosition(bpos)); } while (!isValidPosition(bpos));
if (pos.y < -30 || pos.y >= position.getActualDimension().getLogicalHeight()) {
newPosition();
return;
}
tries++; tries++;
AriasEssentials.LOGGER.info("RTP returns a new position"); AriasEssentials.LOGGER.info("RTP returns new position");
} }
private boolean isValidPosition(BlockPos bpos) { private boolean isValidPosition(BlockPos bpos) {
ServerLevel dimension = position.getActualDimension();
ChunkStatus status = ChunkStatus.SPAWN; ChunkStatus status = ChunkStatus.SPAWN;
dimension.getChunk(bpos.getX() >> 4, bpos.getZ() >> 4, status); dimension.getChunk(bpos.getX() >> 4, bpos.getZ() >> 4, status);
Vector3 pos = new Vector3(dimension.getHeightmapPos(heightMapType, bpos)); Vector3 pos = new Vector3(dimension.getHeightmapPos(heightMapType, bpos));
return dimension.getWorldBorder().isWithinBounds(pos.asBlockPos()); return dimension.getWorldBorder().isWithinBounds(pos.asBlockPos());
} }
private Vector3 spiralPositions(Vector3 position) { private Vector3 spiralPositions(Vector3 position) {
Vec3i posi = position.asMinecraftVec3i(); Vec3i posi = position.asMinecraftVec3i();
ServerLevel dimension = this.position.getActualDimension();
BlockPos startBlockPos = new BlockPos(posi.getX(), dimension.getSeaLevel(), posi.getZ()); BlockPos startBlockPos = new BlockPos(posi.getX(), dimension.getSeaLevel(), posi.getZ());
for (BlockPos pos : BlockPos.spiralAround(startBlockPos, 16, Direction.WEST, Direction.NORTH)) { for (BlockPos pos : BlockPos.spiralAround(startBlockPos, 16, Direction.WEST, Direction.NORTH)) {
@ -142,17 +188,32 @@ public class RTP {
return position; return position;
} }
public static List<RTP> slicedByDimension(ServerLevel lvl) {
List<RTP> slice = new ArrayList<>();
Iterator<RTP> it = RTPCaches.Locations.iterator(); private boolean safe(BlockPos blockPos)
while (it.hasNext()) { {
RTP nxt = it.next(); containingThread=Thread.currentThread();
if (nxt.isDimension(lvl)) { BlockState b = position.getActualDimension().getBlockState(blockPos);
slice.add(nxt); BlockState b2 = position.getActualDimension().getBlockState(blockPos.above());
} BlockState b3 = position.getActualDimension().getBlockState(blockPos.below());
}
return slice; 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;*/
} }
} }

View file

@ -4,9 +4,7 @@ import dev.zontreck.essentials.AriasEssentials;
import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.Messages;
import dev.zontreck.essentials.commands.teleport.TeleportActioner; import dev.zontreck.essentials.commands.teleport.TeleportActioner;
import dev.zontreck.essentials.events.RTPFoundEvent; import dev.zontreck.essentials.events.RTPFoundEvent;
import dev.zontreck.libzontreck.LibZontreck;
import dev.zontreck.libzontreck.util.ChatHelpers; import dev.zontreck.libzontreck.util.ChatHelpers;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.TickEvent;
@ -21,7 +19,6 @@ public class RTPCachesEventHandlers
{ {
if(!AriasEssentials.ALIVE) return; if(!AriasEssentials.ALIVE) return;
lastTick++; lastTick++;
MinecraftServer server = LibZontreck.THE_SERVER;
if(lastTick>=400) if(lastTick>=400)
{ {
lastTick=0; lastTick=0;
@ -34,7 +31,7 @@ public class RTPCachesEventHandlers
firstRun=false; firstRun=false;
AriasEssentials.LOGGER.info("Aria's Essentials startup is running. Scanning for initial RTP locations"); AriasEssentials.LOGGER.info("Aria's Essentials startup is running. Scanning for initial RTP locations");
for(ServerLevel level : server.getAllLevels()) for(ServerLevel level : event.getServer().getAllLevels())
{ {
if(AriasEssentials.DEBUG) if(AriasEssentials.DEBUG)
{ {

View file

@ -0,0 +1,24 @@
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) {
}
}
}

View file

@ -0,0 +1,5 @@
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

View file

@ -6,67 +6,71 @@
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml # The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
modLoader="javafml" #mandatory modLoader="javafml" #mandatory
# A version range to match for said mod loader - for regular FML @Mod it will be the forge version # A version range to match for said mod loader - for regular FML @Mod it will be the forge version
loaderVersion="[40,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. loaderVersion="${loader_version_range}" #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. # 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. # Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here.
license="GPLv3" license="${mod_license}"
# A URL to refer people to when problems occur with this mod # A URL to refer people to when problems occur with this mod
#issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional issueTrackerURL="https://github.com/zontreck/Arias-Essentials/issues/" #optional
# A list of mods - how many allowed here is determined by the individual mod loader # A list of mods - how many allowed here is determined by the individual mod loader
[[mods]] #mandatory [[mods]] #mandatory
# The modid of the mod # The modid of the mod
modId="ariasessentials" #mandatory modId="${mod_id}" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it # The version number of the mod
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata version="${mod_version}" #mandatory
# 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 # A display name for the mod
displayName="Aria's Essentials" #mandatory displayName="${mod_name}" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/ # A URL to query for updates for this mod. See the JSON update specification https://docs.minecraftforge.net/en/latest/misc/updatechecker/
#updateJSONURL="https://change.me.example.invalid/updates.json" #optional #updateJSONURL="https://change.me.example.invalid/updates.json" #optional
# A URL for the "homepage" for this mod, displayed in the mod UI # A URL for the "homepage" for this mod, displayed in the mod UI
#displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional #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 # A file name (in the root of the mod JAR) containing a logo for display
logoFile="ariasessentials.png" #optional logoFile="ariasessentials.png" #optional
# A text field displayed in the mod UI # A text field displayed in the mod UI
credits="Thanks for this example mod goes to Java" #optional #credits="" #optional
# A text field displayed in the mod UI # A text field displayed in the mod UI
authors="Love, Cheese and small house plants" #optional authors="${mod_authors}" #optional
# Display Test controls the display for your mod in the server connection screen # 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. # 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_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. # 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. # 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. # 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) # The description text for the mod (multi line!) (#mandatory)
description=''' description='''${mod_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. # A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
[[dependencies.ariasessentials]] #optional [[dependencies.${mod_id}]] #optional
# the modid of the dependency # the modid of the dependency
modId="forge" #mandatory modId="forge" #mandatory
# Does this dependency have to exist - if not, ordering below must be specified # Does this dependency have to exist - if not, ordering below must be specified
mandatory=true #mandatory mandatory=true #mandatory
# The version range of the dependency # The version range of the dependency
versionRange="[40,)" #mandatory versionRange="${forge_version_range}" #mandatory
# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory # An ordering relationship for the dependency - BEFORE or AFTER required if the dependency is not mandatory
ordering="NONE" # BEFORE - This mod is loaded BEFORE the dependency
# Side this dependency is applied on - BOTH, CLIENT or SERVER # AFTER - This mod is loaded AFTER the dependency
side="BOTH" ordering="NONE"
# Side this dependency is applied on - BOTH, CLIENT, or SERVER
side="BOTH"
# Here's another dependency # Here's another dependency
[[dependencies.ariasessentials]] [[dependencies.${mod_id}]]
modId="minecraft" modId="minecraft"
mandatory=true mandatory=true
# This version range declares a minimum of the current minecraft version up to but not including the next major version # 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)" versionRange="${minecraft_version_range}"
ordering="NONE" ordering="NONE"
side="BOTH" side="BOTH"
[[dependencies.libzontreck]] [[dependencies.${mod_id}]]
modId="libzontreck" modId="libzontreck"
mandatory=true mandatory=true
versionRange="[1.10,1.11)" versionRange="[1.10,1.11)"
ordering="NONE" ordering="NONE"
side="BOTH" 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,)"

View file

@ -1,8 +1,8 @@
{ {
"pack": { "pack": {
"description": "Aria's Essentials resources", "description": {
"pack_format": 9, "text": "${mod_id} resources"
"forge:resource_pack_format": 8, },
"forge:data_pack_format": 9 "pack_format": 15
} }
} }