From 59e10a782b93c35db0309adfd1b6aed96ed561c8 Mon Sep 17 00:00:00 2001 From: WayofTime Date: Sun, 16 Oct 2016 19:33:14 -0400 Subject: [PATCH] Modified the Sigil of the Phantom Bridge so it better performs with speed modifications --- changelog.txt | 1 + .../item/sigil/ItemSigilPhantomBridge.java | 70 ++++++++++++++++--- 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/changelog.txt b/changelog.txt index e6547b15..32dec725 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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 diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilPhantomBridge.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilPhantomBridge.java index f6745251..8a8846a0 100644 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilPhantomBridge.java +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilPhantomBridge.java @@ -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> prevPositionMap = new HashMap>(); + 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 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)); } }