Some small steps regarding teleportation

This commit is contained in:
Mathijs Riezebos 2017-01-19 06:23:46 +01:00
parent 30c86f1e16
commit 3ffbe2ad03
5 changed files with 69 additions and 12 deletions

View file

@ -7,6 +7,7 @@ package com.zixiken.dimdoors;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
@ -23,6 +24,8 @@ public interface IDDProxy {
public void onInitialization(FMLInitializationEvent event);
public EntityPlayer getLocalPlayer();
public WorldServer getWorldServer(int dimId);
public World getDefWorld();
}

View file

@ -7,7 +7,7 @@ import com.zixiken.dimdoors.tileentities.TileEntityTransTrapdoor;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
@ -38,6 +38,11 @@ public class DDProxyClient extends DDProxyCommon {
@Override
public World getDefWorld() {
return Minecraft.getMinecraft().getIntegratedServer().worldServerForDimension(0); //gets the client world dim 0 handler
return getWorldServer(0); //gets the client world dim 0 handler
}
@Override
public WorldServer getWorldServer(int dimId) {
return Minecraft.getMinecraft().getIntegratedServer().worldServerForDimension(dimId);
}
}

View file

@ -8,6 +8,7 @@ package com.zixiken.dimdoors.server;
import com.zixiken.dimdoors.DDProxyCommon;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
/**
@ -28,7 +29,12 @@ public class DDProxyServer extends DDProxyCommon {
@Override
public World getDefWorld() {
return DimensionManager.getWorld(0); //gets the server world dim 0 handler
return getWorldServer(0); //gets the server world dim 0 handler
}
@Override
public WorldServer getWorldServer(int dimId) {
return DimensionManager.getWorld(dimId);
}
}

View file

@ -6,6 +6,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
/**
@ -46,7 +47,7 @@ public class Location {
return pos;
}
public World getWorld() {
public WorldServer getWorld() {
return DimensionManager.getWorld(dimensionID);
}

View file

@ -1,17 +1,25 @@
package com.zixiken.dimdoors.shared;
import com.zixiken.dimdoors.DimDoors;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.play.server.SPacketUpdateHealth;
import net.minecraft.server.management.PlayerList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Teleporter;
import net.minecraft.world.WorldServer;
public class TeleportHelper extends Teleporter {
Location location;
private final Location location;
public TeleportHelper(Location location) {
public TeleportHelper(Location location) {//@todo make TeleportHelper static
super((WorldServer) location.getWorld());
this.location = location;
}
@Override
@ -21,11 +29,45 @@ public class TeleportHelper extends Teleporter {
}
public static void teleport(Entity entity, Location location) {
Teleporter tele = new TeleportHelper(location);
if (entity instanceof EntityPlayerMP) {
location.getWorld().getMinecraftServer().getPlayerList().transferPlayerToDimension((EntityPlayerMP) entity, location.getDimensionID(), tele);
} else {
location.getWorld().getMinecraftServer().getPlayerList().transferEntityToWorld(entity, entity.world.provider.getDimension(), (WorldServer) entity.world, (WorldServer) location.getWorld(), tele);
if (entity instanceof EntityPlayerSP) {
return;
}
BlockPos newPos = location.getPos();
int oldDimID = entity.dimension;
int newDimID = location.getDimensionID();
WorldServer oldWorldServer = DimDoors.proxy.getWorldServer(oldDimID);
WorldServer newWorldServer = DimDoors.proxy.getWorldServer(newDimID);
if (oldDimID == newDimID) {
if (entity instanceof EntityPlayer) {
EntityPlayerMP player = (EntityPlayerMP) entity;
player.setPositionAndUpdate(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5);
player.world.updateEntityWithOptionalForce(player, false);
//player.connection.sendPacket(new SPacketUpdateHealth(player.getHealth(), player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel()));
player.timeUntilPortal = 150;
} else {
WorldServer world = (WorldServer) entity.world;
entity.setPosition(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5);
entity.timeUntilPortal = 150;
world.resetUpdateEntityTick();
}
} else {
if (entity instanceof EntityPlayer) {
EntityPlayerMP player = (EntityPlayerMP) entity;
player.changeDimension(newDimID);
player.setPositionAndUpdate(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5);
player.world.updateEntityWithOptionalForce(player, false);
//player.connection.sendPacket(new SPacketUpdateHealth(player.getHealth(), player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel()));
} else if (!entity.world.isRemote) {
entity.changeDimension(newDimID);
entity.setPosition(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5);
oldWorldServer.resetUpdateEntityTick();
newWorldServer.resetUpdateEntityTick();
}
}
//@todo set player angle in front of and facing away from the door
}
}
}