Utilize the new LibZ teleport event

This commit is contained in:
Zontreck 2024-02-18 08:53:11 -07:00
parent 2f3e867fe5
commit 81ab188c62
3 changed files with 21 additions and 10 deletions

View file

@ -3,7 +3,7 @@
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
libzontreck=1201.11.021824.0409
libzontreck=1201.11.021824.0838
## Environment Properties
@ -48,7 +48,7 @@ mod_name=Thresholds
# 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=1201.4.021824.0806
mod_version=1201.4.021824.0846
# 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

View file

@ -1,6 +1,7 @@
package dev.zontreck.otemod.commands.dims;
import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.libzontreck.events.TeleportEvent;
import dev.zontreck.libzontreck.exceptions.InvalidDeserialization;
import dev.zontreck.libzontreck.util.ChatHelpers;
import dev.zontreck.libzontreck.vectors.Vector3;
@ -13,6 +14,8 @@ import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.commands.ExperienceCommand;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.server.command.EnumArgument;
public class BuildCommand
@ -33,30 +36,33 @@ public class BuildCommand
{
if(stack.isPlayer())
{
boolean playerIsOp = stack.getPlayer().hasPermissions(stack.getServer().getOperatorUserPermissionLevel());
ServerPlayer sp = stack.getPlayer();
boolean playerIsOp = sp.hasPermissions(stack.getServer().getOperatorUserPermissionLevel());
if(playerIsOp || OTEServerConfig.ALLOW_BUILDER_DIM.get())
{
if(direction == Options.enter)
{
WorldPosition save = new WorldPosition(stack.getPlayer());
PerPlayerDataRegistry.put(stack.getPlayer().getUUID(), "builder_entered_from", save.serialize());
WorldPosition save = new WorldPosition(sp);
PerPlayerDataRegistry.put(sp.getUUID(), "builder_entered_from", save.serialize());
WorldPosition pos = new WorldPosition(new Vector3(0, -55, 0), ModDimensions.BUILDER_DIM());
stack.getPlayer().teleportTo(pos.getActualDimension(), pos.Position.x, pos.Position.y, pos.Position.z, 0, 0);
if(!MinecraftForge.EVENT_BUS.post(new TeleportEvent(pos, sp)))
stack.getPlayer().teleportTo(pos.getActualDimension(), pos.Position.x, pos.Position.y, pos.Position.z, 0, 0);
return 0;
} else if(direction == Options.leave) {
CompoundTag tag = (CompoundTag) PerPlayerDataRegistry.get(stack.getPlayer().getUUID(), "builder_entered_from");
CompoundTag tag = (CompoundTag) PerPlayerDataRegistry.get(sp.getUUID(), "builder_entered_from");
if(tag != null)
{
try {
WorldPosition pos = new WorldPosition(tag, false);
stack.getPlayer().teleportTo(pos.getActualDimension(), pos.Position.x, pos.Position.y, pos.Position.z, 0,0);
if(!MinecraftForge.EVENT_BUS.post(new TeleportEvent(pos, sp)))
sp.teleportTo(pos.getActualDimension(), pos.Position.x, pos.Position.y, pos.Position.z, 0,0);
} catch (InvalidDeserialization e) {
throw new RuntimeException(e);
}
@ -67,7 +73,7 @@ public class BuildCommand
return 0;
} else return 0;
}else {
ChatHelpers.broadcastTo(stack.getPlayer(), ChatHelpers.macro(Messages.BUILDER_DIMENSION_DISALLOWED), stack.getServer());
ChatHelpers.broadcastTo(sp, ChatHelpers.macro(Messages.BUILDER_DIMENSION_DISALLOWED), stack.getServer());
return 0;
}

View file

@ -1,5 +1,6 @@
package dev.zontreck.otemod.events;
import dev.zontreck.libzontreck.events.TeleportEvent;
import dev.zontreck.libzontreck.lore.LoreContainer;
import dev.zontreck.libzontreck.lore.LoreEntry;
import dev.zontreck.libzontreck.profiles.Profile;
@ -34,6 +35,7 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.GameType;
import net.minecraftforge.common.ForgeSpawnEggItem;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
@ -127,7 +129,10 @@ public class EventHandler {
// Teleport the player to Thresholds
WorldPosition pos = new WorldPosition(new Vector3(), ModDimensions.THRESHOLD_DIM());
ServerPlayer sp = (ServerPlayer) ev.getEntity();
sp.teleportTo(pos.getActualDimension(), 0, 365, 0, 0,0);
if(!MinecraftForge.EVENT_BUS.post(new TeleportEvent(pos, sp)))
sp.teleportTo(pos.getActualDimension(), 0, 365, 0, 0,0);
}
}