Modified the Sigil of the Phantom Bridge so it better performs with speed modifications

This commit is contained in:
WayofTime 2016-10-16 19:33:14 -04:00
parent e3c55da214
commit 59e10a782b
2 changed files with 62 additions and 9 deletions

View file

@ -13,6 +13,7 @@ Version 2.1.0-66
- Changed most of the BlockString blocks to a BlockEnum in order to solve a loading issue with schematics.
- Added the entries for the Skeleton Turret Array and the Updraft Array
- Added the Bounce Array
- Modified the Sigil of the Phantom Bridge so it better performs with speed modifications
------------------------------------------------------
Version 2.1.0-65

View file

@ -1,13 +1,23 @@
package WayofTime.bloodmagic.item.sigil;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.apache.commons.lang3.tuple.Pair;
import WayofTime.bloodmagic.registry.ModBlocks;
public class ItemSigilPhantomBridge extends ItemSigilToggleableBase
{
private Map<EntityPlayer, Pair<Double, Double>> prevPositionMap = new HashMap<EntityPlayer, Pair<Double, Double>>();
private double expansionFactor = 2;
private int range = 3;
public ItemSigilPhantomBridge()
{
super("phantomBridge", 100);
@ -16,28 +26,70 @@ public class ItemSigilPhantomBridge extends ItemSigilToggleableBase
@Override
public void onSigilUpdate(ItemStack stack, World world, EntityPlayer player, int itemSlot, boolean isSelected)
{
if ((!player.onGround && !player.isRiding()) && !player.isSneaking())
return;
if (!prevPositionMap.containsKey(player))
{
prevPositionMap.put(player, Pair.of(player.posX, player.posZ));
}
if ((!player.onGround && !player.isRiding()) && !player.isSneaking())
{
prevPositionMap.put(player, Pair.of(player.posX, player.posZ));
return;
}
int range = 2;
int verticalOffset = -1;
if (player.isSneaking())
verticalOffset--;
int posX = (int) Math.round(player.posX - 0.5f);
int posY = (int) player.posY;
int posZ = (int) Math.round(player.posZ - 0.5f);
Pair<Double, Double> prevPosition = prevPositionMap.get(player);
for (int ix = posX - range; ix <= posX + range; ix++)
double playerVelX = player.posX - prevPosition.getLeft();
double playerVelZ = player.posZ - prevPosition.getRight();
double totalVel = Math.sqrt(playerVelX * playerVelX + playerVelZ * playerVelZ);
if (totalVel > 2)
{
for (int iz = posZ - range; iz <= posZ + range; iz++)
//I am SURE you are teleporting!
playerVelX = 0;
playerVelZ = 0;
}
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++)
{
BlockPos blockPos = new BlockPos(ix, posY + verticalOffset, iz);
if (computeEllipse(ix + avgX, iz + avgZ, posX, posZ, offsetPosX, offsetPosZ) > C)
{
continue;
}
BlockPos blockPos = new BlockPos(ix + posX, posY + verticalOffset, iz + posZ);
if (world.isAirBlock(blockPos))
world.setBlockState(blockPos, ModBlocks.PHANTOM_BLOCK.getDefaultState());
}
}
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));
}
}