Add archivist's eyeglass and spectral tether, plus some improvements to teleportation

This commit is contained in:
Electroblob77
2020-06-23 22:09:06 +01:00
parent 0ca86eb01b
commit 33c5f79ed7
16 changed files with 224 additions and 103 deletions
@@ -1,13 +1,14 @@
package electroblob.wizardry.spell;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.item.ItemArtefact;
import electroblob.wizardry.item.SpellActions;
import electroblob.wizardry.registry.WizardryItems;
import electroblob.wizardry.util.BlockUtils;
import electroblob.wizardry.util.RayTracer;
import electroblob.wizardry.util.SpellModifiers;
import electroblob.wizardry.util.*;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityBoat;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
@@ -15,6 +16,7 @@ import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
public class Blink extends Spell {
@@ -27,8 +29,12 @@ public class Blink extends Spell {
@Override
public boolean cast(World world, EntityPlayer caster, EnumHand hand, int ticksInUse, SpellModifiers modifiers){
RayTraceResult rayTrace = RayTracer.standardBlockRayTrace(world, caster,
getProperty(RANGE).doubleValue() * modifiers.get(WizardryItems.range_upgrade), false);
boolean teleportMount = caster.isRiding() && ItemArtefact.isArtefactActive(caster, WizardryItems.charm_mount_teleporting);
boolean hitLiquids = teleportMount && caster.getRidingEntity() instanceof EntityBoat; // Boats teleport to the surface
double range = getProperty(RANGE).floatValue() * modifiers.get(WizardryItems.range_upgrade);
RayTraceResult rayTrace = RayTracer.standardBlockRayTrace(world, caster, range, hitLiquids, !hitLiquids,false);
// It's worth noting that on the client side, the cast() method only gets called if the server side
// cast method succeeded, so you need not check any conditions for spawning particles.
@@ -48,32 +54,21 @@ public class Blink extends Spell {
if(rayTrace != null && rayTrace.typeOfHit == RayTraceResult.Type.BLOCK){
BlockPos pos = rayTrace.getBlockPos();
BlockPos pos = rayTrace.getBlockPos().offset(rayTrace.sideHit);
Entity toTeleport = teleportMount ? caster.getRidingEntity() : caster;
// Leave space for the player's head
if(rayTrace.sideHit == EnumFacing.DOWN) pos = pos.down();
Vec3d vec = EntityUtils.findSpaceForTeleport(toTeleport, GeometryUtils.getFaceCentre(pos, EnumFacing.DOWN), teleportMount);
// This means stuff like snow layers is ignored, meaning when on snow-covered ground the player does
// not teleport 1 block above the ground.
if(rayTrace.sideHit == EnumFacing.UP && !world.getBlockState(pos).getMaterial().blocksMovement()){
pos = pos.down();
if(vec != null){
// Plays before and after so it is heard from both positions
this.playSound(world, caster, ticksInUse, -1, modifiers);
if(!teleportMount && caster.isRiding()) caster.dismountRidingEntity();
if(!world.isRemote) toTeleport.setPositionAndUpdate(vec.x, vec.y, vec.z);
this.playSound(world, caster, ticksInUse, -1, modifiers);
return true;
}
pos = pos.offset(rayTrace.sideHit);
// Prevents the player from teleporting into blocks and suffocating.
if(world.getBlockState(pos).getMaterial().blocksMovement()
|| world.getBlockState(pos.up()).getMaterial().blocksMovement()){
return false;
}
// Plays before and after so it is heard from both positions
this.playSound(world, caster, ticksInUse, -1, modifiers);
if(!world.isRemote) caster.setPositionAndUpdate(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5);
this.playSound(world, caster, ticksInUse, -1, modifiers);
return true;
}
return false;