|
@@ -1,6 +1,5 @@
|
|
|
package me.km.api;
|
|
|
|
|
|
-import java.lang.reflect.Field;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collection;
|
|
@@ -8,6 +7,7 @@ import java.util.List;
|
|
|
import java.util.Random;
|
|
|
import java.util.stream.Collectors;
|
|
|
import me.km.KajetansMod;
|
|
|
+import me.km.dimensions.ModTeleporter;
|
|
|
import me.km.exception.PlayerNotFoundException;
|
|
|
import net.minecraft.entity.Entity;
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
@@ -17,6 +17,7 @@ import net.minecraft.block.BlockContainer;
|
|
|
import net.minecraft.block.BlockDoor;
|
|
|
import net.minecraft.block.BlockPistonMoving;
|
|
|
import net.minecraft.block.BlockTrapDoor;
|
|
|
+import net.minecraft.block.properties.IProperty;
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
|
|
import net.minecraft.init.Blocks;
|
|
@@ -30,14 +31,27 @@ import net.minecraft.item.ItemSpade;
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
import net.minecraft.util.math.Vec3d;
|
|
|
-import net.minecraft.util.math.Vec3i;
|
|
|
import net.minecraft.world.World;
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
-import net.minecraft.item.ItemSword;
|
|
|
+import net.minecraft.item.ItemSword;
|
|
|
import net.minecraft.potion.Potion;
|
|
|
+import net.minecraft.util.math.RayTraceResult;
|
|
|
+import net.minecraft.world.WorldServer;
|
|
|
|
|
|
public class Utils
|
|
|
{
|
|
|
+ public static <T extends Comparable<T>> T getStateValue(IBlockState state, IProperty<T> property)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ return state.getValue(property);
|
|
|
+ }
|
|
|
+ catch(IllegalArgumentException ex)
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -304,28 +318,39 @@ public class Utils
|
|
|
return new Location(ent.getEntityWorld(), ent.getPositionVector(), ent.rotationYaw, ent.rotationPitch);
|
|
|
}
|
|
|
|
|
|
- public static BlockPos getEyeLocation(Entity ent)
|
|
|
+ public static Vec3d getEyeLocation(Entity ent)
|
|
|
{
|
|
|
- return ent.getPosition().add(0, ent.getEyeHeight(), 0);
|
|
|
+ return ent.getPositionVector().addVector(0, ent.getEyeHeight(), 0);
|
|
|
}
|
|
|
|
|
|
public static void teleportEntity(Entity ent, Location l)
|
|
|
{
|
|
|
Vec3d pos = l.getPos();
|
|
|
-
|
|
|
+
|
|
|
if(ent instanceof EntityPlayerMP)
|
|
|
{
|
|
|
+ EntityPlayerMP p = (EntityPlayerMP) ent;
|
|
|
+ if(ent.dimension != l.getWorld().provider.getDimension())
|
|
|
+ {
|
|
|
+ int dim = l.getWorld().provider.getDimension();
|
|
|
+ KajetansMod.server.getPlayerList().transferPlayerToDimension(p, dim, new ModTeleporter(KajetansMod.server.worldServerForDimension(dim)));
|
|
|
+ }
|
|
|
if(l.getYaw() != 0 && l.getPitch() != 0)
|
|
|
{
|
|
|
- ((EntityPlayerMP) ent).connection.setPlayerLocation(pos.xCoord, pos.yCoord, pos.zCoord, l.getYaw(), l.getPitch());
|
|
|
+ p.connection.setPlayerLocation(pos.xCoord, pos.yCoord, pos.zCoord, l.getYaw(), l.getPitch());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- ((EntityPlayerMP) ent).connection.setPlayerLocation(pos.xCoord, pos.yCoord, pos.zCoord, ent.rotationYaw, ent.rotationPitch);
|
|
|
+ p.connection.setPlayerLocation(pos.xCoord, pos.yCoord, pos.zCoord, ent.rotationYaw, ent.rotationPitch);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ if(ent.dimension != l.getWorld().provider.getDimension())
|
|
|
+ {
|
|
|
+ WorldServer n = KajetansMod.server.worldServerForDimension(l.getWorld().provider.getDimension());
|
|
|
+ KajetansMod.server.getPlayerList().transferEntityToWorld(ent, ent.dimension, KajetansMod.server.worldServerForDimension(ent.dimension), n, new ModTeleporter(n));
|
|
|
+ }
|
|
|
if(l.getYaw() != 0 && l.getPitch() != 0)
|
|
|
{
|
|
|
ent.setLocationAndAngles(pos.xCoord, pos.yCoord, pos.zCoord, l.getYaw(), l.getPitch());
|
|
@@ -374,13 +399,12 @@ public class Utils
|
|
|
{
|
|
|
World w = p.getEntityWorld();
|
|
|
BlockPos l = getPlayerTarget(p, radius);
|
|
|
- BlockPos eye = getEyeLocation(p);
|
|
|
- List<Entity> col = getEntitiesExcluding(p, w, eye, l);
|
|
|
+ Vec3d end = new Vec3d(l.getX(), l.getY(), l.getZ());
|
|
|
+ Vec3d eye = getEyeLocation(p);
|
|
|
+ List<Entity> col = getEntitiesExcluding(p, w, new BlockPos(eye), l);
|
|
|
col.removeIf(ent -> !type.isAssignableFrom(ent.getClass()));
|
|
|
|
|
|
|
|
|
- Vec3d first = new Vec3d(eye.getX(), eye.getY(), eye.getZ());
|
|
|
- Vec3d second = new Vec3d(l.getX(), l.getY(), l.getZ());
|
|
|
col.removeIf(ent ->
|
|
|
{
|
|
|
AxisAlignedBB bound = ent.getCollisionBoundingBox();
|
|
@@ -388,12 +412,12 @@ public class Utils
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
- return bound.calculateIntercept(first, second) == null;
|
|
|
+ return bound.calculateIntercept(eye, end) == null;
|
|
|
});
|
|
|
|
|
|
return (T) col.stream().sorted((Entity e1, Entity e2) ->
|
|
|
{
|
|
|
- return Double.compare(e1.getDistanceSq(eye), e2.getDistanceSq(eye));
|
|
|
+ return Double.compare(e1.getDistanceSq(eye.xCoord, eye.yCoord, eye.zCoord), e2.getDistanceSq(eye.xCoord, eye.yCoord, eye.zCoord));
|
|
|
}).findFirst().orElse(null);
|
|
|
}
|
|
|
|
|
@@ -406,25 +430,21 @@ public class Utils
|
|
|
return w.getPlayers(EntityPlayer.class, p -> true).stream().min((p1, p2) -> Double.compare(p1.getDistanceSq(l), p2.getDistanceSq(l))).orElse(null);
|
|
|
}
|
|
|
|
|
|
- public static BlockPos getPlayerTarget(EntityPlayer p, int range)
|
|
|
+ public static BlockPos getPlayerTarget(EntityPlayer p, double range)
|
|
|
{
|
|
|
if(range > 64)
|
|
|
{
|
|
|
range = 64;
|
|
|
}
|
|
|
World w = p.getEntityWorld();
|
|
|
- BlockPos l = getEyeLocation(p);
|
|
|
- Vec3d unit2 = p.getLookVec();
|
|
|
- Vec3i unit = new Vec3i(unit2.xCoord, unit2.yCoord, unit2.zCoord);
|
|
|
- for(int i = 0; i < range; i++)
|
|
|
+ Vec3d start = getEyeLocation(p);
|
|
|
+ Vec3d end = start.add(p.getLookVec().scale(range));
|
|
|
+ RayTraceResult ray = w.rayTraceBlocks(start, end, true);
|
|
|
+ if(ray == null)
|
|
|
{
|
|
|
- l = l.add(unit);
|
|
|
- if(w.isBlockFullCube(l))
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
+ return new BlockPos(end);
|
|
|
}
|
|
|
- return l;
|
|
|
+ return ray.getBlockPos();
|
|
|
}
|
|
|
|
|
|
public static BlockPos getPlayerTarget(EntityPlayer p)
|
|
@@ -475,32 +495,24 @@ public class Utils
|
|
|
|
|
|
|
|
|
|
|
|
- public static Block getSameNearbyBlock(World w, BlockPos pos, Block b)
|
|
|
+ public static BlockPos getSameNearbyBlock(World w, BlockPos pos, Block b)
|
|
|
{
|
|
|
- Block bcheck = Location.getRelativeBlock(w, pos, 1, 0, 0).getBlock();
|
|
|
- if(bcheck == b)
|
|
|
+ if(Location.getRelativeBlock(w, pos, 1, 0, 0).getBlock() == b)
|
|
|
{
|
|
|
- return bcheck;
|
|
|
+ return pos.add(1, 0, 0);
|
|
|
}
|
|
|
-
|
|
|
- bcheck = Location.getRelativeBlock(w, pos, -1, 0, 0).getBlock();
|
|
|
- if(bcheck == b)
|
|
|
+ else if(Location.getRelativeBlock(w, pos, -1, 0, 0).getBlock() == b)
|
|
|
{
|
|
|
- return bcheck;
|
|
|
+ return pos.add(-1, 0, 0);
|
|
|
}
|
|
|
-
|
|
|
- bcheck = Location.getRelativeBlock(w, pos, 0, 0, 1).getBlock();;
|
|
|
- if(bcheck == b)
|
|
|
+ else if(Location.getRelativeBlock(w, pos, 0, 0, 1).getBlock() == b)
|
|
|
{
|
|
|
- return bcheck;
|
|
|
+ return pos.add(0, 0, 1);
|
|
|
}
|
|
|
-
|
|
|
- bcheck = Location.getRelativeBlock(w, pos, 0, 0, -1).getBlock();
|
|
|
- if(bcheck == b)
|
|
|
+ else if(Location.getRelativeBlock(w, pos, 0, 0, -1).getBlock() == b)
|
|
|
{
|
|
|
- return bcheck;
|
|
|
+ return pos.add(0, 0, -1);
|
|
|
}
|
|
|
-
|
|
|
return null;
|
|
|
}
|
|
|
|