From 4a476c2f37f054ccb5ad68925753974c8e09140c Mon Sep 17 00:00:00 2001 From: Mary Hopson Date: Sun, 12 Jul 2026 06:07:22 -0400 Subject: [PATCH] Default dimension respawn to player spawn coordinates if unset --- .../common/blocks/BlockPortalEndOfTime.java | 14 +++++++++++++- .../common/blocks/BlockPortalUnderWorld.java | 13 ++++++++++++- .../endoftime/EndOfTimeSourceProperty.java | 3 +++ .../underworld/UnderWorldSourceProperty.java | 3 +++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockPortalEndOfTime.java b/src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockPortalEndOfTime.java index 84c90838a..8a1d7dddf 100644 --- a/src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockPortalEndOfTime.java +++ b/src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockPortalEndOfTime.java @@ -97,11 +97,21 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer p } EndOfTimeSourceProperty source = (EndOfTimeSourceProperty) player .getExtendedProperties(EndOfTimeSourceProperty.PROP_KEY); + WorldServer dest = MinecraftServer.getServer() .worldServerForDimension(source.entranceWorld); + BlockPos spawn = findSpawnLocation(dest, source.entranceX, source.entranceY, source.entranceZ); - if (spawn == null) { + + if (!source.isSet || spawn == null) { + ChunkCoordinates playerSpawn = player.getBedLocation(0); + if (playerSpawn != null) playerSpawn = EntityPlayer.verifyRespawnCoordinates(dest, playerSpawn, false); + if (playerSpawn == null) { + playerSpawn = dest.getSpawnPoint(); + playerSpawn.posY = dest.getTopSolidOrLiquidBlock(playerSpawn.posX, playerSpawn.posZ); + } player.addChatComponentMessage(new ChatComponentTranslation("uie.chat.portal.blocked")); + teleport((EntityPlayerMP) player, dest, playerSpawn.posX, playerSpawn.posY, playerSpawn.posZ); } else { teleport((EntityPlayerMP) player, dest, spawn.x, spawn.y, spawn.z); } @@ -122,6 +132,8 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer p source.entranceX = x; source.entranceY = y; source.entranceZ = z; + source.isSet = true; + teleport((EntityPlayerMP) player, dest, spawn.posX, spawn.posY + 1, spawn.posZ); } return true; diff --git a/src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockPortalUnderWorld.java b/src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockPortalUnderWorld.java index 8811cd3d4..78725ee75 100644 --- a/src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockPortalUnderWorld.java +++ b/src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockPortalUnderWorld.java @@ -11,6 +11,7 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.ChunkCoordinates; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; @@ -116,8 +117,17 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer p BlockPos spawn = findSpawnLocation(dest, source.entranceX, source.entranceY, source.entranceZ); - if (spawn == null) { + if (!source.isSet || spawn == null) { + ChunkCoordinates playerSpawn = player.getBedLocation(0); + if (playerSpawn != null) + playerSpawn = EntityPlayer.verifyRespawnCoordinates(dest, playerSpawn, false); + if (playerSpawn == null) { + playerSpawn = dest.getSpawnPoint(); + playerSpawn.posY = dest.getTopSolidOrLiquidBlock(playerSpawn.posX, playerSpawn.posZ); + } + player.addChatComponentMessage(new ChatComponentTranslation("uie.chat.portal.blocked")); + teleport((EntityPlayerMP) player, dest, playerSpawn.posX, playerSpawn.posY, playerSpawn.posZ); } else { teleport((EntityPlayerMP) player, dest, spawn.x, spawn.y, spawn.z); } @@ -159,6 +169,7 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer p source.entranceX = x; source.entranceY = y; source.entranceZ = z; + source.isSet = true; teleport((EntityPlayerMP) player, dest, spawn.x, spawn.y + 1, spawn.z); } diff --git a/src/main/java/com/fouristhenumber/utilitiesinexcess/common/dimensions/endoftime/EndOfTimeSourceProperty.java b/src/main/java/com/fouristhenumber/utilitiesinexcess/common/dimensions/endoftime/EndOfTimeSourceProperty.java index d81312809..0084b9f29 100644 --- a/src/main/java/com/fouristhenumber/utilitiesinexcess/common/dimensions/endoftime/EndOfTimeSourceProperty.java +++ b/src/main/java/com/fouristhenumber/utilitiesinexcess/common/dimensions/endoftime/EndOfTimeSourceProperty.java @@ -18,6 +18,7 @@ public class EndOfTimeSourceProperty implements IExtendedEntityProperties { public static final String PROP_KEY = "end-of-time-source"; public int entranceX, entranceY, entranceZ, entranceWorld; + public boolean isSet; @Override public void saveNBTData(NBTTagCompound compound) { @@ -28,6 +29,7 @@ public void saveNBTData(NBTTagCompound compound) { tag.setInteger("entranceY", entranceY); tag.setInteger("entranceZ", entranceZ); tag.setInteger("entranceWorld", entranceWorld); + tag.setBoolean("isSet", isSet); } @Override @@ -39,6 +41,7 @@ public void loadNBTData(NBTTagCompound compound) { entranceY = tag.getInteger("entranceY"); entranceZ = tag.getInteger("entranceZ"); entranceWorld = tag.getInteger("entranceWorld"); + isSet = tag.getBoolean("isSet"); } } diff --git a/src/main/java/com/fouristhenumber/utilitiesinexcess/common/dimensions/underworld/UnderWorldSourceProperty.java b/src/main/java/com/fouristhenumber/utilitiesinexcess/common/dimensions/underworld/UnderWorldSourceProperty.java index fe7d6de7e..bdd66ee32 100644 --- a/src/main/java/com/fouristhenumber/utilitiesinexcess/common/dimensions/underworld/UnderWorldSourceProperty.java +++ b/src/main/java/com/fouristhenumber/utilitiesinexcess/common/dimensions/underworld/UnderWorldSourceProperty.java @@ -18,6 +18,7 @@ public class UnderWorldSourceProperty implements IExtendedEntityProperties { public static final String PROP_KEY = "underworld-source"; public int entranceX, entranceY, entranceZ, entranceWorld; + public boolean isSet; @Override public void saveNBTData(NBTTagCompound compound) { @@ -28,6 +29,7 @@ public void saveNBTData(NBTTagCompound compound) { tag.setInteger("entranceY", entranceY); tag.setInteger("entranceZ", entranceZ); tag.setInteger("entranceWorld", entranceWorld); + tag.setBoolean("isSet", isSet); } @Override @@ -39,6 +41,7 @@ public void loadNBTData(NBTTagCompound compound) { entranceY = tag.getInteger("entranceY"); entranceZ = tag.getInteger("entranceZ"); entranceWorld = tag.getInteger("entranceWorld"); + isSet = tag.getBoolean("isSet"); } }