mirror of
https://github.com/GTNewHorizons/Opis.git
synced 2026-11-22 13:09:53 +00:00
The whole teleportation is now handled properly. It shouldn't create portals anymore.
It could use a bit more cleanup and additions to fix nether tp and such (move that from EntityManager)
This commit is contained in:
1 parent
80d315a5a4
commit
8410825ec1
2 files changed
+170
-10
No files matched your search
@@ -3,26 +3,38 @@ package mcp.mobius.opis.data.managers;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.network.packet.Packet3Chat;
|
||||
import net.minecraft.network.packet.Packet41EntityEffect;
|
||||
import net.minecraft.network.packet.Packet9Respawn;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.Teleporter;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldProvider;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import mcp.mobius.opis.data.holders.basetypes.AmountHolder;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesBlock;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesChunk;
|
||||
import mcp.mobius.opis.data.holders.stats.StatsEntity;
|
||||
import mcp.mobius.opis.data.holders.stats.StatsPlayer;
|
||||
import mcp.mobius.opis.helpers.Teleport;
|
||||
|
||||
public class EntityManager {
|
||||
|
||||
@@ -273,10 +285,10 @@ public class EntityManager {
|
||||
|
||||
if (!canTeleport) return false;
|
||||
|
||||
if (player.worldObj.provider.dimensionId != coord.dim)
|
||||
player.travelToDimension(coord.dim);
|
||||
|
||||
player.setPositionAndUpdate(finalTarget.x + 0.5, finalTarget.y, finalTarget.z + 0.5);
|
||||
if (Teleport.instance().movePlayerToDimension(player, coord.dim))
|
||||
player.setPositionAndUpdate(finalTarget.x + 0.5, finalTarget.y, finalTarget.z + 0.5);
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -292,15 +304,23 @@ public class EntityManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (src.worldObj.provider.dimensionId != trg.worldObj.provider.dimensionId)
|
||||
src.travelToDimension(trg.worldObj.provider.dimensionId);
|
||||
|
||||
src.setLocationAndAngles(trg.posX, trg.posY, trg.posZ, src.rotationYaw, src.rotationPitch);
|
||||
|
||||
if (src instanceof EntityPlayerMP){
|
||||
if (Teleport.instance().movePlayerToDimension((EntityPlayerMP)src, trg.worldObj.provider.dimensionId))
|
||||
src.setLocationAndAngles(trg.posX, trg.posY, trg.posZ, src.rotationYaw, src.rotationPitch);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
if (Teleport.instance().moveEntityToDimension(src, trg.worldObj.provider.dimensionId))
|
||||
src.setLocationAndAngles(trg.posX, trg.posY, trg.posZ, src.rotationYaw, src.rotationPitch);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static Entity getEntity(int eid, int dim){
|
||||
World world = DimensionManager.getWorld(dim);
|
||||
if (world == null) return null;
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
package mcp.mobius.opis.helpers;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.packet.Packet41EntityEffect;
|
||||
import net.minecraft.network.packet.Packet9Respawn;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.management.ServerConfigurationManager;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.Teleporter;
|
||||
import net.minecraft.world.WorldProvider;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
public class Teleport {
|
||||
|
||||
private static Teleport _instance = new Teleport();
|
||||
public static Teleport instance(){return _instance;};
|
||||
|
||||
// Originally in EntityPlayerMP
|
||||
public boolean movePlayerToDimension(EntityPlayerMP player, int dim)
|
||||
{
|
||||
return this.transferPlayerToDimension(player.mcServer.getConfigurationManager(), player, dim);
|
||||
}
|
||||
|
||||
// Originally in ServerConfigurationManager
|
||||
public boolean transferPlayerToDimension(ServerConfigurationManager manager, EntityPlayerMP player, int targetID)
|
||||
{
|
||||
int sourceID = player.dimension;
|
||||
WorldServer sourceWorld = DimensionManager.getWorld(player.dimension);
|
||||
WorldServer targetWorld = DimensionManager.getWorld(targetID);
|
||||
|
||||
if (sourceID == targetID) return true;
|
||||
if (sourceWorld == null || targetWorld == null) return false;
|
||||
|
||||
player.dimension = targetID;
|
||||
|
||||
player.playerNetServerHandler.sendPacketToPlayer(new Packet9Respawn(player.dimension, (byte)player.worldObj.difficultySetting, targetWorld.getWorldInfo().getTerrainType(), targetWorld.getHeight(), player.theItemInWorldManager.getGameType()));
|
||||
sourceWorld.removePlayerEntityDangerously(player);
|
||||
player.isDead = false;
|
||||
this.transferEntityToWorld(player, sourceID, sourceWorld, targetWorld);
|
||||
this.preloadChunk(player, sourceWorld);
|
||||
|
||||
player.playerNetServerHandler.setPlayerLocation(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch);
|
||||
player.theItemInWorldManager.setWorld(targetWorld);
|
||||
|
||||
manager.updateTimeAndWeatherForPlayer(player, targetWorld);
|
||||
manager.syncPlayerInventory(player);
|
||||
Iterator iterator = player.getActivePotionEffects().iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
PotionEffect potioneffect = (PotionEffect)iterator.next();
|
||||
player.playerNetServerHandler.sendPacketToPlayer(new Packet41EntityEffect(player.entityId, potioneffect));
|
||||
}
|
||||
|
||||
GameRegistry.onPlayerChangedDimension(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Originally in ServerConfigurationManager
|
||||
public void preloadChunk(EntityPlayerMP player, WorldServer sourceWorld)
|
||||
{
|
||||
WorldServer otherWorld = player.getServerForPlayer();
|
||||
|
||||
if (sourceWorld != null)
|
||||
{
|
||||
sourceWorld.getPlayerManager().removePlayer(player);
|
||||
}
|
||||
|
||||
otherWorld.getPlayerManager().addPlayer(player);
|
||||
otherWorld.theChunkProviderServer.loadChunk((int)player.posX >> 4, (int)player.posZ >> 4);
|
||||
}
|
||||
|
||||
public void transferEntityToWorld(Entity ent, int dim, WorldServer srcWorld, WorldServer trgWorld)
|
||||
{
|
||||
WorldProvider pOld = srcWorld.provider;
|
||||
WorldProvider pNew = trgWorld.provider;
|
||||
double moveFactor = pOld.getMovementFactor() / pNew.getMovementFactor();
|
||||
double d0 = ent.posX * moveFactor;
|
||||
double d1 = ent.posZ * moveFactor;
|
||||
double d3 = ent.posX;
|
||||
double d4 = ent.posY;
|
||||
double d5 = ent.posZ;
|
||||
float f = ent.rotationYaw;
|
||||
|
||||
srcWorld.theProfiler.startSection("placing");
|
||||
d0 = (double)MathHelper.clamp_int((int)d0, -29999872, 29999872);
|
||||
d1 = (double)MathHelper.clamp_int((int)d1, -29999872, 29999872);
|
||||
|
||||
if (ent.isEntityAlive())
|
||||
{
|
||||
trgWorld.spawnEntityInWorld(ent);
|
||||
ent.setLocationAndAngles(d0, ent.posY, d1, ent.rotationYaw, ent.rotationPitch);
|
||||
trgWorld.updateEntityWithOptionalForce(ent, false);
|
||||
}
|
||||
|
||||
ent.setWorld(trgWorld);
|
||||
}
|
||||
|
||||
public boolean moveEntityToDimension(Entity target, int targetID)
|
||||
{
|
||||
if (!target.worldObj.isRemote && !target.isDead)
|
||||
{
|
||||
MinecraftServer server = MinecraftServer.getServer();
|
||||
int sourceID = target.dimension;
|
||||
WorldServer sourceWorld = DimensionManager.getWorld(sourceID);
|
||||
WorldServer targetWorld = DimensionManager.getWorld(targetID);
|
||||
|
||||
if (sourceID == targetID) return true;
|
||||
if (sourceWorld == null || targetWorld == null) return false;
|
||||
|
||||
target.dimension = targetID;
|
||||
|
||||
target.worldObj.removeEntity(target);
|
||||
target.isDead = false;
|
||||
this.transferEntityToWorld(target, sourceID, sourceWorld, targetWorld);
|
||||
Entity entity = EntityList.createEntityByName(EntityList.getEntityString(target), targetWorld);
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
entity.copyDataFrom(target, true);
|
||||
targetWorld.spawnEntityInWorld(entity);
|
||||
}
|
||||
|
||||
target.isDead = true;
|
||||
sourceWorld.resetUpdateEntityTick();
|
||||
targetWorld.resetUpdateEntityTick();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user