2015-12-27 19:38:12 -05:00
|
|
|
package WayofTime.bloodmagic.item.sigil;
|
|
|
|
|
2016-10-16 19:33:14 -04:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2016-11-11 16:57:50 -08:00
|
|
|
import WayofTime.bloodmagic.api.util.helper.PlayerHelper;
|
2015-12-27 19:38:12 -05:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2016-03-18 15:38:26 -04:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2015-12-27 19:38:12 -05:00
|
|
|
import net.minecraft.world.World;
|
2016-10-16 19:33:14 -04:00
|
|
|
|
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
|
|
2017-08-14 20:53:42 -07:00
|
|
|
import WayofTime.bloodmagic.registry.RegistrarBloodMagicBlocks;
|
2015-12-27 19:38:12 -05:00
|
|
|
|
2016-03-22 21:10:05 -04:00
|
|
|
public class ItemSigilPhantomBridge extends ItemSigilToggleableBase
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
2016-10-16 19:33:14 -04:00
|
|
|
private Map<EntityPlayer, Pair<Double, Double>> prevPositionMap = new HashMap<EntityPlayer, Pair<Double, Double>>();
|
|
|
|
private double expansionFactor = 2;
|
|
|
|
private int range = 3;
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public ItemSigilPhantomBridge()
|
|
|
|
{
|
2015-12-27 19:38:12 -05:00
|
|
|
super("phantomBridge", 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-12-30 15:34:40 -05:00
|
|
|
public void onSigilUpdate(ItemStack stack, World world, EntityPlayer player, int itemSlot, boolean isSelected)
|
|
|
|
{
|
2016-11-11 16:57:50 -08:00
|
|
|
if (PlayerHelper.isFakePlayer(player))
|
|
|
|
return;
|
|
|
|
|
2016-10-16 19:33:14 -04:00
|
|
|
if (!prevPositionMap.containsKey(player))
|
|
|
|
{
|
|
|
|
prevPositionMap.put(player, Pair.of(player.posX, player.posZ));
|
|
|
|
}
|
|
|
|
|
2016-05-11 17:27:01 -07:00
|
|
|
if ((!player.onGround && !player.isRiding()) && !player.isSneaking())
|
2016-10-16 19:33:14 -04:00
|
|
|
{
|
|
|
|
prevPositionMap.put(player, Pair.of(player.posX, player.posZ));
|
2015-12-27 19:38:12 -05:00
|
|
|
return;
|
2016-10-16 19:33:14 -04:00
|
|
|
}
|
2015-12-27 19:38:12 -05:00
|
|
|
|
|
|
|
int verticalOffset = -1;
|
|
|
|
|
|
|
|
if (player.isSneaking())
|
|
|
|
verticalOffset--;
|
|
|
|
|
2016-10-16 19:33:14 -04:00
|
|
|
Pair<Double, Double> prevPosition = prevPositionMap.get(player);
|
2015-12-27 19:38:12 -05:00
|
|
|
|
2016-10-16 19:33:14 -04:00
|
|
|
double playerVelX = player.posX - prevPosition.getLeft();
|
|
|
|
double playerVelZ = player.posZ - prevPosition.getRight();
|
|
|
|
|
|
|
|
double totalVel = Math.sqrt(playerVelX * playerVelX + playerVelZ * playerVelZ);
|
|
|
|
if (totalVel > 2)
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
2016-10-16 19:33:14 -04:00
|
|
|
//I am SURE you are teleporting!
|
|
|
|
playerVelX = 0;
|
|
|
|
playerVelZ = 0;
|
2016-12-06 11:53:47 -05:00
|
|
|
totalVel = 0;
|
2016-10-16 19:33:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
BlockPos playerPos = player.getPosition();
|
|
|
|
int posX = playerPos.getX();
|
|
|
|
int posY = playerPos.getY();
|
|
|
|
int posZ = playerPos.getZ();
|
|
|
|
|
|
|
|
double offsetPosX = posX + expansionFactor * playerVelX;
|
|
|
|
double offsetPosZ = posZ + expansionFactor * playerVelZ;
|
|
|
|
double avgX = (posX + offsetPosX) / 2;
|
|
|
|
double avgZ = (posZ + offsetPosZ) / 2;
|
|
|
|
|
|
|
|
double C = 2 * (range + expansionFactor * totalVel) + 1;
|
|
|
|
int truncC = (int) C;
|
|
|
|
|
|
|
|
//TODO: Make this for-loop better.
|
|
|
|
for (int ix = -truncC; ix <= truncC; ix++)
|
|
|
|
{
|
|
|
|
for (int iz = -truncC; iz <= truncC; iz++)
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
2016-10-16 19:33:14 -04:00
|
|
|
if (computeEllipse(ix + avgX, iz + avgZ, posX, posZ, offsetPosX, offsetPosZ) > C)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockPos blockPos = new BlockPos(ix + posX, posY + verticalOffset, iz + posZ);
|
2015-12-27 19:38:12 -05:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
if (world.isAirBlock(blockPos))
|
2017-08-14 20:53:42 -07:00
|
|
|
world.setBlockState(blockPos, RegistrarBloodMagicBlocks.PHANTOM.getDefaultState());
|
2015-12-27 19:38:12 -05:00
|
|
|
}
|
|
|
|
}
|
2016-10-16 19:33:14 -04:00
|
|
|
|
|
|
|
prevPositionMap.put(player, Pair.of(player.posX, player.posZ));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static double computeEllipse(double x, double z, double focusX1, double focusZ1, double focusX2, double focusZ2)
|
|
|
|
{
|
|
|
|
return Math.sqrt((x - focusX1) * (x - focusX1) + (z - focusZ1) * (z - focusZ1)) + Math.sqrt((x - focusX2) * (x - focusX2) + (z - focusZ2) * (z - focusZ2));
|
2015-12-27 19:38:12 -05:00
|
|
|
}
|
|
|
|
}
|