Add the game mechanic for warping the player directly to Thresholds when falling out of the world.

This commit is contained in:
Zontreck 2024-02-18 08:21:34 -07:00
parent a644bf3994
commit 27b184a040

View file

@ -7,6 +7,7 @@ import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
import dev.zontreck.libzontreck.util.ChatHelpers;
import dev.zontreck.libzontreck.util.ItemUtils;
import dev.zontreck.libzontreck.util.heads.HeadUtilities;
import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.libzontreck.vectors.WorldPosition;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.configs.OTEServerConfig;
@ -22,6 +23,9 @@ import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.ServerPlayerGameMode;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageSources;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.ItemEntity;
@ -32,6 +36,7 @@ import net.minecraft.world.level.GameType;
import net.minecraftforge.common.ForgeSpawnEggItem;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -111,6 +116,23 @@ public class EventHandler {
}
}
@SubscribeEvent
public void onPlayerFallOutOfWorld(LivingHurtEvent ev)
{
if(ev.getEntity() instanceof Player)
{
if(ev.getSource().is(DamageTypes.FELL_OUT_OF_WORLD))
{
// 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);
}
}
}
@SubscribeEvent
public void onEntityKilled(LivingDropsEvent ev){
if(ev.getEntity().level().isClientSide)return;