Fixed long-distance travel and improved vertical portals

This commit is contained in:
Sollace 2019-01-26 20:15:43 +02:00
parent 6ebf34f7f6
commit a367bd57d9

View file

@ -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_Y = new Sphere(true, 1, 2, 0, 2);
private static final IShape portalZone_Z = new Sphere(true, 1, 1, 2, 0); 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; private int cooldown = 0;
@Nullable @Nullable
@ -67,7 +72,7 @@ public class SpellPortal extends AbstractSpell implements IUseAction {
@Override @Override
public SpellCastResult onUse(ItemStack stack, SpellAffinity affinity, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) { 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); position = pos.offset(side);
axis = player.getHorizontalFacing().getAxis(); axis = EnumFacing.getDirectionFromEntityLiving(position, player).getAxis();
IPlayer prop = PlayerSpeciesList.instance().getPlayer(player); IPlayer prop = PlayerSpeciesList.instance().getPlayer(player);
@ -110,20 +115,11 @@ public class SpellPortal extends AbstractSpell implements IUseAction {
@Override @Override
public boolean update(ICaster<?> source, int level) { public boolean update(ICaster<?> source, int level) {
if (!source.getWorld().isRemote) { if (!source.getWorld().isRemote) {
if (cooldown > 0) { getDestinationPortal(source.getWorld()).ifPresent(dest -> {
cooldown--; if (!dest.getDead()) {
} teleportNear(source, level);
if (cooldown <= 0) {
if (destinationPos != null) {
getDestinationPortal(source.getWorld()).ifPresent(dest -> {
if (!dest.getDead() && teleportNear(source, level)) {
dest.cooldown = 30;
cooldown = 30;
}
});
} }
} });
} }
return true; 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); public AxisAlignedBB getTeleportBounds() {
private static final AxisAlignedBB DESTINATION_BOUNDS = new AxisAlignedBB(0, 0, 0, 1.5F, 1.5F, 1.5F); if (axis == EnumFacing.Axis.Y) {
return TELEPORT_BOUNDS_VERT;
}
return TELEPORT_BOUNDS;
}
private boolean teleportNear(ICaster<?> source, int level) { 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) { 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(); EnumFacing offset = i.getHorizontalFacing();
double destX = destinationPos.getX() + (i.posX - source.getOrigin().getX()) + offset.getXOffset(); double destX = destinationPos.getX() + (i.posX - source.getOrigin().getX());
double destY = destinationPos.getY() + (i.posY - source.getOrigin().getY()) + 1; double destY = destinationPos.getY() + (i.posY - source.getOrigin().getY());
double destZ = destinationPos.getZ() + (i.posZ - source.getOrigin().getZ()) + offset.getZOffset(); 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.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.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; return true;
} }
@ -176,7 +199,8 @@ public class SpellPortal extends AbstractSpell implements IUseAction {
} }
public Optional<SpellPortal> getDestinationPortal(World w) { public Optional<SpellPortal> getDestinationPortal(World w) {
if (sibling == null) { if (sibling == null && destinationPos != null) {
w.getBlockLightOpacity(destinationPos);
w.getEntitiesWithinAABB(EntitySpell.class, DESTINATION_BOUNDS.offset(destinationPos)).stream() w.getEntitiesWithinAABB(EntitySpell.class, DESTINATION_BOUNDS.offset(destinationPos)).stream()
.filter(i -> i.getEffect() instanceof SpellPortal) .filter(i -> i.getEffect() instanceof SpellPortal)
.map(i -> (SpellPortal)i.getEffect()) .map(i -> (SpellPortal)i.getEffect())
@ -199,7 +223,6 @@ public class SpellPortal extends AbstractSpell implements IUseAction {
compound.setTag("destination", dest); compound.setTag("destination", dest);
} }
compound.setInteger("portal_cooldown", cooldown);
compound.setString("axis", axis.getName2()); 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")) { if (compound.hasKey("axis")) {
axis = EnumFacing.Axis.byName(compound.getString("axis").toLowerCase(Locale.ROOT)); axis = EnumFacing.Axis.byName(compound.getString("axis").toLowerCase(Locale.ROOT));