More teleportation fixes

Made teleporting check whether door is opened and close it again on
teleportation.
Added some more debug logging.
Made the teleportation methods one "string" of boolean methods,
returning false if anything would go amiss.
Implemented 150 ticks waiting time inbetween teleports
finetuned getTeleportTargetLocation method, but it somehow gets reset on
server restart.
This commit is contained in:
Mathijs Riezebos 2017-01-19 16:28:18 +01:00
parent 8624934d26
commit a9f2f3a82d
6 changed files with 41 additions and 22 deletions

View file

@ -35,18 +35,16 @@ public abstract class BlockDimDoorBase extends BlockDoor implements IDimDoor, IT
@Override @Override
public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) { public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) {
IBlockState down = world.getBlockState(pos.down()); IBlockState down = world.getBlockState(pos.down());
if (!world.isRemote && down.getBlock() == this) { if (!world.isRemote && down.getBlock() == this) { //@todo should only teleport when colliding with top part of the door?
if (down.getValue(BlockDoor.OPEN) if (down.getValue(BlockDoor.OPEN)
&& entity instanceof EntityPlayer && entity instanceof EntityPlayer //@todo remove this so any entity can go through?
&& (entity.timeUntilPortal < 1) //to prevent the player from teleporting all over the place we have a 150-tick cooldown
&& isEntityFacingDoor(down, (EntityLivingBase) entity)) { && isEntityFacingDoor(down, (EntityLivingBase) entity)) {
this.toggleDoor(world, pos, false); this.toggleDoor(world, pos, false);
DimDoors.log(this.getClass(), "Facing direction of Door-block that was just entered by an entity is: "
+ world.getBlockState(pos).getValue(BlockDoor.FACING));
enterDimDoor(world, pos, entity); enterDimDoor(world, pos, entity);
} }
} else {
BlockPos up = pos.up();
if (world.getBlockState(up).getBlock() == this) {
enterDimDoor(world, up, entity);
}
} }
} }
@ -125,8 +123,10 @@ public abstract class BlockDimDoorBase extends BlockDoor implements IDimDoor, IT
public void enterDimDoor(World world, BlockPos pos, Entity entity) { public void enterDimDoor(World world, BlockPos pos, Entity entity) {
DDTileEntityBase riftTile = getRiftTile(world, pos, world.getBlockState(pos)); DDTileEntityBase riftTile = getRiftTile(world, pos, world.getBlockState(pos));
if (riftTile.tryTeleport(entity)) { if (riftTile.tryTeleport(entity)) {
DimDoors.log(this.getClass(), "Entity was teleported succesfully");
//player is succesfully teleported //player is succesfully teleported
} else { } else {
DimDoors.log(this.getClass(), "Entity was NOT teleported succesfully");
//@todo some kind of message that teleporting wasn't successfull //@todo some kind of message that teleporting wasn't successfull
//probably should only happen on personal dimdoors //probably should only happen on personal dimdoors
} }

View file

@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import com.zixiken.dimdoors.DimDoors; import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.blocks.BlockDimDoor;
import com.zixiken.dimdoors.blocks.BlockDimDoorBase; import com.zixiken.dimdoors.blocks.BlockDimDoorBase;
import com.zixiken.dimdoors.blocks.ModBlocks; import com.zixiken.dimdoors.blocks.ModBlocks;
import com.zixiken.dimdoors.tileentities.DDTileEntityBase; import com.zixiken.dimdoors.tileentities.DDTileEntityBase;
@ -65,17 +66,17 @@ public abstract class ItemDoorBase extends ItemDoor {
} }
RayTraceResult hit = ItemDoorBase.doRayTrace(worldIn, playerIn, true); RayTraceResult hit = ItemDoorBase.doRayTrace(worldIn, playerIn, true);
if (hit != null) { if (hit != null) {
DimDoors.log(this.getClass(), "Hit is not null"); DimDoors.log(this.getClass(), "Raytrace hit is not null");
BlockPos pos = hit.getBlockPos(); BlockPos pos = hit.getBlockPos();
if (worldIn.getBlockState(pos).getBlock() == ModBlocks.blockRift) { if (worldIn.getBlockState(pos).getBlock() == ModBlocks.blockRift) {
DimDoors.log(this.getClass(), "Block is a blockRift"); DimDoors.log(this.getClass(), "Raytrace hit Block is a BlockRift");
EnumActionResult canDoorBePlacedOnGroundBelowRift EnumActionResult canDoorBePlacedOnGroundBelowRift
= onItemUse(stack, playerIn, worldIn, pos.down(2), hand, EnumFacing.UP, = onItemUse(stack, playerIn, worldIn, pos.down(2), hand, EnumFacing.UP,
(float) hit.hitVec.xCoord, (float) hit.hitVec.yCoord, (float) hit.hitVec.zCoord); (float) hit.hitVec.xCoord, (float) hit.hitVec.yCoord, (float) hit.hitVec.zCoord);
return new ActionResult(canDoorBePlacedOnGroundBelowRift, stack); return new ActionResult(canDoorBePlacedOnGroundBelowRift, stack);
} }
} }
DimDoors.log(this.getClass(), "Hit is null"); DimDoors.log(this.getClass(), "Raytrace hit is null, or doesn't hit a BlockRift");
return new ActionResult(EnumActionResult.PASS, stack); return new ActionResult(EnumActionResult.PASS, stack);
} }
@ -117,6 +118,7 @@ public abstract class ItemDoorBase extends ItemDoor {
EnumFacing enumfacing = EnumFacing.fromAngle((double) playerIn.rotationYaw); EnumFacing enumfacing = EnumFacing.fromAngle((double) playerIn.rotationYaw);
int i = enumfacing.getFrontOffsetX(); int i = enumfacing.getFrontOffsetX();
int j = enumfacing.getFrontOffsetZ(); int j = enumfacing.getFrontOffsetZ();
DimDoors.log(this.getClass(), "Facing direction of door is being set to: " + enumfacing);
boolean flag = i < 0 && hitZ < 0.5F || i > 0 && hitZ > 0.5F || j < 0 && hitX > 0.5F || j > 0 && hitX < 0.5F; boolean flag = i < 0 && hitZ < 0.5F || i > 0 && hitZ > 0.5F || j < 0 && hitX > 0.5F || j > 0 && hitX < 0.5F;
placeDoor(worldIn, pos, enumfacing, doorBlock, flag); placeDoor(worldIn, pos, enumfacing, doorBlock, flag);
SoundType soundtype = worldIn.getBlockState(pos).getBlock().getSoundType(worldIn.getBlockState(pos), worldIn, pos, playerIn); SoundType soundtype = worldIn.getBlockState(pos).getBlock().getSoundType(worldIn.getBlockState(pos), worldIn, pos, playerIn);
@ -132,6 +134,8 @@ public abstract class ItemDoorBase extends ItemDoor {
newTileEntityDimDoor.register(); newTileEntityDimDoor.register();
} }
DimDoors.log(this.getClass(), "New Door rift-ID after placement: " + newTileEntityDimDoor.getRiftID()); DimDoors.log(this.getClass(), "New Door rift-ID after placement: " + newTileEntityDimDoor.getRiftID());
DimDoors.log(this.getClass(), "Facing direction of Door-block at pos of this Rift tile entity is: "
+ newTileEntityDimDoor.getWorld().getBlockState(newTileEntityDimDoor.getPos()).getValue(BlockDimDoor.FACING));
return EnumActionResult.SUCCESS; return EnumActionResult.SUCCESS;
} else { } else {

View file

@ -81,6 +81,7 @@ public class RiftRegistry {
} }
public Location getRiftLocation(int ID) { public Location getRiftLocation(int ID) {
DimDoors.log(this.getClass(), "Fetching rift location of rift with ID: " + ID);
return riftList.get(ID); return riftList.get(ID);
} }
@ -120,7 +121,11 @@ public class RiftRegistry {
return lastBrokenRift; return lastBrokenRift;
} }
public void teleportEntityToRift(Entity entity, int pairedRiftID) { public boolean teleportEntityToRift(Entity entity, int pairedRiftID) {
TeleportHelper.teleport(entity, ((DDTileEntityBase) getRiftLocation(pairedRiftID).getTileEntity()).getTeleportTarget()); if (pairedRiftID < 0) {
return false;
}
DDTileEntityBase destinationRift = (DDTileEntityBase) getRiftLocation(pairedRiftID).getTileEntity();
return TeleportHelper.teleport(entity, destinationRift.getTeleportTargetLocation());
} }
} }

View file

@ -28,9 +28,10 @@ public class TeleportHelper extends Teleporter {
entityIn.setPositionAndUpdate(pos.getX() + .5, pos.getY() + .05, pos.getZ() + .5); entityIn.setPositionAndUpdate(pos.getX() + .5, pos.getY() + .05, pos.getZ() + .5);
} }
public static void teleport(Entity entity, Location location) { public static boolean teleport(Entity entity, Location location) {
if (entity instanceof EntityPlayerSP) { if (entity instanceof EntityPlayerSP) {
return; DimDoors.log(location.getClass(), "Not teleporting, because EntityPlayerSP.");
return false;
} }
BlockPos newPos = location.getPos(); BlockPos newPos = location.getPos();
@ -38,9 +39,10 @@ public class TeleportHelper extends Teleporter {
int newDimID = location.getDimensionID(); int newDimID = location.getDimensionID();
WorldServer oldWorldServer = DimDoors.proxy.getWorldServer(oldDimID); WorldServer oldWorldServer = DimDoors.proxy.getWorldServer(oldDimID);
WorldServer newWorldServer = DimDoors.proxy.getWorldServer(newDimID); WorldServer newWorldServer = DimDoors.proxy.getWorldServer(newDimID);
DimDoors.log(location.getClass(), "Starting teleporting now:");
if (oldDimID == newDimID) { if (oldDimID == newDimID) {
if (entity instanceof EntityPlayer) { if (entity instanceof EntityPlayer) {
DimDoors.log(location.getClass(), "Using teleport method 1");
EntityPlayerMP player = (EntityPlayerMP) entity; EntityPlayerMP player = (EntityPlayerMP) entity;
player.setPositionAndUpdate(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5); player.setPositionAndUpdate(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5);
@ -48,6 +50,7 @@ public class TeleportHelper extends Teleporter {
//player.connection.sendPacket(new SPacketUpdateHealth(player.getHealth(), player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel())); //player.connection.sendPacket(new SPacketUpdateHealth(player.getHealth(), player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel()));
player.timeUntilPortal = 150; player.timeUntilPortal = 150;
} else { } else {
DimDoors.log(location.getClass(), "Using teleport method 2");
WorldServer world = (WorldServer) entity.world; WorldServer world = (WorldServer) entity.world;
entity.setPosition(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5); entity.setPosition(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5);
@ -56,18 +59,25 @@ public class TeleportHelper extends Teleporter {
} }
} else { } else {
if (entity instanceof EntityPlayer) { if (entity instanceof EntityPlayer) {
DimDoors.log(location.getClass(), "Using teleport method 3");
EntityPlayerMP player = (EntityPlayerMP) entity; EntityPlayerMP player = (EntityPlayerMP) entity;
player.changeDimension(newDimID); player.changeDimension(newDimID); //@todo, this only works for Vanilla dimensions, I've heard?
player.setPositionAndUpdate(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5); player.setPositionAndUpdate(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5);
player.world.updateEntityWithOptionalForce(player, false); player.world.updateEntityWithOptionalForce(player, false);
//player.connection.sendPacket(new SPacketUpdateHealth(player.getHealth(), player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel())); //player.connection.sendPacket(new SPacketUpdateHealth(player.getHealth(), player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel()));
} else if (!entity.world.isRemote) { } else if (!entity.world.isRemote) {
DimDoors.log(location.getClass(), "Using teleport method 4");
entity.changeDimension(newDimID); entity.changeDimension(newDimID);
entity.setPosition(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5); entity.setPosition(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5);
oldWorldServer.resetUpdateEntityTick(); oldWorldServer.resetUpdateEntityTick();
newWorldServer.resetUpdateEntityTick(); newWorldServer.resetUpdateEntityTick();
} else {
//does this statement ever get reached though?
} }
return false;
} }
entity.timeUntilPortal = 150;
return true;
//@todo set player angle in front of and facing away from the door //@todo set player angle in front of and facing away from the door
} }
} }

View file

@ -1,6 +1,7 @@
package com.zixiken.dimdoors.tileentities; package com.zixiken.dimdoors.tileentities;
import com.zixiken.dimdoors.DimDoors; import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.blocks.BlockDimDoor;
import com.zixiken.dimdoors.shared.Location; import com.zixiken.dimdoors.shared.Location;
import com.zixiken.dimdoors.shared.RiftRegistry; import com.zixiken.dimdoors.shared.RiftRegistry;
import java.util.Random; import java.util.Random;
@ -106,7 +107,7 @@ public abstract class DDTileEntityBase extends TileEntity {
return isPaired; return isPaired;
} }
public Location getTeleportTarget() { public Location getTeleportTargetLocation() {
return new Location(this.getWorld().provider.getDimension(), this.getPos()); return new Location(this.getWorld().provider.getDimension(), this.getPos());
} }

View file

@ -60,10 +60,10 @@ public class TileEntityDimDoor extends DDTileEntityBase {
} }
@Override @Override
public Location getTeleportTarget() { public Location getTeleportTargetLocation() {
EnumFacing facing = getWorld().getBlockState(getPos()).getValue(BlockDimDoor.FACING); EnumFacing facing = getWorld().getBlockState(getPos()).getValue(BlockDimDoor.FACING).getOpposite(); //@todo this will allways return South after world-load?
return new Location(world, pos.offset(facing)); return new Location(this.getWorld().provider.getDimension(), this.getPos().offset(facing));
} }
@Override @Override
@ -71,7 +71,6 @@ public class TileEntityDimDoor extends DDTileEntityBase {
if (!isPaired()) { if (!isPaired()) {
//@todo try to automatically pair this door somehow //@todo try to automatically pair this door somehow
} }
RiftRegistry.Instance.teleportEntityToRift(entity, getPairedRiftID()); return RiftRegistry.Instance.teleportEntityToRift(entity, getPairedRiftID());
return true;
} }
} }