diff --git a/src/main/java/electroblob/wizardry/block/BlockTransportationStone.java b/src/main/java/electroblob/wizardry/block/BlockTransportationStone.java
index cb9d7c88..f72ea195 100644
--- a/src/main/java/electroblob/wizardry/block/BlockTransportationStone.java
+++ b/src/main/java/electroblob/wizardry/block/BlockTransportationStone.java
@@ -174,10 +174,11 @@ public class BlockTransportationStone extends Block {
return false;
}
- /** Returns whether the specified location is surrounded by a complete cicle of 8 transportation stones. */
+ /** Returns whether the specified location is surrounded by a complete circle of 8 transportation stones. */
public static boolean testForCircle(World world, BlockPos pos){
- if(world.getBlockState(pos).getMaterial().blocksMovement()) return false;
+ if(world.getBlockState(pos).getMaterial().blocksMovement() || world.getBlockState(pos.up()).getMaterial()
+ .blocksMovement()) return false;
for(int x = -1; x <= 1; x++){
for(int z = -1; z <= 1; z++){
diff --git a/src/main/java/electroblob/wizardry/client/ClientProxy.java b/src/main/java/electroblob/wizardry/client/ClientProxy.java
index 748631c1..67f7d84c 100644
--- a/src/main/java/electroblob/wizardry/client/ClientProxy.java
+++ b/src/main/java/electroblob/wizardry/client/ClientProxy.java
@@ -549,36 +549,38 @@ public class ClientProxy extends CommonProxy {
public void handleTransportationPacket(PacketTransportation.Message message){
World world = Minecraft.getMinecraft().world;
- Entity caster = world.getEntityByID(message.casterID);
+ BlockPos pos = message.destination;
- if(caster == null) return; // Shouldn't happen
+ Entity entity = world.getEntityByID(message.dismountEntityID);
+ if(message.dismountEntityID != -1 && entity != null) entity.dismountRidingEntity();
// Moved from when the packet is sent to when it is received; fixes the sound not playing in first person.
- caster.playSound(WizardrySounds.SPELL_TRANSPORTATION_TRAVEL, 1, 1);
+ // Changed to a position to avoid syncing issues
+ world.playSound(pos.getX(), pos.getY(), pos.getZ(), WizardrySounds.SPELL_TRANSPORTATION_TRAVEL, WizardrySounds.SPELLS, 1, 1, false);
for(int i = 0; i < 20; i++){
double radius = 1;
float angle = world.rand.nextFloat() * (float)Math.PI * 2;
- double x = caster.posX + radius * MathHelper.cos(angle);
- double y = caster.getEntityBoundingBox().minY + world.rand.nextDouble() * 2;
- double z = caster.posZ + radius * MathHelper.sin(angle);
+ double x = pos.getX() + 0.5 + radius * MathHelper.cos(angle);
+ double y = pos.getY() + world.rand.nextDouble() * 2;
+ double z = pos.getZ() + 0.5 + radius * MathHelper.sin(angle);
ParticleBuilder.create(Type.SPARKLE).pos(x, y, z).vel(0, 0.02, 0).clr(0.6f, 1, 0.6f)
.time(80 + world.rand.nextInt(10)).spawn(world);
}
for(int i = 0; i < 20; i++){
double radius = 1;
float angle = world.rand.nextFloat() * (float)Math.PI * 2;
- double x = caster.posX + radius * MathHelper.cos(angle);
- double y = caster.getEntityBoundingBox().minY + world.rand.nextDouble() * 2;
- double z = caster.posZ + radius * MathHelper.sin(angle);
+ double x = pos.getX() + 0.5 + radius * MathHelper.cos(angle);
+ double y = pos.getY() + world.rand.nextDouble() * 2;
+ double z = pos.getZ() + 0.5 + radius * MathHelper.sin(angle);
world.spawnParticle(EnumParticleTypes.VILLAGER_HAPPY, x, y, z, 0, 0.02, 0);
}
for(int i = 0; i < 20; i++){
double radius = 1;
float angle = world.rand.nextFloat() * (float)Math.PI * 2;
- double x = caster.posX + radius * MathHelper.cos(angle);
- double y = caster.getEntityBoundingBox().minY + world.rand.nextDouble() * 2;
- double z = caster.posZ + radius * MathHelper.sin(angle);
+ double x = pos.getX() + 0.5 + radius * MathHelper.cos(angle);
+ double y = pos.getY() + world.rand.nextDouble() * 2;
+ double z = pos.getZ() + 0.5 + radius * MathHelper.sin(angle);
world.spawnParticle(EnumParticleTypes.ENCHANTMENT_TABLE, x, y, z, 0, 0.02, 0);
}
}
diff --git a/src/main/java/electroblob/wizardry/client/model/WizardryModels.java b/src/main/java/electroblob/wizardry/client/model/WizardryModels.java
index cb776c61..d0519405 100644
--- a/src/main/java/electroblob/wizardry/client/model/WizardryModels.java
+++ b/src/main/java/electroblob/wizardry/client/model/WizardryModels.java
@@ -282,6 +282,7 @@ public final class WizardryModels {
registerItemModel(WizardryItems.charm_haggler);
registerItemModel(WizardryItems.charm_experience_tome);
registerItemModel(WizardryItems.charm_move_speed);
+ registerItemModel(WizardryItems.charm_spell_discovery);
registerItemModel(WizardryItems.charm_auto_smelt);
registerItemModel(WizardryItems.charm_lava_walking);
registerItemModel(WizardryItems.charm_storm);
@@ -295,6 +296,7 @@ public final class WizardryModels {
registerItemModel(WizardryItems.charm_light);
registerItemModel(WizardryItems.charm_transportation);
registerItemModel(WizardryItems.charm_black_hole);
+ registerItemModel(WizardryItems.charm_mount_teleporting);
registerItemModel(WizardryItems.charm_feeding);
}
diff --git a/src/main/java/electroblob/wizardry/loot/RandomSpell.java b/src/main/java/electroblob/wizardry/loot/RandomSpell.java
index 9db7972c..9e1819e5 100644
--- a/src/main/java/electroblob/wizardry/loot/RandomSpell.java
+++ b/src/main/java/electroblob/wizardry/loot/RandomSpell.java
@@ -5,9 +5,11 @@ import electroblob.wizardry.Wizardry;
import electroblob.wizardry.constants.Element;
import electroblob.wizardry.constants.Tier;
import electroblob.wizardry.data.WizardData;
+import electroblob.wizardry.item.ItemArtefact;
import electroblob.wizardry.item.ItemScroll;
import electroblob.wizardry.item.ItemSpellBook;
import electroblob.wizardry.registry.Spells;
+import electroblob.wizardry.registry.WizardryItems;
import electroblob.wizardry.spell.Spell;
import electroblob.wizardry.util.SpellProperties;
import net.minecraft.entity.player.EntityPlayer;
@@ -150,8 +152,12 @@ public class RandomSpell extends LootFunction {
possibleSpells.removeIf(s -> s.getElement() != element);
if(possibleSpells.isEmpty()) return Spells.none; // If it fails anywhere, it'll most likely be here
+ float bias = undiscoveredBias;
+ // Archivist's eyeglass increases undiscovered bias by 0.4 up to a maximum of 0.9
+ if(ItemArtefact.isArtefactActive(player, WizardryItems.charm_spell_discovery)) bias = Math.min(bias + 0.4f, 0.9f);
+
// Remove either the undiscovered spells or the discovered ones, depending on the bias
- if(undiscoveredBias > 0 && player != null){
+ if(bias > 0 && player != null){
WizardData data = WizardData.get(player);
@@ -159,7 +165,7 @@ public class RandomSpell extends LootFunction {
// If none have been discovered or they've all been discovered, don't bother!
if(discoveredCount > 0 && discoveredCount < possibleSpells.size()){
// Kinda unintuitive but it's very neat!
- boolean keepDiscovered = random.nextFloat() < 0.5f + 0.5f * undiscoveredBias;
+ boolean keepDiscovered = random.nextFloat() < 0.5f + 0.5f * bias;
possibleSpells.removeIf(s -> keepDiscovered != data.hasSpellBeenDiscovered(s));
}
}
diff --git a/src/main/java/electroblob/wizardry/packet/PacketTransportation.java b/src/main/java/electroblob/wizardry/packet/PacketTransportation.java
index afb07f7d..1824de64 100644
--- a/src/main/java/electroblob/wizardry/packet/PacketTransportation.java
+++ b/src/main/java/electroblob/wizardry/packet/PacketTransportation.java
@@ -3,10 +3,14 @@ package electroblob.wizardry.packet;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.packet.PacketTransportation.Message;
import io.netty.buffer.ByteBuf;
+import net.minecraft.entity.Entity;
+import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
+import javax.annotation.Nullable;
+
/**
* [Server -> Client] This packet is sent when a player is teleported due to the transportation spell to spawn
* the particles.
@@ -26,26 +30,31 @@ public class PacketTransportation implements IMessageHandler
}
public static class Message implements IMessage {
- /** EntityID of the caster */
- public int casterID;
+
+ /** The destination that was teleported to */
+ public BlockPos destination;
+ public int dismountEntityID;
// This constructor is required otherwise you'll get errors (used somewhere in fml through reflection)
public Message(){
}
- public Message(int casterID){
- this.casterID = casterID;
+ public Message(BlockPos destination, @Nullable Entity toDismount){
+ this.destination = destination;
+ this.dismountEntityID = toDismount == null ? -1 : toDismount.getEntityId();
}
@Override
public void fromBytes(ByteBuf buf){
// The order is important
- this.casterID = buf.readInt();
+ this.destination = BlockPos.fromLong(buf.readLong());
+ this.dismountEntityID = buf.readInt();
}
@Override
public void toBytes(ByteBuf buf){
- buf.writeInt(casterID);
+ buf.writeLong(destination.toLong());
+ buf.writeInt(dismountEntityID);
}
}
}
diff --git a/src/main/java/electroblob/wizardry/registry/WizardryItems.java b/src/main/java/electroblob/wizardry/registry/WizardryItems.java
index a490b27c..a37e48d8 100644
--- a/src/main/java/electroblob/wizardry/registry/WizardryItems.java
+++ b/src/main/java/electroblob/wizardry/registry/WizardryItems.java
@@ -266,6 +266,7 @@ public final class WizardryItems {
public static final Item charm_haggler = placeholder();
public static final Item charm_experience_tome = placeholder();
public static final Item charm_move_speed = placeholder();
+ public static final Item charm_spell_discovery = placeholder();
public static final Item charm_auto_smelt = placeholder();
public static final Item charm_lava_walking = placeholder();
public static final Item charm_storm = placeholder();
@@ -279,6 +280,7 @@ public final class WizardryItems {
public static final Item charm_light = placeholder();
public static final Item charm_transportation = placeholder();
public static final Item charm_black_hole = placeholder();
+ public static final Item charm_mount_teleporting = placeholder();
public static final Item charm_feeding = placeholder();
private static final Map, Item> WAND_MAP = new HashMap<>();
@@ -627,6 +629,7 @@ public final class WizardryItems {
registerItem(registry, "charm_haggler", new ItemArtefact(EnumRarity.RARE, ItemArtefact.Type.CHARM));
registerItem(registry, "charm_experience_tome", new ItemArtefact(EnumRarity.EPIC, ItemArtefact.Type.CHARM));
registerItem(registry, "charm_move_speed", new ItemArtefact(EnumRarity.RARE, ItemArtefact.Type.CHARM));
+ registerItem(registry, "charm_spell_discovery", new ItemArtefact(EnumRarity.UNCOMMON, ItemArtefact.Type.CHARM));
registerItem(registry, "charm_auto_smelt", new ItemArtefact(EnumRarity.RARE, ItemArtefact.Type.CHARM));
registerItem(registry, "charm_lava_walking", new ItemArtefact(EnumRarity.EPIC, ItemArtefact.Type.CHARM));
registerItem(registry, "charm_storm", new ItemArtefact(EnumRarity.RARE, ItemArtefact.Type.CHARM));
@@ -640,6 +643,7 @@ public final class WizardryItems {
registerItem(registry, "charm_light", new ItemArtefact(EnumRarity.RARE, ItemArtefact.Type.CHARM));
registerItem(registry, "charm_transportation", new ItemArtefact(EnumRarity.RARE, ItemArtefact.Type.CHARM));
registerItem(registry, "charm_black_hole", new ItemArtefact(EnumRarity.EPIC, ItemArtefact.Type.CHARM));
+ registerItem(registry, "charm_mount_teleporting", new ItemArtefact(EnumRarity.RARE, ItemArtefact.Type.CHARM));
registerItem(registry, "charm_feeding", new ItemArtefact(EnumRarity.UNCOMMON, ItemArtefact.Type.CHARM));
}
diff --git a/src/main/java/electroblob/wizardry/spell/Blink.java b/src/main/java/electroblob/wizardry/spell/Blink.java
index 01c63c46..e45cb59d 100644
--- a/src/main/java/electroblob/wizardry/spell/Blink.java
+++ b/src/main/java/electroblob/wizardry/spell/Blink.java
@@ -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;
diff --git a/src/main/java/electroblob/wizardry/spell/PhaseStep.java b/src/main/java/electroblob/wizardry/spell/PhaseStep.java
index 30f4b40a..9c521bc4 100644
--- a/src/main/java/electroblob/wizardry/spell/PhaseStep.java
+++ b/src/main/java/electroblob/wizardry/spell/PhaseStep.java
@@ -2,11 +2,12 @@ package electroblob.wizardry.spell;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.constants.Constants;
+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.item.EntityBoat;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
@@ -28,8 +29,12 @@ public class PhaseStep extends Spell {
@Override
public boolean cast(World world, EntityPlayer caster, EnumHand hand, int ticksInUse, SpellModifiers modifiers){
+ 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, false);
+
+ RayTraceResult rayTrace = RayTracer.standardBlockRayTrace(world, caster, range, hitLiquids, !hitLiquids, false);
// This is here because the conditions are false on the client for whatever reason. (see the Javadoc for cast()
// for an explanation)
@@ -46,6 +51,8 @@ public class PhaseStep extends Spell {
Wizardry.proxy.playBlinkEffect(caster);
}
+ Entity toTeleport = teleportMount ? caster.getRidingEntity() : caster;
+
if(rayTrace != null && rayTrace.typeOfHit == RayTraceResult.Type.BLOCK){
BlockPos pos = rayTrace.getBlockPos();
@@ -68,66 +75,40 @@ public class PhaseStep extends Spell {
&& !Wizardry.settings.teleportThroughUnbreakableBlocks)
break; // Don't return false yet, there are other possible outcomes below now
- if(!world.getBlockState(pos1).getMaterial().blocksMovement()
- && !world.getBlockState(pos1.up()).getMaterial().blocksMovement()){
-
- // Plays before and after so it is heard from both positions
- this.playSound(world, caster, ticksInUse, -1, modifiers);
-
- if(!world.isRemote){
- caster.setPositionAndUpdate(pos1.getX() + 0.5, pos1.getY() + 0.5, pos1.getZ() + 0.5);
- }
-
- this.playSound(world, caster, ticksInUse, -1, modifiers);
- return true;
- }
+ Vec3d vec = GeometryUtils.getFaceCentre(pos1, EnumFacing.DOWN);
+ if(attemptTeleport(world, toTeleport, vec, teleportMount, caster, ticksInUse, modifiers)) return true;
}
// If no suitable position was found on the other side of the wall, works like blink instead
-
- // Leave space for the player's head
- if(rayTrace.sideHit == EnumFacing.DOWN) pos = pos.down();
-
- // 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();
- }
-
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;
- }
+ Vec3d vec = GeometryUtils.getFaceCentre(pos, EnumFacing.DOWN);
+ if(attemptTeleport(world, toTeleport, vec, teleportMount, caster, ticksInUse, modifiers)) return true;
+ }else{ // The ray trace missed
+ Vec3d vec = caster.getPositionVector().add(caster.getLookVec().scale(range));
+ if(attemptTeleport(world, toTeleport, vec, teleportMount, caster, ticksInUse, modifiers)) return true;
+ }
+
+ return false;
+ }
+
+ protected boolean attemptTeleport(World world, Entity toTeleport, Vec3d destination, boolean teleportMount, EntityPlayer caster, int ticksInUse, SpellModifiers modifiers){
+
+ destination = EntityUtils.findSpaceForTeleport(toTeleport, destination, teleportMount);
+
+ if(destination != null){
// 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);
+ if(!teleportMount && caster.isRiding()) caster.dismountRidingEntity();
+ if(!world.isRemote) toTeleport.setPositionAndUpdate(destination.x, destination.y, destination.z);
this.playSound(world, caster, ticksInUse, -1, modifiers);
- caster.swingArm(hand);
- return true;
-
- }else{ // The ray trace missed
-
- Vec3d destination = caster.getPositionVector().add(caster.getLookVec().scale(range));
- BlockPos pos = new BlockPos(destination);
-
- // Prevents the player from teleporting into blocks and suffocating.
- if(world.getBlockState(pos).getMaterial().blocksMovement()
- || world.getBlockState(pos.up()).getMaterial().blocksMovement()){
- return false;
- }
-
- if(!world.isRemote) caster.setPositionAndUpdate(destination.x, destination.y, destination.z);
-
- this.playSound(world, caster, ticksInUse, -1, modifiers);
- caster.swingArm(hand);
return true;
}
+
+ return false;
}
}
diff --git a/src/main/java/electroblob/wizardry/spell/Transportation.java b/src/main/java/electroblob/wizardry/spell/Transportation.java
index c5f57c9c..19a810f8 100644
--- a/src/main/java/electroblob/wizardry/spell/Transportation.java
+++ b/src/main/java/electroblob/wizardry/spell/Transportation.java
@@ -9,7 +9,11 @@ import electroblob.wizardry.item.SpellActions;
import electroblob.wizardry.packet.PacketTransportation;
import electroblob.wizardry.packet.WizardryPacketHandler;
import electroblob.wizardry.registry.WizardryItems;
-import electroblob.wizardry.util.*;
+import electroblob.wizardry.util.GeometryUtils;
+import electroblob.wizardry.util.Location;
+import electroblob.wizardry.util.NBTExtras;
+import electroblob.wizardry.util.SpellModifiers;
+import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.nbt.NBTTagList;
@@ -177,9 +181,21 @@ public class Transportation extends Spell {
Location destination = locations.get(locations.size() - 1);
if(countdown == 1 && destination.dimension == player.dimension){
+
+ Entity mount = player.getRidingEntity();
+ if(mount != null) player.dismountRidingEntity();
+
player.setPositionAndUpdate(destination.pos.getX() + 0.5, destination.pos.getY(), destination.pos.getZ() + 0.5);
+
+ boolean teleportMount = mount != null && ItemArtefact.isArtefactActive(player, WizardryItems.charm_mount_teleporting);
+
+ if(teleportMount){
+ mount.setPositionAndUpdate(destination.pos.getX() + 0.5, destination.pos.getY(), destination.pos.getZ() + 0.5);
+ player.startRiding(mount);
+ }
+
player.addPotionEffect(new PotionEffect(MobEffects.BLINDNESS, 50, 0));
- IMessage msg = new PacketTransportation.Message(player.getEntityId());
+ IMessage msg = new PacketTransportation.Message(destination.pos, teleportMount ? null : player);
WizardryPacketHandler.net.sendToDimension(msg, player.world.provider.getDimension());
}
diff --git a/src/main/java/electroblob/wizardry/util/EntityUtils.java b/src/main/java/electroblob/wizardry/util/EntityUtils.java
index bf827af2..dbbf488d 100644
--- a/src/main/java/electroblob/wizardry/util/EntityUtils.java
+++ b/src/main/java/electroblob/wizardry/util/EntityUtils.java
@@ -1,5 +1,6 @@
package electroblob.wizardry.util;
+import com.google.common.collect.Streams;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.data.WizardData;
import electroblob.wizardry.entity.living.ISpellCaster;
@@ -17,17 +18,24 @@ import net.minecraft.item.ItemStack;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.DamageSource;
+import net.minecraft.util.EnumFacing;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.AxisAlignedBB;
+import net.minecraft.util.math.BlockPos;
+import net.minecraft.util.math.MathHelper;
+import net.minecraft.util.math.Vec3d;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.World;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import javax.annotation.Nullable;
+import java.util.Comparator;
import java.util.List;
import java.util.UUID;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
/**
* Contains useful static methods for retrieving and interacting with players, mobs and other entities. These methods
@@ -182,6 +190,83 @@ public final class EntityUtils {
target.knockBack(attacker, 0.4f, dx, dz);
}
+ /**
+ * Finds the nearest space to the specified position that the given entity can teleport to without being inside one
+ * or more solid blocks. The search volume is twice the size of the entity's bounding box (meaning that when
+ * teleported to the returned position, the original destination remains within the entity's bounding box).
+ * @param entity The entity being teleported
+ * @param destination The target position to search around
+ * @param accountForPassengers True to take passengers into account when searching for a space, false to ignore them
+ * @return The resulting position, or null if no space was found.
+ */
+ public static Vec3d findSpaceForTeleport(Entity entity, Vec3d destination, boolean accountForPassengers){
+
+ World world = entity.world;
+ AxisAlignedBB box = entity.getEntityBoundingBox();
+
+ if(accountForPassengers){
+ for(Entity passenger : entity.getPassengers()){
+ box = box.union(passenger.getEntityBoundingBox());
+ }
+ }
+
+ box = box.offset(destination.subtract(entity.posX, box.minY, entity.posZ));
+
+ // All the parameters of this method are INCLUSIVE, so even the max coordinates should be rounded down
+ Iterable cuboid = BlockPos.getAllInBox(MathHelper.floor(box.minX), MathHelper.floor(box.minY),
+ MathHelper.floor(box.minZ), MathHelper.floor(box.maxX), MathHelper.floor(box.maxY), MathHelper.floor(box.maxZ));
+
+ if(Streams.stream(cuboid).noneMatch(b -> world.collidesWithAnyBlock(new AxisAlignedBB(b)))){
+ // Nothing in the way
+ return destination;
+
+ }else{
+ // Nearby position search
+ double dx = box.maxX - box.minX;
+ double dy = box.maxY - box.minY;
+ double dz = box.maxZ - box.minZ;
+
+ // Minimum space required is (nx + px) blocks * (ny + py) blocks * (nz + pz) blocks
+ int nx = MathHelper.ceil(dx) / 2;
+ int px = MathHelper.ceil(dx) - nx;
+ int ny = MathHelper.ceil(dy) / 2;
+ int py = MathHelper.ceil(dy) - ny;
+ int nz = MathHelper.ceil(dz) / 2;
+ int pz = MathHelper.ceil(dz) - nz;
+
+ // Check all the blocks in and around the bounding box...
+ List nearby = Streams.stream(BlockPos.getAllInBox(MathHelper.floor(box.minX) - 1,
+ MathHelper.floor(box.minY) - 1, MathHelper.floor(box.minZ) - 1,
+ MathHelper.floor(box.maxX) + 1, MathHelper.floor(box.maxY) + 1,
+ MathHelper.floor(box.maxZ) + 1)).collect(Collectors.toList());
+
+ // ... but only return positions actually inside the box
+ List possiblePositions = Streams.stream(cuboid).collect(Collectors.toList());
+
+ // Rather than iterate over each position and check if the box fits, find all solid blocks and cut out all
+ // positions whose corresponding box would include them - this is waaay more efficient!
+ while(!nearby.isEmpty()){
+
+ BlockPos pos = nearby.remove(0);
+
+ if(world.collidesWithAnyBlock(new AxisAlignedBB(pos))){
+ Predicate nearSolidBlock = b -> b.getX() >= pos.getX() - nx && b.getX() <= pos.getX() + px
+ && b.getY() >= pos.getY() - ny && b.getY() <= pos.getY() + py
+ && b.getZ() >= pos.getZ() - nz && b.getZ() <= pos.getZ() + pz;
+ nearby.removeIf(nearSolidBlock);
+ possiblePositions.removeIf(nearSolidBlock);
+ }
+ }
+
+ if(possiblePositions.isEmpty()) return null; // No space nearby
+
+ BlockPos nearest = possiblePositions.stream().min(Comparator.comparingDouble(b -> destination.squareDistanceTo(
+ b.getX() + 0.5, b.getY() + 0.5, b.getZ() + 0.5))).get(); // The list can't be empty
+
+ return GeometryUtils.getFaceCentre(nearest, EnumFacing.DOWN);
+ }
+ }
+
// Damage
// ===============================================================================================================
diff --git a/src/main/resources/assets/ebwizardry/lang/en_gb.lang b/src/main/resources/assets/ebwizardry/lang/en_gb.lang
index 325c1eb2..8fc1175e 100644
--- a/src/main/resources/assets/ebwizardry/lang/en_gb.lang
+++ b/src/main/resources/assets/ebwizardry/lang/en_gb.lang
@@ -370,6 +370,8 @@ item.ebwizardry\:charm_experience_tome.name=Tome of the Diligent
item.ebwizardry\:charm_experience_tome.desc=Increases the rate at which wands gain progression by 50%%
item.ebwizardry\:charm_move_speed.name=Icarus Medallion
item.ebwizardry\:charm_move_speed.desc=Move at near-full speed when casting spells
+item.ebwizardry\:charm_spell_discovery.name=Archivist's Eyeglass
+item.ebwizardry\:charm_spell_discovery.desc=Spell books found in chests are much more likely to be ones you have not yet discovered
item.ebwizardry\:charm_auto_smelt.name=Metallurgist's Mark
item.ebwizardry\:charm_auto_smelt.desc=Pocket furnace triggers automatically when bound to a wand on your hotbar
item.ebwizardry\:charm_lava_walking.name=Nether Ice Core
@@ -396,6 +398,8 @@ item.ebwizardry\:charm_transportation.name=Ancient Compass
item.ebwizardry\:charm_transportation.desc=Up to four stone circles may be remembered and selected from when using transportation
item.ebwizardry\:charm_black_hole.name=Void Opal
item.ebwizardry\:charm_black_hole.desc=Black hole sucks in and destroys blocks
+item.ebwizardry\:charm_mount_teleporting.name=Spectral Tether
+item.ebwizardry\:charm_mount_teleporting.desc=Teleporting while riding an animal or vehicle brings it with you
item.ebwizardry\:charm_feeding.name=Bottomless Provisions
item.ebwizardry\:charm_feeding.desc=Replenish hunger and satiety trigger automatically when bound to a wand on your hotbar
diff --git a/src/main/resources/assets/ebwizardry/lang/en_us.lang b/src/main/resources/assets/ebwizardry/lang/en_us.lang
index 4156c4bc..7b9df5c4 100644
--- a/src/main/resources/assets/ebwizardry/lang/en_us.lang
+++ b/src/main/resources/assets/ebwizardry/lang/en_us.lang
@@ -370,6 +370,8 @@ item.ebwizardry\:charm_experience_tome.name=Tome of the Diligent
item.ebwizardry\:charm_experience_tome.desc=Increases the rate at which wands gain progression by 50%%
item.ebwizardry\:charm_move_speed.name=Icarus Medallion
item.ebwizardry\:charm_move_speed.desc=Move at near-full speed when casting spells
+item.ebwizardry\:charm_spell_discovery.name=Archivist's Eyeglass
+item.ebwizardry\:charm_spell_discovery.desc=Spell books found in chests are much more likely to be ones you have not yet discovered
item.ebwizardry\:charm_auto_smelt.name=Metallurgist's Mark
item.ebwizardry\:charm_auto_smelt.desc=Pocket furnace triggers automatically when bound to a wand on your hotbar
item.ebwizardry\:charm_lava_walking.name=Nether Ice Core
@@ -396,6 +398,8 @@ item.ebwizardry\:charm_transportation.name=Ancient Compass
item.ebwizardry\:charm_transportation.desc=Up to four stone circles may be remembered and selected from when using transportation
item.ebwizardry\:charm_black_hole.name=Void Opal
item.ebwizardry\:charm_black_hole.desc=Black hole sucks in and destroys blocks
+item.ebwizardry\:charm_mount_teleporting.name=Spectral Tether
+item.ebwizardry\:charm_mount_teleporting.desc=Teleporting while riding an animal or vehicle brings it with you
item.ebwizardry\:charm_feeding.name=Bottomless Provisions
item.ebwizardry\:charm_feeding.desc=Replenish hunger and satiety trigger automatically when bound to a wand on your hotbar
diff --git a/src/main/resources/assets/ebwizardry/models/item/charm_mount_teleporting.json b/src/main/resources/assets/ebwizardry/models/item/charm_mount_teleporting.json
new file mode 100644
index 00000000..b0d8b187
--- /dev/null
+++ b/src/main/resources/assets/ebwizardry/models/item/charm_mount_teleporting.json
@@ -0,0 +1,6 @@
+{
+ "parent": "item/generated",
+ "textures": {
+ "layer0": "ebwizardry:items/charm_mount_teleporting"
+ }
+}
\ No newline at end of file
diff --git a/src/main/resources/assets/ebwizardry/models/item/charm_spell_discovery.json b/src/main/resources/assets/ebwizardry/models/item/charm_spell_discovery.json
new file mode 100644
index 00000000..061c845f
--- /dev/null
+++ b/src/main/resources/assets/ebwizardry/models/item/charm_spell_discovery.json
@@ -0,0 +1,6 @@
+{
+ "parent": "item/generated",
+ "textures": {
+ "layer0": "ebwizardry:items/charm_spell_discovery"
+ }
+}
\ No newline at end of file
diff --git a/src/main/resources/assets/ebwizardry/textures/items/charm_mount_teleporting.png b/src/main/resources/assets/ebwizardry/textures/items/charm_mount_teleporting.png
new file mode 100644
index 00000000..4ca520fc
Binary files /dev/null and b/src/main/resources/assets/ebwizardry/textures/items/charm_mount_teleporting.png differ
diff --git a/src/main/resources/assets/ebwizardry/textures/items/charm_spell_discovery.png b/src/main/resources/assets/ebwizardry/textures/items/charm_spell_discovery.png
new file mode 100644
index 00000000..ea0c3575
Binary files /dev/null and b/src/main/resources/assets/ebwizardry/textures/items/charm_spell_discovery.png differ