diff --git a/src/main/java/com/minelittlepony/unicopia/spell/SpellPortal.java b/src/main/java/com/minelittlepony/unicopia/spell/SpellPortal.java index 3305984f..2cdfde37 100644 --- a/src/main/java/com/minelittlepony/unicopia/spell/SpellPortal.java +++ b/src/main/java/com/minelittlepony/unicopia/spell/SpellPortal.java @@ -32,6 +32,11 @@ public class SpellPortal extends AbstractSpell implements IUseAction { private static final IShape portalZone_Y = new Sphere(true, 1, 2, 0, 2); private static final IShape portalZone_Z = new Sphere(true, 1, 1, 2, 0); + private static final AxisAlignedBB TELEPORT_BOUNDS_VERT = new AxisAlignedBB(-1, -0.5, -1, 1, 0.5, 1); + private static final AxisAlignedBB TELEPORT_BOUNDS = new AxisAlignedBB(-0.5, -0.5, -0.5, 0.5, 3, 0.5); + + private static final AxisAlignedBB DESTINATION_BOUNDS = new AxisAlignedBB(0, 0, 0, 1.5F, 1.5F, 1.5F); + private int cooldown = 0; @Nullable @@ -67,7 +72,7 @@ public class SpellPortal extends AbstractSpell implements IUseAction { @Override public SpellCastResult onUse(ItemStack stack, SpellAffinity affinity, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) { position = pos.offset(side); - axis = player.getHorizontalFacing().getAxis(); + axis = EnumFacing.getDirectionFromEntityLiving(position, player).getAxis(); IPlayer prop = PlayerSpeciesList.instance().getPlayer(player); @@ -110,20 +115,11 @@ public class SpellPortal extends AbstractSpell implements IUseAction { @Override public boolean update(ICaster source, int level) { if (!source.getWorld().isRemote) { - if (cooldown > 0) { - cooldown--; - } - - if (cooldown <= 0) { - if (destinationPos != null) { - getDestinationPortal(source.getWorld()).ifPresent(dest -> { - if (!dest.getDead() && teleportNear(source, level)) { - dest.cooldown = 30; - cooldown = 30; - } - }); + getDestinationPortal(source.getWorld()).ifPresent(dest -> { + if (!dest.getDead()) { + teleportNear(source, level); } - } + }); } return true; @@ -150,23 +146,50 @@ public class SpellPortal extends AbstractSpell implements IUseAction { } } - private static final AxisAlignedBB TELEPORT_BOUNDS = new AxisAlignedBB(-0.5, -0.5, -0.5, 0.5, 3, 0.5); - private static final AxisAlignedBB DESTINATION_BOUNDS = new AxisAlignedBB(0, 0, 0, 1.5F, 1.5F, 1.5F); + public AxisAlignedBB getTeleportBounds() { + if (axis == EnumFacing.Axis.Y) { + return TELEPORT_BOUNDS_VERT; + } + + return TELEPORT_BOUNDS; + } private boolean teleportNear(ICaster source, int level) { - return source.getWorld().getEntitiesWithinAABB(Entity.class, TELEPORT_BOUNDS.offset(source.getOrigin())).stream().filter(i -> { + return source.getWorld().getEntitiesWithinAABB(Entity.class, getTeleportBounds().offset(source.getOrigin())).stream().filter(i -> { if (!(i instanceof IMagicals) && i.timeUntilPortal == 0) { + EnumFacing.Axis xi = i.getHorizontalFacing().getAxis(); + + if (axis != EnumFacing.Axis.Y && xi != axis) { + return false; + } + EnumFacing offset = i.getHorizontalFacing(); - double destX = destinationPos.getX() + (i.posX - source.getOrigin().getX()) + offset.getXOffset(); - double destY = destinationPos.getY() + (i.posY - source.getOrigin().getY()) + 1; - double destZ = destinationPos.getZ() + (i.posZ - source.getOrigin().getZ()) + offset.getZOffset(); + double destX = destinationPos.getX() + (i.posX - source.getOrigin().getX()); + double destY = destinationPos.getY() + (i.posY - source.getOrigin().getY()); + double destZ = destinationPos.getZ() + (i.posZ - source.getOrigin().getZ()); + + if (axis != EnumFacing.Axis.Y) { + destX += offset.getXOffset(); + destY++; + destZ += offset.getZOffset(); + } i.timeUntilPortal = i.getPortalCooldown(); - i.getEntityWorld().playSound(null, i.getPosition(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 1, 1); + i.getEntityWorld().playSound(null, i.getPosition(), SoundEvents.BLOCK_END_PORTAL_FRAME_FILL, SoundCategory.PLAYERS, 1, 1); + + + + if (sibling.axis != axis) { + + if (xi != sibling.axis) { + i.setPositionAndRotation(i.posX, i.posY, i.posZ, i.rotationYaw + 90, i.rotationPitch); + } + } + i.setPositionAndUpdate(destX, destY, destZ); - i.getEntityWorld().playSound(null, i.getPosition(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 1, 1); + i.getEntityWorld().playSound(null, i.getPosition(), SoundEvents.BLOCK_END_PORTAL_FRAME_FILL, SoundCategory.PLAYERS, 1, 1); return true; } @@ -176,7 +199,8 @@ public class SpellPortal extends AbstractSpell implements IUseAction { } public Optional getDestinationPortal(World w) { - if (sibling == null) { + if (sibling == null && destinationPos != null) { + w.getBlockLightOpacity(destinationPos); w.getEntitiesWithinAABB(EntitySpell.class, DESTINATION_BOUNDS.offset(destinationPos)).stream() .filter(i -> i.getEffect() instanceof SpellPortal) .map(i -> (SpellPortal)i.getEffect()) @@ -199,7 +223,6 @@ public class SpellPortal extends AbstractSpell implements IUseAction { compound.setTag("destination", dest); } - compound.setInteger("portal_cooldown", cooldown); compound.setString("axis", axis.getName2()); } @@ -215,7 +238,6 @@ public class SpellPortal extends AbstractSpell implements IUseAction { ); } - cooldown = compound.getInteger("portal_cooldown"); if (compound.hasKey("axis")) { axis = EnumFacing.Axis.byName(compound.getString("axis").toLowerCase(Locale.ROOT));