diff --git a/src/main/java/com/zixiken/dimdoors/blocks/BlockDimDoorBase.java b/src/main/java/com/zixiken/dimdoors/blocks/BlockDimDoorBase.java index 92138dc8..2ff7098e 100644 --- a/src/main/java/com/zixiken/dimdoors/blocks/BlockDimDoorBase.java +++ b/src/main/java/com/zixiken/dimdoors/blocks/BlockDimDoorBase.java @@ -35,18 +35,16 @@ public abstract class BlockDimDoorBase extends BlockDoor implements IDimDoor, IT @Override public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) { 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) - && 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)) { 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); } - } 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) { DDTileEntityBase riftTile = getRiftTile(world, pos, world.getBlockState(pos)); if (riftTile.tryTeleport(entity)) { + DimDoors.log(this.getClass(), "Entity was teleported succesfully"); //player is succesfully teleported } else { + DimDoors.log(this.getClass(), "Entity was NOT teleported succesfully"); //@todo some kind of message that teleporting wasn't successfull //probably should only happen on personal dimdoors } diff --git a/src/main/java/com/zixiken/dimdoors/items/ItemDoorBase.java b/src/main/java/com/zixiken/dimdoors/items/ItemDoorBase.java index 369cd5a8..e8d74b1a 100644 --- a/src/main/java/com/zixiken/dimdoors/items/ItemDoorBase.java +++ b/src/main/java/com/zixiken/dimdoors/items/ItemDoorBase.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.List; import com.zixiken.dimdoors.DimDoors; +import com.zixiken.dimdoors.blocks.BlockDimDoor; import com.zixiken.dimdoors.blocks.BlockDimDoorBase; import com.zixiken.dimdoors.blocks.ModBlocks; import com.zixiken.dimdoors.tileentities.DDTileEntityBase; @@ -65,17 +66,17 @@ public abstract class ItemDoorBase extends ItemDoor { } RayTraceResult hit = ItemDoorBase.doRayTrace(worldIn, playerIn, true); if (hit != null) { - DimDoors.log(this.getClass(), "Hit is not null"); + DimDoors.log(this.getClass(), "Raytrace hit is not null"); BlockPos pos = hit.getBlockPos(); 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 = onItemUse(stack, playerIn, worldIn, pos.down(2), hand, EnumFacing.UP, (float) hit.hitVec.xCoord, (float) hit.hitVec.yCoord, (float) hit.hitVec.zCoord); 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); } @@ -117,6 +118,7 @@ public abstract class ItemDoorBase extends ItemDoor { EnumFacing enumfacing = EnumFacing.fromAngle((double) playerIn.rotationYaw); int i = enumfacing.getFrontOffsetX(); 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; placeDoor(worldIn, pos, enumfacing, doorBlock, flag); 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(); } 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; } else { diff --git a/src/main/java/com/zixiken/dimdoors/shared/RiftRegistry.java b/src/main/java/com/zixiken/dimdoors/shared/RiftRegistry.java index a415de58..970691bd 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/RiftRegistry.java +++ b/src/main/java/com/zixiken/dimdoors/shared/RiftRegistry.java @@ -81,6 +81,7 @@ public class RiftRegistry { } public Location getRiftLocation(int ID) { + DimDoors.log(this.getClass(), "Fetching rift location of rift with ID: " + ID); return riftList.get(ID); } @@ -120,7 +121,11 @@ public class RiftRegistry { return lastBrokenRift; } - public void teleportEntityToRift(Entity entity, int pairedRiftID) { - TeleportHelper.teleport(entity, ((DDTileEntityBase) getRiftLocation(pairedRiftID).getTileEntity()).getTeleportTarget()); + public boolean teleportEntityToRift(Entity entity, int pairedRiftID) { + if (pairedRiftID < 0) { + return false; + } + DDTileEntityBase destinationRift = (DDTileEntityBase) getRiftLocation(pairedRiftID).getTileEntity(); + return TeleportHelper.teleport(entity, destinationRift.getTeleportTargetLocation()); } } diff --git a/src/main/java/com/zixiken/dimdoors/shared/TeleportHelper.java b/src/main/java/com/zixiken/dimdoors/shared/TeleportHelper.java index 9605700a..9d08e6f3 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/TeleportHelper.java +++ b/src/main/java/com/zixiken/dimdoors/shared/TeleportHelper.java @@ -28,9 +28,10 @@ public class TeleportHelper extends Teleporter { 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) { - return; + DimDoors.log(location.getClass(), "Not teleporting, because EntityPlayerSP."); + return false; } BlockPos newPos = location.getPos(); @@ -38,9 +39,10 @@ public class TeleportHelper extends Teleporter { int newDimID = location.getDimensionID(); WorldServer oldWorldServer = DimDoors.proxy.getWorldServer(oldDimID); WorldServer newWorldServer = DimDoors.proxy.getWorldServer(newDimID); - + DimDoors.log(location.getClass(), "Starting teleporting now:"); if (oldDimID == newDimID) { if (entity instanceof EntityPlayer) { + DimDoors.log(location.getClass(), "Using teleport method 1"); EntityPlayerMP player = (EntityPlayerMP) entity; 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.timeUntilPortal = 150; } else { + DimDoors.log(location.getClass(), "Using teleport method 2"); WorldServer world = (WorldServer) entity.world; entity.setPosition(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5); @@ -56,18 +59,25 @@ public class TeleportHelper extends Teleporter { } } else { if (entity instanceof EntityPlayer) { + DimDoors.log(location.getClass(), "Using teleport method 3"); 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.world.updateEntityWithOptionalForce(player, false); //player.connection.sendPacket(new SPacketUpdateHealth(player.getHealth(), player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel())); } else if (!entity.world.isRemote) { + DimDoors.log(location.getClass(), "Using teleport method 4"); entity.changeDimension(newDimID); entity.setPosition(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5); oldWorldServer.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 } } diff --git a/src/main/java/com/zixiken/dimdoors/tileentities/DDTileEntityBase.java b/src/main/java/com/zixiken/dimdoors/tileentities/DDTileEntityBase.java index c5198c40..eeff9021 100644 --- a/src/main/java/com/zixiken/dimdoors/tileentities/DDTileEntityBase.java +++ b/src/main/java/com/zixiken/dimdoors/tileentities/DDTileEntityBase.java @@ -1,6 +1,7 @@ package com.zixiken.dimdoors.tileentities; import com.zixiken.dimdoors.DimDoors; +import com.zixiken.dimdoors.blocks.BlockDimDoor; import com.zixiken.dimdoors.shared.Location; import com.zixiken.dimdoors.shared.RiftRegistry; import java.util.Random; @@ -106,7 +107,7 @@ public abstract class DDTileEntityBase extends TileEntity { return isPaired; } - public Location getTeleportTarget() { + public Location getTeleportTargetLocation() { return new Location(this.getWorld().provider.getDimension(), this.getPos()); } diff --git a/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityDimDoor.java b/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityDimDoor.java index b8697311..a6bcc606 100644 --- a/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityDimDoor.java +++ b/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityDimDoor.java @@ -60,10 +60,10 @@ public class TileEntityDimDoor extends DDTileEntityBase { } @Override - public Location getTeleportTarget() { - EnumFacing facing = getWorld().getBlockState(getPos()).getValue(BlockDimDoor.FACING); + public Location getTeleportTargetLocation() { + 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 @@ -71,7 +71,6 @@ public class TileEntityDimDoor extends DDTileEntityBase { if (!isPaired()) { //@todo try to automatically pair this door somehow } - RiftRegistry.Instance.teleportEntityToRift(entity, getPairedRiftID()); - return true; + return RiftRegistry.Instance.teleportEntityToRift(entity, getPairedRiftID()); } }