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
9 changed files with 468 additions and 203 deletions

No files matched your search

+3 -3
View File
@@ -12,10 +12,10 @@ dependencies {
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.46.05: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.14.1-GTNH:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:Chisel:2.15.0-GTNH:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:OpenComputers:1.10.11-GTNH:api') {transitive = false}
compileOnly('curse.maven:minefactory-reloaded-66672:2366150') // https://www.curseforge.com/minecraft/mc-mods/minefactory-reloaded/files/2366150
compileOnly('thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev')
@@ -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-alpha45:api') {transitive = false}
compileOnlyApi('com.github.GTNewHorizons:Angelica:1.0.0-alpha50:api') {transitive = false}
}
@@ -174,6 +174,42 @@ 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.
*
* <p>
* Values:
* <ul>
* <li><b>0:</b> Do nothing
* <li><b>1:</b> Teleport to look
* <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;
/**
* Sets the teleport staff sneak right-click action.
*
* <p>
* Values:
* <ul>
* <li><b>0:</b> Do nothing
* <li><b>1:</b> Teleport to look <em>(default)</em>
* <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;
public static int enderIoRange = 8;
public static boolean enderIoMeAccessEnabled = true;
@@ -1271,6 +1307,37 @@ 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(
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)\n"
+ "Overridden if teleportStaffOriginalControls is true.")
.getInt(teleportStaffAction);
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(
sectionEfficiency.name,
"enderIoRange",
@@ -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();
@@ -15,6 +15,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.EnderIO;
import crazypants.enderio.ModObject;
import crazypants.enderio.api.teleport.TravelSource;
import crazypants.enderio.config.Config;
import crazypants.enderio.machine.power.PowerDisplayUtil;
public class ItemTeleportStaff extends ItemTravelStaff {
@@ -56,14 +57,40 @@ public class ItemTeleportStaff extends ItemTravelStaff {
@Override
public ItemStack onItemRightClick(ItemStack equipped, World world, EntityPlayer player) {
if (world.isRemote) {
if (player.isSneaking()) {
TravelController.instance
.activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF);
if (Config.teleportStaffOriginalControls) {
if (player.isSneaking()) {
TravelController.instance
.activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF);
} else {
TravelController.instance.doTeleport(player);
}
player.swingItem();
} else {
TravelController.instance.doTeleport(player);
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:
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;
}
}
}
player.swingItem();
return equipped;
}
@@ -89,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) {
@@ -3,10 +3,8 @@ package crazypants.enderio.teleport;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import java.util.TreeMap;
import javax.annotation.Nullable;
@@ -32,6 +30,7 @@ import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.event.world.WorldEvent;
import com.enderio.core.common.util.BlockCoord;
import com.enderio.core.common.util.Util;
@@ -41,7 +40,10 @@ import com.enderio.core.common.vecmath.VecmathUtil;
import com.enderio.core.common.vecmath.Vector2d;
import com.enderio.core.common.vecmath.Vector3d;
import com.google.common.collect.MultimapBuilder;
import com.google.common.collect.RowSortedTable;
import com.google.common.collect.SetMultimap;
import com.google.common.collect.Table;
import com.google.common.collect.TreeBasedTable;
import com.gtnewhorizon.gtnhlib.GTNHLib;
import cpw.mods.fml.common.Loader;
@@ -148,8 +150,9 @@ public class TravelController {
// target must be a valid selectedCoord
// selectedCoord can either be a block right above/below when the player is on anchor...
if (on.x == x && on.z == z) return null;
// or another anchor
TileEntity maybeAnchor = target.getTileEntity(toTp.worldObj);
// or another anchor. We need to look one block below because TP goes above the anchor.
BlockCoord belowTarget = target.getLocation(ForgeDirection.DOWN);
TileEntity maybeAnchor = belowTarget.getTileEntity(toTp.worldObj);
if (!(maybeAnchor instanceof ITravelAccessable)) return "not anchor";
ITravelAccessable anchor = (ITravelAccessable) maybeAnchor;
if (!isValidTarget(toTp, target, TravelSource.BLOCK)) {
@@ -160,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);
}
}
@@ -190,8 +194,27 @@ public class TravelController {
}
public boolean activateTravelAccessable(ItemStack equipped, World world, EntityPlayer player, TravelSource source) {
return activateTravelAccessable(equipped, world, player, source, false);
}
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();
p = new PacketLongDistanceTravelEvent(
player,
false,
source,
true,
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;
@@ -243,7 +266,10 @@ public class TravelController {
sample.add(eye);
// we test against our feets location
sample.y -= playerHeight;
if (doBlinkAround(player, source, sample, true)) {
Optional<BlockCoord> destinationOptional = findNearbyDestination(player, source, sample);
if (destinationOptional.isPresent()
&& travelToLocation(player, source, destinationOptional.get(), true)) {
return true;
}
}
@@ -280,7 +306,9 @@ public class TravelController {
// we test against our feets location
sample.y -= playerHeight;
if (doBlinkAround(player, source, sample, false)) {
Optional<BlockCoord> destinationOptional = findNearbyDestination(player, source, sample);
if (destinationOptional.isPresent()
&& travelToLocation(player, source, destinationOptional.get(), false)) {
return true;
}
teleDistance++;
@@ -296,7 +324,9 @@ public class TravelController {
// we test against our feets location
sample.y -= playerHeight;
if (doBlinkAround(player, source, sample, false)) {
Optional<BlockCoord> destinationOptional = findNearbyDestination(player, source, sample);
if (destinationOptional.isPresent()
&& travelToLocation(player, source, destinationOptional.get(), false)) {
return true;
}
sampleDistance--;
@@ -308,6 +338,15 @@ public class TravelController {
/** This is the teleport staff super-teleport. */
public boolean doTeleport(EntityPlayer player) {
Optional<BlockCoord> destinationOptional = findTeleportDestination(player);
if (destinationOptional.isPresent()) {
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);
@@ -357,12 +396,14 @@ public class TravelController {
}
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 < 3) {
distanceIncrement = 2;
if (teleDistance < 4) {
distanceIncrement = 0.5;
maxIter = 32;
}
for (int i = 0; i < 8; i++) {
for (int i = 0; i < maxIter; i++) {
teleDistance += distanceIncrement;
sample.set(look);
@@ -371,49 +412,37 @@ public class TravelController {
// we test against our feets location
sample.y -= playerHeight;
if (doBlinkAround(player, source, sample, false)) {
return true;
Optional<BlockCoord> destinationOptional = findNearbyDestination(player, source, sample);
if (destinationOptional.isPresent()) {
return destinationOptional;
}
}
return false;
return Optional.empty();
}
/** Returns empty optional if no travel destination was found. */
/** Finds a long-distance travel anchor, or returns empty optional if unsuccessful. */
public Optional<BlockCoord> findTravelDestination(EntityPlayer player, TravelSource source) {
Vector3d eye = Util.getEyePositionEio(player);
Vector3d look = Util.getLookVecEio(player);
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);
// Map of distance to coordinate for eligible travel destinations (within angle).
Map<Double, BlockCoord> distanceMap = new TreeMap<>();
// Limit the max distance at which we'll display an out of range message.
// Otherwise, you could trigger the message for any travel anchor on the entire server.
double maxMessageDistance = 1.25 * source.getMaxDistanceTravelled();
boolean displayOutOfRangeMessage = false;
for (BlockCoord p : travelDestinations.get(player.worldObj.provider.dimensionId)) {
Vector3d block = new Vector3d(p.x + 0.5, p.y + 0.5, p.z + 0.5);
block.sub(eye);
double distance = block.length();
if (distance > maxMessageDistance) {
continue;
}
block.normalize();
double angle = Math.acos(look.dot(block));
// Roughly 5 degrees
if (angle < 0.087) {
if (distance > source.getMaxDistanceTravelled()) {
displayOutOfRangeMessage = true;
} else {
distanceMap.put(distance, p);
}
for (Table.Cell<Double, Double, BlockCoord> cell : possibleDestinations.cellSet()) {
if (cell.getColumnKey() <= maxDistance) {
return Optional.of(cell.getValue());
}
}
if (displayOutOfRangeMessage && distanceMap.isEmpty()) {
if (!possibleDestinations.isEmpty()) {
// We found at least one block within maxMessageDistance, but no blocks within maxDistance.
showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.outOfRange"));
}
return distanceMap.values().stream().findFirst();
return Optional.empty();
}
private boolean isBlackListedBlock(EntityPlayer player, MovingObjectPosition pos, Block hitBlock) {
@@ -426,36 +455,6 @@ public class TravelController {
|| !Config.travelStaffBlinkThroughUnbreakableBlocksEnabled);
}
private boolean doBlinkAround(EntityPlayer player, TravelSource source, Vector3d sample, boolean conserveMomentum) {
if (travelToLocation(
player,
source,
new BlockCoord((int) Math.floor(sample.x), (int) Math.floor(sample.y), (int) Math.floor(sample.z)),
conserveMomentum)) {
return true;
}
if (travelToLocation(
player,
source,
new BlockCoord((int) Math.floor(sample.x), (int) Math.floor(sample.y) + 1, (int) Math.floor(sample.z)),
conserveMomentum)) {
return true;
}
if (!Config.travelStaffSearchOptimize) {
if (travelToLocation(
player,
source,
new BlockCoord(
(int) Math.floor(sample.x),
(int) Math.floor(sample.y) - 1,
(int) Math.floor(sample.z)),
conserveMomentum)) {
return true;
}
}
return false;
}
public boolean showTargets() {
return showTargets && selectionEnabled;
}
@@ -492,6 +491,13 @@ public class TravelController {
.getBlock(selectedCoord.x, selectedCoord.y, selectedCoord.z) == EnderIO.blockEnderIo;
}
@SubscribeEvent
public void onWorldLoad(WorldEvent.Load e) {
if (!e.world.isRemote) {
travelDestinations.removeAll(e.world.provider.dimensionId);
}
}
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onRender(RenderWorldLastEvent event) {
@@ -527,7 +533,7 @@ public class TravelController {
}
onBlockCoord = getActiveTravelBlock(player);
boolean onBlock = onBlockCoord != null;
showTargets = onBlock || isTravelItemActive(player, false);
showTargets = onBlock || (isTravelItemActive(player, false) && !shouldHideTargets(player));
if (showTargets) {
updateSelectedTarget(player);
} else {
@@ -619,6 +625,16 @@ public class TravelController {
return getTravelItemTravelSource(ep, checkInventoryAndBaubles) != null;
}
public boolean shouldHideTargets(EntityPlayer ep) {
if (getTravelItemTravelSource(ep, false) != TravelSource.TELEPORT_STAFF
|| Config.teleportStaffOriginalControls) {
return false;
}
int action = ep.isSneaking() ? Config.teleportStaffSneakAction : Config.teleportStaffAction;
return action < 2;
}
/** Returns null if no travel item is in inventory/baubles. */
@Nullable
public TravelSource getTravelItemTravelSource(EntityPlayer ep, boolean checkInventoryAndBaubles) {
@@ -628,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);
}
}
@@ -657,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;
}
@@ -668,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;
}
@@ -692,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;
}
@@ -703,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;
}
@@ -713,43 +734,101 @@ public class TravelController {
return travelItemSlot;
}
/** 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(
player,
source,
new BlockCoord((int) Math.floor(sample.x), (int) Math.floor(sample.y), (int) Math.floor(sample.z)));
if (destinationOptional.isPresent()) {
return destinationOptional;
}
destinationOptional = findValidDestination(
player,
source,
new BlockCoord((int) Math.floor(sample.x), (int) Math.floor(sample.y) + 1, (int) Math.floor(sample.z)));
if (destinationOptional.isPresent()) {
return destinationOptional;
}
if (!Config.travelStaffSearchOptimize) {
destinationOptional = findValidDestination(
player,
source,
new BlockCoord(
(int) Math.floor(sample.x),
(int) Math.floor(sample.y) - 1,
(int) Math.floor(sample.z)));
if (destinationOptional.isPresent()) {
return destinationOptional;
}
}
return Optional.empty();
}
/**
* Returns the provided position if it's valid, or returns empty optional if unsuccessful.
*
* <p>
* To be precise: if the destination is a travel anchor or other block, then the returned coordinates will be one
* block higher, to place the player on top of the block.
*/
public Optional<BlockCoord> findValidDestination(EntityPlayer player, TravelSource source, BlockCoord coord) {
// Are we trying to travel to a block (anchor or telepad)?
boolean travelToBlock = source != TravelSource.STAFF_BLINK && source != TravelSource.TELEPORT_STAFF_BLINK;
BlockCoord destination = coord;
if (travelToBlock) {
TileEntity te = player.worldObj.getTileEntity(coord.x, coord.y, coord.z);
if (te instanceof ITravelAccessable) {
ITravelAccessable ta = (ITravelAccessable) te;
if (!ta.canBlockBeAccessed(player)) {
showMessage(player, new ChatComponentTranslation("enderio.gui.travelAccessable.unauthorised"));
return Optional.empty();
}
}
// We actually want to go on top of the block.
destination = coord.getLocation(ForgeDirection.UP);
}
if (!isInRangeTarget(player, destination, source.getMaxDistanceTravelledSq())) {
if (travelToBlock) {
showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.outOfRange"));
}
return Optional.empty();
}
if (!isValidTarget(player, destination, source)) {
if (travelToBlock) {
showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.invalidTarget"));
}
return Optional.empty();
}
return Optional.of(destination);
}
public boolean travelToSelectedTarget(EntityPlayer player, TravelSource source, boolean conserveMomentum) {
return travelToLocation(player, source, selectedCoord, conserveMomentum);
}
public boolean travelToLocation(EntityPlayer player, TravelSource source, BlockCoord coord,
boolean conserveMomentum) {
if (source != TravelSource.STAFF_BLINK && source != TravelSource.TELEPORT_STAFF_BLINK) {
TileEntity te = player.worldObj.getTileEntity(coord.x, coord.y, coord.z);
if (te instanceof ITravelAccessable) {
ITravelAccessable ta = (ITravelAccessable) te;
if (!ta.canBlockBeAccessed(player)) {
showMessage(player, new ChatComponentTranslation("enderio.gui.travelAccessable.unauthorised"));
return false;
}
}
Optional<BlockCoord> destinationOptional = findValidDestination(player, source, coord);
if (!destinationOptional.isPresent()) {
return false;
}
BlockCoord destination = destinationOptional.get();
int requiredPower = 0;
requiredPower = getRequiredPower(player, source, coord);
requiredPower = getRequiredPower(player, source, destination);
if (requiredPower < 0) {
return false;
}
if (!isInRangeTarget(player, coord, source.getMaxDistanceTravelledSq())) {
if (source != TravelSource.STAFF_BLINK && source != TravelSource.TELEPORT_STAFF_BLINK) {
showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.outOfRange"));
}
return false;
}
if (!isValidTarget(player, coord, source)) {
if (source != TravelSource.STAFF_BLINK && source != TravelSource.TELEPORT_STAFF_BLINK) {
showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.invalidTarget"));
}
return false;
}
if (doClientTeleport(player, coord, source, requiredPower, conserveMomentum)) {
if (doClientTeleport(player, destinationOptional.get(), source, requiredPower, conserveMomentum)) {
for (int i = 0; i < 6; ++i) {
player.worldObj.spawnParticle(
"portal",
@@ -764,6 +843,17 @@ public class TravelController {
return true;
}
public boolean isValidTarget(EntityPlayer player, BlockCoord bc, TravelSource source) {
if (bc == null) {
return false;
}
World w = player.worldObj;
BlockCoord baseLoc = bc;
return canTeleportTo(player, source, baseLoc, w)
&& canTeleportTo(player, source, baseLoc.getLocation(ForgeDirection.UP), w);
}
public int getRequiredPower(EntityPlayer player, TravelSource source, BlockCoord coord) {
if (!isTravelItemActive(player, true)) {
return 0;
@@ -808,21 +898,6 @@ public class TravelController {
return Math.sqrt(getDistanceSquared(player, coord));
}
private boolean isValidTarget(EntityPlayer player, BlockCoord bc, TravelSource source) {
if (bc == null) {
return false;
}
World w = player.worldObj;
BlockCoord baseLoc = bc;
if (source != TravelSource.STAFF_BLINK && source != TravelSource.TELEPORT_STAFF_BLINK) {
// targeting a block so go one up
baseLoc = bc.getLocation(ForgeDirection.UP);
}
return canTeleportTo(player, source, baseLoc, w)
&& canTeleportTo(player, source, baseLoc.getLocation(ForgeDirection.UP), w);
}
private boolean canTeleportTo(EntityPlayer player, TravelSource source, BlockCoord bc, World w) {
if (bc.y < 1) {
return false;
@@ -904,6 +979,7 @@ public class TravelController {
if (selectedBlock instanceof ITravelAccessable) {
ITravelAccessable travelBlock = (ITravelAccessable) selectedBlock;
BlockCoord targetBlock = new BlockCoord(currentBlock.x, y, currentBlock.z);
BlockCoord destination = targetBlock.getLocation(ForgeDirection.UP);
if (Config.travelAnchorSkipWarning) {
if (travelBlock.getRequiresPassword(player)) {
@@ -914,55 +990,67 @@ public class TravelController {
&& !travelBlock.canUiBeAccessed(player)) {
showMessage(player, new ChatComponentTranslation("enderio.gui.travelAccessable.skipPrivate"));
}
if (!isValidTarget(player, targetBlock, TravelSource.BLOCK)) {
if (!isValidTarget(player, destination, TravelSource.BLOCK)) {
showMessage(player, new ChatComponentTranslation("enderio.gui.travelAccessable.skipObstructed"));
}
}
if (travelBlock.canBlockBeAccessed(player) && isValidTarget(player, targetBlock, TravelSource.BLOCK)) {
if (travelBlock.canBlockBeAccessed(player) && isValidTarget(player, destination, TravelSource.BLOCK)) {
return targetBlock;
}
}
return null;
}
/**
* Returns a row-sorted table with angle in radians as the row, distance as the column, and block coordinate as the
* value, holding all blocks which lie within the specified viewing angle and distance.
*
* <p>
* The table is sorted by angle ascending, so the smallest angle will be first.
*
* @param player The player to search from.
* @param blocks The blocks to search through.
* @param maxAngle The maximum allowed angle, in radians.
* @param maxDistance The maximum allowed distance.
*/
private RowSortedTable<Double, Double, BlockCoord> findBlocksWithinAngle(EntityPlayer player,
Iterable<BlockCoord> blocks, double maxAngle, double maxDistance) {
Vector3d eye = Util.getEyePositionEio(player);
Vector3d look = Util.getLookVecEio(player);
// Table of angle, distance, and block coordinate holding found blocks.
// Angle is the row, so this table will automatically be sorted by angle ascending.
RowSortedTable<Double, Double, BlockCoord> foundBlocks = TreeBasedTable.create();
for (BlockCoord p : blocks) {
Vector3d block = new Vector3d(p.x + 0.5, p.y + 0.5, p.z + 0.5);
block.sub(eye);
double distance = block.length();
if (distance > maxDistance) {
continue;
}
block.normalize();
double angle = Math.acos(look.dot(block));
if (angle <= maxAngle) {
foundBlocks.put(angle, distance, p);
}
}
return foundBlocks;
}
@SideOnly(Side.CLIENT)
private void updateSelectedTarget(EntityPlayer player) {
selectedCoord = null;
if (candidates.isEmpty()) {
selectedCoord = null;
return;
}
double closestDistance = Double.MAX_VALUE;
for (BlockCoord bc : candidates.keySet()) {
if (!bc.equals(onBlockCoord)) {
double d = addRatio(bc);
if (d < closestDistance) {
selectedCoord = bc;
closestDistance = d;
}
}
}
if (selectedCoord != null) {
Vector3d blockCenter = new Vector3d(selectedCoord.x + 0.5, selectedCoord.y + 0.5, selectedCoord.z + 0.5);
Vector2d blockCenterPixel = currentView.getScreenPoint(blockCenter);
Vector2d screenMidPixel = new Vector2d(
Minecraft.getMinecraft().displayWidth,
Minecraft.getMinecraft().displayHeight);
screenMidPixel.scale(0.5);
double pixDist = blockCenterPixel.distance(screenMidPixel);
double rat = pixDist / Minecraft.getMinecraft().displayHeight;
if (rat != rat) {
rat = 0;
}
if (rat > 0.07) {
selectedCoord = null;
}
}
// Find the nearest travel anchor within roughly 10 degrees.
Optional<BlockCoord> selectedBlock = findBlocksWithinAngle(player, candidates.keySet(), 0.175, Double.MAX_VALUE)
.values().stream().findFirst();
selectedCoord = selectedBlock.orElse(null);
}
@SideOnly(Side.CLIENT)
@@ -346,10 +346,4 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable
super.invalidate();
TravelController.instance.travelDestinations.remove(worldObj.provider.dimensionId, getLocation());
}
@Override
public void onChunkUnload() {
super.onChunkUnload();
TravelController.instance.travelDestinations.remove(worldObj.provider.dimensionId, getLocation());
}
}
@@ -7,7 +7,10 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.server.S12PacketEntityVelocity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
import com.enderio.core.common.util.BlockCoord;
import com.enderio.core.common.util.Util;
@@ -18,6 +21,7 @@ import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import crazypants.enderio.Log;
import crazypants.enderio.api.teleport.IItemOfTravel;
import crazypants.enderio.api.teleport.ITravelAccessable;
import crazypants.enderio.api.teleport.TeleportEntityEvent;
import crazypants.enderio.api.teleport.TravelSource;
import crazypants.enderio.teleport.ItemTeleportStaff;
@@ -30,13 +34,27 @@ public class PacketLongDistanceTravelEvent
boolean conserveMotion;
int entityId;
int source;
// Below values are for also attempting a regular blink if the long-distance anchor check fails.
boolean alsoDoTeleport;
int tpX;
int tpY;
int tpZ;
public PacketLongDistanceTravelEvent() {}
public PacketLongDistanceTravelEvent(Entity entity, boolean conserveMotion, TravelSource source) {
this(entity, conserveMotion, source, false, 0, 0, 0);
}
public PacketLongDistanceTravelEvent(Entity entity, boolean conserveMotion, TravelSource source,
boolean alsoDoTeleport, int tpX, int tpY, int tpZ) {
this.conserveMotion = conserveMotion;
this.entityId = entity instanceof EntityPlayer ? -1 : entity.getEntityId();
this.source = source.ordinal();
this.alsoDoTeleport = alsoDoTeleport;
this.tpX = tpX;
this.tpY = tpY;
this.tpZ = tpZ;
}
@Override
@@ -44,6 +62,10 @@ public class PacketLongDistanceTravelEvent
buf.writeBoolean(conserveMotion);
buf.writeInt(entityId);
buf.writeInt(source);
buf.writeBoolean(alsoDoTeleport);
buf.writeInt(tpX);
buf.writeInt(tpY);
buf.writeInt(tpZ);
}
@Override
@@ -51,6 +73,10 @@ public class PacketLongDistanceTravelEvent
conserveMotion = buf.readBoolean();
entityId = buf.readInt();
source = buf.readInt();
alsoDoTeleport = buf.readBoolean();
tpX = buf.readInt();
tpY = buf.readInt();
tpZ = buf.readInt();
}
@Override
@@ -69,7 +95,14 @@ public class PacketLongDistanceTravelEvent
TravelSource source = TravelSource.values()[message.source];
if (!validate(toTp, source)) {
if (!validate(
toTp,
source,
message.conserveMotion,
message.alsoDoTeleport,
message.tpX,
message.tpY,
message.tpZ)) {
Log.LOGGER.warn(
Log.securityMarker,
"Player {} tried to tp without valid prereq.",
@@ -77,35 +110,82 @@ public class PacketLongDistanceTravelEvent
return null;
}
doServerTeleport(toTp, message.conserveMotion, source);
doServerTeleport(
toTp,
message.conserveMotion,
source,
message.alsoDoTeleport,
message.tpX,
message.tpY,
message.tpZ);
return null;
}
private static boolean validate(EntityPlayerMP toTp, TravelSource source) {
private static boolean validate(EntityPlayerMP toTp, TravelSource source, boolean conserveMotion,
boolean alsoDoTeleport, int tpX, int tpY, int tpZ) {
ItemStack equippedItem = toTp.getCurrentEquippedItem();
switch (source) {
case STAFF:
// Not allowed to do teleport staff teleport with regular staff.
if (alsoDoTeleport) {
return false;
}
return equippedItem != null && equippedItem.getItem() instanceof IItemOfTravel
&& ((IItemOfTravel) equippedItem.getItem()).isActive(toTp, equippedItem);
case TELEPORT_STAFF:
// tp staff is creative version of traveling staff
// no energy check or anything else needed
// but the player must actually be equipped with one of these
if (alsoDoTeleport) {
String error = TravelController.instance
.validatePacketTravelEvent(toTp, tpX, tpY, tpZ, 0, conserveMotion, source);
if (error != null) {
return false;
}
}
return equippedItem != null && equippedItem.getItem() instanceof ItemTeleportStaff;
default:
// all other types are not allowed
return false;
}
}
public static boolean doServerTeleport(Entity toTp, boolean conserveMotion, TravelSource source) {
EntityPlayer player = toTp instanceof EntityPlayer ? (EntityPlayer) toTp : null;
Optional<BlockCoord> travelDestination = TravelController.instance.findTravelDestination(player, source);
if (!travelDestination.isPresent()) {
public static boolean doServerTeleport(Entity toTp, boolean conserveMotion, TravelSource source,
boolean alsoDoTeleport, int tpX, int tpY, int tpZ) {
if (!(toTp instanceof EntityPlayer)) {
return false;
}
BlockCoord destination = travelDestination.get();
EntityPlayer player = (EntityPlayer) toTp;
Optional<BlockCoord> travelDestination = TravelController.instance.findTravelDestination(player, source);
if (!travelDestination.isPresent()) {
if (alsoDoTeleport) {
return PacketTravelEvent.doServerTeleport(toTp, tpX, tpY, tpZ, 0, conserveMotion, source);
}
return false;
}
BlockCoord targetBlock = travelDestination.get();
TileEntity te = player.worldObj.getTileEntity(targetBlock.x, targetBlock.y, targetBlock.z);
if (te instanceof ITravelAccessable) {
ITravelAccessable ta = (ITravelAccessable) te;
if (!ta.canBlockBeAccessed(player)) {
TravelController
.showMessage(player, new ChatComponentTranslation("enderio.gui.travelAccessable.unauthorised"));
return false;
}
}
// We're teleporting to a block, so go one above.
BlockCoord destination = targetBlock.getLocation(ForgeDirection.UP);
if (!TravelController.instance.isValidTarget(player, destination, source)) {
TravelController
.showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.invalidTarget"));
return false;
}
int x = destination.x;
int y = destination.y;
int z = destination.z;
@@ -113,7 +193,7 @@ public class PacketLongDistanceTravelEvent
if (powerUse < 0) {
return false;
}
if (player != null && player.getCurrentEquippedItem() != null
if (player.getCurrentEquippedItem() != null
&& player.getCurrentEquippedItem().getItem() instanceof IItemOfTravel) {
int used = ((IItemOfTravel) player.getCurrentEquippedItem().getItem())
.canExtractInternal(player.getCurrentEquippedItem(), powerUse);
@@ -134,32 +214,26 @@ public class PacketLongDistanceTravelEvent
toTp.playSound(source.sound, 1.0F, 1.0F);
if (player != null) {
player.setPositionAndUpdate(x + 0.5, y + 1.1, z + 0.5);
} else {
toTp.setPosition(x, y, z);
player.setPositionAndUpdate(x + 0.5, y + 0.1, z + 0.5);
player.worldObj.playSoundEffect(x, y, z, source.sound, 1.0F, 1.0F);
player.fallDistance = 0;
if (conserveMotion) {
Vector3d velocityVex = Util.getLookVecEio(player);
S12PacketEntityVelocity p = new S12PacketEntityVelocity(
toTp.getEntityId(),
velocityVex.x,
velocityVex.y,
velocityVex.z);
((EntityPlayerMP) player).playerNetServerHandler.sendPacket(p);
}
toTp.worldObj.playSoundEffect(x, y, z, source.sound, 1.0F, 1.0F);
toTp.fallDistance = 0;
if (player != null) {
if (conserveMotion) {
Vector3d velocityVex = Util.getLookVecEio(player);
S12PacketEntityVelocity p = new S12PacketEntityVelocity(
toTp.getEntityId(),
velocityVex.x,
velocityVex.y,
velocityVex.z);
((EntityPlayerMP) player).playerNetServerHandler.sendPacket(p);
}
if (powerUse > 0 && player.getCurrentEquippedItem() != null
&& player.getCurrentEquippedItem().getItem() instanceof IItemOfTravel) {
ItemStack item = player.getCurrentEquippedItem().copy();
((IItemOfTravel) item.getItem()).extractInternal(item, powerUse);
toTp.setCurrentItemOrArmor(0, item);
}
if (powerUse > 0 && player.getCurrentEquippedItem() != null
&& player.getCurrentEquippedItem().getItem() instanceof IItemOfTravel) {
ItemStack item = player.getCurrentEquippedItem().copy();
((IItemOfTravel) item.getItem()).extractInternal(item, powerUse);
toTp.setCurrentItemOrArmor(0, item);
}
return true;
@@ -118,7 +118,7 @@ public class PacketTravelEvent implements IMessage, IMessageHandler<PacketTravel
toTp.playSound(source.sound, 1.0F, 1.0F);
if (player != null) {
player.setPositionAndUpdate(x + 0.5, y + 1.1, z + 0.5);
player.setPositionAndUpdate(x + 0.5, y + 0.1, z + 0.5);
} else {
toTp.setPosition(x, y, z);
}