プレイヤーのディメンション移動をTeleporterを介さずに安全に行います。
ライセンスはWTFPLライセンスです。勝手に改変だとかコピペだとかしちゃってください。
環境: Forge 10.13.0.1180
他のバージョンでも必要に応じて多少修正すれば使えると思います。
- コード: 全て選択
public static EntityPlayerMP respawnPlayer(EntityPlayerMP player, int dim)
{
player.isDead = false;
player.forceSpawn = true;
player.timeUntilPortal = player.getPortalCooldown();
player.playerNetServerHandler.playerEntity = player.mcServer.getConfigurationManager().respawnPlayer(player, dim, true);
return player.playerNetServerHandler.playerEntity;
}
public static EntityPlayerMP forceTeleport(EntityPlayerMP player, int dim)
{
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
int dimOld = player.dimension;
WorldServer world = server.worldServerForDimension(dim);
if (dim != player.dimension)
{
player = respawnPlayer(player, dim);
FMLCommonHandler.instance().bus().post(new PlayerChangedDimensionEvent(player, dimOld, dim));
}
ChunkCoordinates spawn = world.getSpawnPoint();
int var1 = 64;
for (int x = spawn.posX - var1; x < spawn.posX + var1; ++x)
{
for (int z = spawn.posZ - var1; z < spawn.posZ + var1; ++z)
{
for (int y = world.getActualHeight() - 3; y > world.provider.getAverageGroundLevel(); --y)
{
if (world.isAirBlock(x, y, z) && world.isAirBlock(x, y + 1, z) &&
world.isAirBlock(x - 1, y, z) && world.isAirBlock(x - 1, y + 1, z) &&
world.isAirBlock(x + 1, y, z) && world.isAirBlock(x + 1, y + 1, z) &&
world.isAirBlock(x, y, z - 1) && world.isAirBlock(x, y + 1, z - 1) &&
world.isAirBlock(x, y, z + 1) && world.isAirBlock(x, y + 1, z + 1) &&
!world.getBlock(x, y - 1, z).getMaterial().isLiquid())
{
while (world.isAirBlock(x, y - 1, z))
{
--y;
}
if (!world.getBlock(x, y - 1, z).getMaterial().isLiquid())
{
player.playerNetServerHandler.setPlayerLocation(x + 0.5D, y + 0.8D, z + 0.5D, player.rotationYaw, player.rotationPitch);
player.addExperienceLevel(0);
return player;
}
}
}
}
}
return player;
}
respawnPlayerメソッドで実際にディメンションを移動させた後、forceTeleportで安全な場所を探しまわっています。
別のディメンションに手っ取り早く強制送還したいときに使ってます。