Compare commits

..
21 Commits
Author SHA1 Message Date
Martin Robertz d60fc9b436 update 2024-05-20 11:07:51 +02:00
Martin Robertz 6ad43b2e0d Merge remote-tracking branch 'TheUnderTaker11/git-please' into dev 2024-05-20 11:07:22 +02:00
CreditScore 77f3e6974f Travel Staff Blink Keybind fixes.
Fixes 2 separate bugs with the SoT keybind.
1. Staff of Teleportation in GTNH pack specifically didn't work due to reporting as having 0 power through the RF API. Fixed this by having it always report that it's full of power since it has infinite.
2. BlackSteelSword and EndSteelSword (The Ender and MKII) both were quite funky with keybind, causing no teleports to happen when they really should have.
Fixed this through tweaks to how this is handled in a number of places to allow for proper handling while not changing the default held/shift held behavior.

Tested in SP, Anchor behavior while holding staffs and Swords with travel thing on them work as expected. Keybind now works and is able to use swords with travel thing on them.
One quirk is that if you are holding a sword with travel upgrade, but NOT shifting, the sword itself stops counting as a valid travel item. So if ONLY using sword no separate SoT the keybind will not work unless you hold shift. If you have another SoT in your inventory it will identify and use that and still blink you upon hitting keybind.
This quirk doesn't really matter in most cases, just something worth noting I guess.
2024-05-19 15:13:50 -05:00
Martin Robertz 42573b3fa4 update 2024-05-09 10:04:12 +02:00
Martin Robertz c4cbe05dfe Merge branch 'master' into dev
# Conflicts:
#	dependencies.gradle
2024-05-09 10:03:47 +02:00
Martin Robertz a591baf426 update 2024-05-06 09:55:08 +02:00
Martin Robertz 4131a1e7b7 Merge remote-tracking branch 'origin/tweak-teleport-staff' into dev 2024-05-06 09:54:22 +02:00
github-actions[bot]andGitHub GTNH Actions 32c251d805 spotlessApply (#161)
Co-authored-by: GitHub GTNH Actions <>
2024-04-23 19:03:07 -06:00
D-Cysteine b237c6cb4d 2-in-1 TP: find destination client-side 2024-04-23 18:59:06 -06:00
D-Cysteine 58e8bf712c Limit backwards teleport check 2024-04-14 13:01:17 -06:00
D-Cysteine f1978a6a15 Handle server-side travelToLocation 2024-04-13 16:14:42 -06:00
D-Cysteine 5bd58bd981 Check anchor accessibility and require player != null 2024-04-13 16:14:25 -06:00
D-Cysteine b0f7c8600a Check for obstructed anchor on long-distance teleport 2024-04-13 15:35:40 -06:00
D-Cysteine 1b2c38cf0a Clear stored anchors on world load 2024-04-13 15:35:26 -06:00
D-Cysteine e6c216ab31 Add server-side handling for two-in-one teleport action 2024-04-13 15:35:08 -06:00
D-Cysteine 745b6ed528 Various TP fixes
* Allow TP to unloaded anchor
* Improve TP through wall by checking every 0.5 instead of 2 distance
* Fix blink placing player one block too high
* Fix anchor being incorrectly selected sometimes by constraining to visual angle
2024-04-13 14:46:20 -06:00
D-Cysteine 9422337282 Add configs for teleport staff actions 2024-04-13 14:44:43 -06:00
github-actions[bot]andGitHub GTNH Actions 3b0025500e spotlessApply (#159)
Co-authored-by: GitHub GTNH Actions <>
2024-04-13 17:36:56 +02:00
D-Cysteine dd739ba58e Fix logic 2024-04-13 09:11:50 -06:00
D-Cysteine edbd5621c3 Fix comment 2024-04-13 09:10:10 -06:00
D-Cysteine d90c7dae1b Tweak teleport staff controls 2024-04-13 09:06:16 -06:00
8 changed files with 209 additions and 172 deletions

No files matched your search

+6 -6
View File
@@ -2,17 +2,17 @@
dependencies {
api('com.github.GTNewHorizons:EnderCore:0.4.6:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:ForestryMC:4.9.3:dev')
compileOnly('com.github.GTNewHorizons:NotEnoughItems:2.6.1-GTNH:dev')
compileOnly('com.github.GTNewHorizons:ForestryMC:4.9.0:dev')
compileOnly('com.github.GTNewHorizons:NotEnoughItems:2.6.0-GTNH:dev')
compileOnly("com.github.GTNewHorizons:GTNHLib:0.2.11:dev")
compileOnly('com.github.GTNewHorizons:BuildCraft:7.1.39:dev')
api('curse.maven:cofh-lib-220333:2388748') // https://www.curseforge.com/minecraft/mc-mods/cofh-lib/files/2388748
shadowImplementation('cglib:cglib-nodep:3.3.0')
compileOnly('com.github.GTNewHorizons:waila:1.8.0:api') {transitive = false}
compileOnly('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-404-GTNH:api') {transitive = false}
compileOnly('com.github.GTNewHorizons:waila:1.7.3:api') {transitive = false}
compileOnly('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-400-GTNH:api') {transitive = false}
compileOnly('com.github.GTNewHorizons:Baubles:1.0.4:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.48.20:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.46.18:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:Railcraft:9.15.8:api') {transitive = false}
compileOnly('com.github.GTNewHorizons:StorageDrawers:1.13.5-GTNH:api') {transitive = false}
compileOnly('com.github.GTNewHorizons:Chisel:2.15.0-GTNH:dev') {transitive = false}
@@ -24,5 +24,5 @@ dependencies {
compileOnly(rfg.deobf('curse.maven:mekanism-268560:2475797')) // https://www.curseforge.com/minecraft/mc-mods/mekanism/files/2475797
compileOnly(rfg.deobf('maven.modrinth:immibis-microblocks:59.1.2')) // https://modrinth.com/mod/immibis-microblocks/version/59.1.2
compileOnlyApi('com.github.GTNewHorizons:Angelica:1.0.0-alpha52:api') {transitive = false}
compileOnlyApi('com.github.GTNewHorizons:Angelica:1.0.0-alpha50:api') {transitive = false}
}
@@ -2,11 +2,10 @@ package crazypants.enderio.conduit.liquid;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
@@ -114,29 +113,27 @@ public class LiquidConduitRenderer extends DefaultConduitRenderer implements IRe
}
}
private static final Map<CollidableComponent, Map<Fluid, List<CachableRenderStatement>>> cache = Collections
.synchronizedMap(new WeakHashMap<>());
private static Map<CollidableComponent, Map<Fluid, List<CachableRenderStatement>>> cache = new WeakHashMap<CollidableComponent, Map<Fluid, List<CachableRenderStatement>>>();
public static List<CachableRenderStatement> computeFluidOutlineToCache(CollidableComponent component, Fluid fluid,
double scaleFactor, float outlineWidth) {
// Only init once per component across all threads so the cache stays accurate.
Map<Fluid, List<CachableRenderStatement>> cache0 = cache
.computeIfAbsent(component, _k -> new ConcurrentHashMap<>());
// The rest of this function 'should' be in a `computeIfAbsent` as well for:
// `cache0.computeIfAbsent(fluid, _k -> ...)` but that won't cause a bug in this case,
// just a bit more garbage.
Map<Fluid, List<CachableRenderStatement>> cache0 = cache.get(component);
if (cache0 == null) {
cache0 = new HashMap<Fluid, List<CachableRenderStatement>>();
cache.put(component, cache0);
}
List<CachableRenderStatement> data = cache0.get(fluid);
if (data != null) {
return data;
}
data = new ArrayList<>();
data = new ArrayList<CachableRenderStatement>();
cache0.put(fluid, data);
IIcon texture = fluid.getStillIcon();
if (texture == null) {
texture = fluid.getIcon();
if (texture == null) {
cache0.put(fluid, data);
return data;
}
}
@@ -195,7 +192,6 @@ public class LiquidConduitRenderer extends DefaultConduitRenderer implements IRe
}
}
}
cache0.put(fluid, data);
return data;
}
@@ -174,6 +174,8 @@ public final class Config {
* The distance travelled when no block is found within {@link #teleportStaffMaxBlinkDistance}.
*/
public static int teleportStaffFailedBlinkDistance = 64;
/** If true, use the original staff of teleportation controls. */
public static boolean teleportStaffOriginalControls = false;
/**
* Sets the teleport staff right-click action.
@@ -186,6 +188,9 @@ public final class Config {
* <li><b>2:</b> Teleport to anchor
* <li><b>3:</b> Teleport to anchor, or to look if no anchor <em>(default)</em>
* </ul>
*
* <p>
* Overridden if {@link #teleportStaffOriginalControls} is true.
*/
public static int teleportStaffAction = 3;
@@ -200,6 +205,9 @@ public final class Config {
* <li><b>2:</b> Teleport to anchor
* <li><b>3:</b> Teleport to anchor, or to look if no anchor
* </ul>
*
* <p>
* Overridden if {@link #teleportStaffOriginalControls} is true.
*/
public static int teleportStaffSneakAction = 1;
@@ -1299,25 +1307,35 @@ public final class Config {
"Number of blocks teleported when no block is being looked at.")
.getInt(teleportStaffFailedBlinkDistance);
teleportStaffOriginalControls = config.get(
sectionPersonal.name,
"teleportStaffOriginalControls",
teleportStaffOriginalControls,
"If true, the staff of teleportation will use its original controls: R-Click for teleport to look, Shift R-Click for teleport to anchor.")
.getBoolean(teleportStaffOriginalControls);
teleportStaffAction = config.get(
sectionStaff.name,
sectionPersonal.name,
"teleportStaffAction",
teleportStaffAction,
"Sets the action for right-click with the staff of teleportation. Values:\n" + " 0: Do nothing\n"
+ " 1: Teleport to look\n"
+ " 2: Teleport to anchor\n"
+ " 3: Teleport to anchor, or look if no anchor (default)")
+ " 3: Teleport to anchor, or look if no anchor (default)\n"
+ "Overridden if teleportStaffOriginalControls is true.")
.getInt(teleportStaffAction);
teleportStaffSneakAction = config.get(
sectionStaff.name,
"teleportStaffSneakAction",
teleportStaffSneakAction,
"Sets the action for sneak right-click with the staff of teleportation. Values:\n"
+ " 0: Do nothing\n"
+ " 1: Teleport to look (default)\n"
+ " 2: Teleport to anchor\n"
+ " 3: Teleport to anchor, or look if no anchor")
teleportStaffSneakAction = config
.get(
sectionPersonal.name,
"teleportStaffSneakAction",
teleportStaffSneakAction,
"Sets the action for sneak right-click with the staff of teleportation. Values:\n"
+ " 0: Do nothing\n"
+ " 1: Teleport to look (default)\n"
+ " 2: Teleport to anchor\n"
+ " 3: Teleport to anchor, or look if no anchor\n"
+ "Overridden if teleportStaffOriginalControls is true.")
.getInt(teleportStaffSneakAction);
enderIoRange = config.get(
@@ -154,7 +154,8 @@ public class KeyTracker {
if (player != null) {
ItemStack travelItem = player.getHeldItem();
if (travelItem == null || travelItem.getItem() == null
|| !(travelItem.getItem() instanceof IItemOfTravel)) {
|| !(travelItem.getItem() instanceof IItemOfTravel)
|| !((IItemOfTravel) travelItem.getItem()).isActive(player, travelItem)) {
travelItem = TravelController.instance.findTravelItemInInventoryOrBaubles(player);
}
@@ -386,7 +386,15 @@ public class ItemDarkSteelSword extends ItemSword
@Override
public boolean isActive(EntityPlayer ep, ItemStack equipped) {
return isTravelUpgradeActive(ep, equipped);
if (ep != null && equipped != null && isTravelUpgradeActive(ep, equipped)) {
// Only "active" if held while sneaking. But still "active" for the purposes of travel keybind if not held
if (isEquipped(ep)) {
return ep.isSneaking();
} else {
return true;
}
}
return false;
}
@Override
@@ -400,12 +408,12 @@ public class ItemDarkSteelSword extends ItemSword
}
private boolean isTravelUpgradeActive(EntityPlayer ep, ItemStack equipped) {
return isEquipped(ep) && ep.isSneaking() && TravelUpgrade.loadFromItem(equipped) != null;
return ep != null && equipped != null && TravelUpgrade.loadFromItem(equipped) != null;
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
if (isTravelUpgradeActive(player, stack)) {
if (isActive(player, stack)) {
if (world.isRemote) {
if (TravelController.instance.activateTravelAccessable(stack, world, player, TravelSource.STAFF)) {
player.swingItem();
@@ -57,28 +57,38 @@ public class ItemTeleportStaff extends ItemTravelStaff {
@Override
public ItemStack onItemRightClick(ItemStack equipped, World world, EntityPlayer player) {
if (world.isRemote) {
int action = player.isSneaking() ? Config.teleportStaffSneakAction : Config.teleportStaffAction;
switch (action) {
case 0:
// Do nothing.
break;
case 1:
TravelController.instance.doTeleport(player);
player.swingItem();
break;
case 2:
if (Config.teleportStaffOriginalControls) {
if (player.isSneaking()) {
TravelController.instance
.activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF);
player.swingItem();
break;
} else {
TravelController.instance.doTeleport(player);
}
player.swingItem();
} else {
int action = player.isSneaking() ? Config.teleportStaffSneakAction : Config.teleportStaffAction;
switch (action) {
case 0:
// Do nothing.
break;
case 3:
TravelController.instance
.activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF, true);
player.swingItem();
break;
case 1:
TravelController.instance.doTeleport(player);
player.swingItem();
break;
case 2:
TravelController.instance
.activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF);
player.swingItem();
break;
case 3:
TravelController.instance
.activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF, true);
player.swingItem();
break;
}
}
}
return equipped;
@@ -106,6 +116,12 @@ public class ItemTeleportStaff extends ItemTravelStaff {
return power;
}
@Override
public int getEnergyStored(ItemStack item) {
// Has infinite energy, always report as being full of energy for any validation-code purposes.
return this.capacity;
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List par3List) {
@@ -163,7 +163,8 @@ public class TravelController {
case STAFF_BLINK:
if (Config.travelStaffKeybindEnabled) {
if (equippedItem == null || equippedItem.getItem() == null
|| !(equippedItem.getItem() instanceof IItemOfTravel)) {
|| !(equippedItem.getItem() instanceof IItemOfTravel)
|| !((IItemOfTravel) equippedItem.getItem()).isActive(toTp, equippedItem)) {
equippedItem = findTravelItemInInventoryOrBaubles(toTp);
}
}
@@ -199,11 +200,12 @@ public class TravelController {
public boolean activateTravelAccessable(ItemStack equipped, World world, EntityPlayer player, TravelSource source,
boolean alsoDoTeleport) {
if (!hasTarget()) {
PacketLongDistanceTravelEvent p = new PacketLongDistanceTravelEvent(player, false, source);
if (alsoDoTeleport) {
Optional<BlockCoord> destinationOptional = findTeleportDestination(player);
if (destinationOptional.isPresent()) {
BlockCoord destination = destinationOptional.get();
PacketLongDistanceTravelEvent p = new PacketLongDistanceTravelEvent(
p = new PacketLongDistanceTravelEvent(
player,
false,
source,
@@ -211,18 +213,12 @@ public class TravelController {
destination.x,
destination.y,
destination.z);
PacketHandler.INSTANCE.sendToServer(p);
// We have no way of knowing if it will succeed, so just return false.
return false;
}
}
PacketLongDistanceTravelEvent p = new PacketLongDistanceTravelEvent(player, false, source);
PacketHandler.INSTANCE.sendToServer(p);
// We have no way of knowing if it will succeed, so just return false.
return false;
}
BlockCoord target = selectedCoord;
TileEntity te = world.getTileEntity(target.x, target.y, target.z);
if (te instanceof ITravelAccessable) {
@@ -344,11 +340,111 @@ public class TravelController {
public boolean doTeleport(EntityPlayer player) {
Optional<BlockCoord> destinationOptional = findTeleportDestination(player);
if (destinationOptional.isPresent()) {
return travelToLocation(player, TravelSource.TELEPORT_STAFF_BLINK, destinationOptional.get(), false);
return travelToLocation(player, TravelSource.TELEPORT_STAFF_BLINK, destinationOptional.get(), true);
}
return false;
}
/** Finds the destination for the teleport staff super-teleport, or returns empty optional if unsuccessful. */
public Optional<BlockCoord> findTeleportDestination(EntityPlayer player) {
TravelSource source = TravelSource.TELEPORT_STAFF_BLINK;
Vector3d eye = Util.getEyePositionEio(player);
Vector3d look = Util.getLookVecEio(player);
double playerHeight = player.yOffset;
// +2 to compensate for the standard distance decrement of -2
double teleDistance = Config.teleportStaffFailedBlinkDistance + 2;
Vec3 eye3 = Vec3.createVectorHelper(eye.x, eye.y, eye.z);
// rayTraceBlocks has a limit of 200 distance.
double maxDistance = Config.teleportStaffMaxBlinkDistance;
double currDistance = 0;
Vec3 pos = eye3;
boolean loop = true;
while (loop) {
double distance = 200;
if (maxDistance - currDistance < 200) {
distance = maxDistance - currDistance;
loop = false;
}
Vector3d sample = new Vector3d(look);
sample.scale(distance);
sample.add(eye);
Vec3 end = Vec3.createVectorHelper(sample.x, sample.y, sample.z);
MovingObjectPosition p = player.worldObj
.rayTraceBlocks(pos, end, !Config.travelStaffBlinkThroughClearBlocksEnabled);
if (p != null) {
teleDistance = VecmathUtil.distance(eye, new Vector3d(p.blockX + 0.5, p.blockY + 0.5, p.blockZ + 0.5));
break;
}
pos = end;
currDistance += distance;
}
Vector3d sample = new Vector3d(look);
sample.scale(Config.teleportStaffMaxBlinkDistance);
sample.add(eye);
Vec3 end = Vec3.createVectorHelper(sample.x, sample.y, sample.z);
MovingObjectPosition p = player.worldObj
.rayTraceBlocks(eye3, end, !Config.travelStaffBlinkThroughClearBlocksEnabled);
if (p != null) {
teleDistance = VecmathUtil.distance(eye, new Vector3d(p.blockX + 0.5, p.blockY + 0.5, p.blockZ + 0.5));
}
double distanceIncrement = -2;
int maxIter = Math.min(8, (int) teleDistance / 2);
// Special case: if the targeted block is too close, we'll try to teleport through it.
if (teleDistance < 4) {
distanceIncrement = 0.5;
maxIter = 32;
}
for (int i = 0; i < maxIter; i++) {
teleDistance += distanceIncrement;
sample.set(look);
sample.scale(teleDistance);
sample.add(eye);
// we test against our feets location
sample.y -= playerHeight;
Optional<BlockCoord> destinationOptional = findNearbyDestination(player, source, sample);
if (destinationOptional.isPresent()) {
return destinationOptional;
}
}
return Optional.empty();
}
/** Finds a long-distance travel anchor, or returns empty optional if unsuccessful. */
public Optional<BlockCoord> findTravelDestination(EntityPlayer player, TravelSource source) {
double maxDistance = source.getMaxDistanceTravelled();
double maxMessageDistance = 1.25 * maxDistance;
// Find possible destinations within about 5 degrees.
RowSortedTable<Double, Double, BlockCoord> possibleDestinations = findBlocksWithinAngle(
player,
travelDestinations.get(player.worldObj.provider.dimensionId),
0.087,
maxMessageDistance);
for (Table.Cell<Double, Double, BlockCoord> cell : possibleDestinations.cellSet()) {
if (cell.getColumnKey() <= maxDistance) {
return Optional.of(cell.getValue());
}
}
if (!possibleDestinations.isEmpty()) {
// We found at least one block within maxMessageDistance, but no blocks within maxDistance.
showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.outOfRange"));
}
return Optional.empty();
}
private boolean isBlackListedBlock(EntityPlayer player, MovingObjectPosition pos, Block hitBlock) {
UniqueIdentifier ui = GameRegistry.findUniqueIdentifierFor(hitBlock);
if (ui == null) {
@@ -529,9 +625,9 @@ public class TravelController {
return getTravelItemTravelSource(ep, checkInventoryAndBaubles) != null;
}
/** Currently, we only hide travel targets for the teleport staff, in certain action modes. */
public boolean shouldHideTargets(EntityPlayer ep) {
if (getTravelItemTravelSource(ep, false) != TravelSource.TELEPORT_STAFF) {
if (getTravelItemTravelSource(ep, false) != TravelSource.TELEPORT_STAFF
|| Config.teleportStaffOriginalControls) {
return false;
}
@@ -548,7 +644,8 @@ public class TravelController {
ItemStack equipped = ep.getCurrentEquippedItem();
if (checkInventoryAndBaubles) {
if (equipped == null || !(equipped.getItem() instanceof IItemOfTravel)) {
if (equipped == null || !(equipped.getItem() instanceof IItemOfTravel)
|| !((IItemOfTravel) equipped.getItem()).isActive(ep, equipped)) {
equipped = findTravelItemInInventoryOrBaubles(ep);
}
}
@@ -577,7 +674,8 @@ public class TravelController {
ItemStack travelItem = null;
for (int i = 0; i < ep.inventory.getSizeInventory(); i++) {
ItemStack stack = ep.inventory.getStackInSlot(i);
if (stack != null && stack.getItem() instanceof IItemOfTravel) {
if (stack != null && stack.getItem() instanceof IItemOfTravel
&& ((IItemOfTravel) stack.getItem()).isActive(ep, stack)) {
travelItem = stack;
break;
}
@@ -588,7 +686,8 @@ public class TravelController {
if (baubles != null) {
for (int i = 0; i < baubles.getSizeInventory(); i++) {
ItemStack stack = baubles.getStackInSlot(i);
if (stack != null && stack.getItem() instanceof IItemOfTravel) {
if (stack != null && stack.getItem() instanceof IItemOfTravel
&& ((IItemOfTravel) stack.getItem()).isActive(ep, stack)) {
travelItem = stack;
break;
}
@@ -612,7 +711,8 @@ public class TravelController {
int travelItemSlot = -1;
for (int i = 0; i < ep.inventory.getSizeInventory(); i++) {
ItemStack stack = ep.inventory.getStackInSlot(i);
if (stack != null && (stack.getItem() instanceof IItemOfTravel)) {
if (stack != null && stack.getItem() instanceof IItemOfTravel
&& ((IItemOfTravel) stack.getItem()).isActive(ep, stack)) {
travelItemSlot = i;
break;
}
@@ -623,7 +723,8 @@ public class TravelController {
if (baubles != null) {
for (int i = 0; i < baubles.getSizeInventory(); i++) {
ItemStack stack = baubles.getStackInSlot(i);
if (stack != null && stack.getItem() instanceof IItemOfTravel) {
if (stack != null && stack.getItem() instanceof IItemOfTravel
&& ((IItemOfTravel) stack.getItem()).isActive(ep, stack)) {
travelItemSlot = -(i + 2);
break;
}
@@ -633,106 +734,6 @@ public class TravelController {
return travelItemSlot;
}
/** Finds the destination for the teleport staff super-teleport, or returns empty optional if unsuccessful. */
public Optional<BlockCoord> findTeleportDestination(EntityPlayer player) {
TravelSource source = TravelSource.TELEPORT_STAFF_BLINK;
Vector3d eye = Util.getEyePositionEio(player);
Vector3d look = Util.getLookVecEio(player);
double playerHeight = player.yOffset;
// +2 to compensate for the standard distance decrement of -2
double teleDistance = Config.teleportStaffFailedBlinkDistance + 2;
Vec3 eye3 = Vec3.createVectorHelper(eye.x, eye.y, eye.z);
// rayTraceBlocks has a limit of 200 distance.
double maxDistance = Config.teleportStaffMaxBlinkDistance;
double currDistance = 0;
Vec3 pos = eye3;
boolean loop = true;
while (loop) {
double distance = 200;
if (maxDistance - currDistance < 200) {
distance = maxDistance - currDistance;
loop = false;
}
Vector3d sample = new Vector3d(look);
sample.scale(distance);
sample.add(eye);
Vec3 end = Vec3.createVectorHelper(sample.x, sample.y, sample.z);
MovingObjectPosition p = player.worldObj
.rayTraceBlocks(pos, end, !Config.travelStaffBlinkThroughClearBlocksEnabled);
if (p != null) {
teleDistance = VecmathUtil.distance(eye, new Vector3d(p.blockX + 0.5, p.blockY + 0.5, p.blockZ + 0.5));
break;
}
pos = end;
currDistance += distance;
}
Vector3d sample = new Vector3d(look);
sample.scale(Config.teleportStaffMaxBlinkDistance);
sample.add(eye);
Vec3 end = Vec3.createVectorHelper(sample.x, sample.y, sample.z);
MovingObjectPosition p = player.worldObj
.rayTraceBlocks(eye3, end, !Config.travelStaffBlinkThroughClearBlocksEnabled);
if (p != null) {
teleDistance = VecmathUtil.distance(eye, new Vector3d(p.blockX + 0.5, p.blockY + 0.5, p.blockZ + 0.5));
}
double distanceIncrement = -2;
int maxIter = Math.min(8, (int) teleDistance / 2);
// Special case: if the targeted block is too close, we'll try to teleport through it.
if (teleDistance < 4) {
distanceIncrement = 0.5;
maxIter = 32;
}
for (int i = 0; i < maxIter; i++) {
teleDistance += distanceIncrement;
sample.set(look);
sample.scale(teleDistance);
sample.add(eye);
// we test against our feets location
sample.y -= playerHeight;
Optional<BlockCoord> destinationOptional = findNearbyDestination(player, source, sample);
if (destinationOptional.isPresent()) {
return destinationOptional;
}
}
return Optional.empty();
}
/** Finds a long-distance travel anchor, or returns empty optional if unsuccessful. */
public Optional<BlockCoord> findTravelDestination(EntityPlayer player, TravelSource source) {
double maxDistance = source.getMaxDistanceTravelled();
double maxMessageDistance = 1.25 * maxDistance;
// Find possible destinations within about 5 degrees.
RowSortedTable<Double, Double, BlockCoord> possibleDestinations = findBlocksWithinAngle(
player,
travelDestinations.get(player.worldObj.provider.dimensionId),
0.087,
maxMessageDistance);
for (Table.Cell<Double, Double, BlockCoord> cell : possibleDestinations.cellSet()) {
if (cell.getColumnKey() <= maxDistance) {
return Optional.of(cell.getValue());
}
}
if (!possibleDestinations.isEmpty()) {
// We found at least one block within maxMessageDistance, but no blocks within maxDistance.
showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.outOfRange"));
}
return Optional.empty();
}
/** Finds a valid destination near the provided vector, or returns empty optional if unsuccessful. */
private Optional<BlockCoord> findNearbyDestination(EntityPlayer player, TravelSource source, Vector3d sample) {
Optional<BlockCoord> destinationOptional = findValidDestination(
@@ -337,9 +337,6 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable
public void validate() {
super.validate();
if (isTravelSource()) {
// Note: travelDestinations is a SetMultimap, which does not allow duplicate entries.
// So it's okay if this gets called multiple times with the same BlockCoord.
// Though, I think that it's not currently getting called multiple times, anyway.
TravelController.instance.travelDestinations.put(worldObj.provider.dimensionId, getLocation());
}
}