Skip to content

Commit

Permalink
Travel Staff Blink Keybind fixes. (#163)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheUnderTaker11 authored Jul 15, 2024
1 parent e39a1e1 commit 6c20515
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/main/java/crazypants/enderio/item/KeyTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ private void handleStaffOfTravelingTP() {
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,15 @@ public ItemStack createItemStack() {

@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
Expand All @@ -400,12 +408,12 @@ public int canExtractInternal(ItemStack equipped, int power) {
}

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ public int canExtractInternal(ItemStack equipped, int power) {
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) {
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/crazypants/enderio/teleport/TravelController.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ public String validatePacketTravelEvent(EntityPlayerMP toTp, int x, int y, int z
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);
}
}
Expand Down Expand Up @@ -547,7 +548,8 @@ public TravelSource getTravelItemTravelSource(EntityPlayer ep, boolean checkInve

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);
}
}
Expand Down Expand Up @@ -576,7 +578,8 @@ public ItemStack findTravelItemInInventoryOrBaubles(EntityPlayer ep) {
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;
}
Expand All @@ -587,7 +590,8 @@ public ItemStack findTravelItemInInventoryOrBaubles(EntityPlayer ep) {
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;
}
Expand All @@ -611,7 +615,8 @@ public int findTravelItemSlotInInventoryOrBaubles(EntityPlayer ep) {
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;
}
Expand All @@ -622,7 +627,8 @@ public int findTravelItemSlotInInventoryOrBaubles(EntityPlayer ep) {
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;
}
Expand Down

0 comments on commit 6c20515

Please sign in to comment.