Staff Of Traveling Keybind Feature (#144)

* Staff Of Traveling Keybind Update

Two main things
1. Added a keybind for Staff of Traveling blink ability
2. Due to the new keybind, also added Baubles support for Staff of Traveling.

By extension, both features 1 and 2 also apply to the Staff of Teleportation.

* Update en_US.lang

* Add config to disable Travel Staff Keybind

Change as per request by @Caedis .
New config option is synced in the PacketConfigSync class.
A helpful info message is displayed when players attempt to use the keybind but it is disabled so it's immediately apparent why it's not working.

* Typo/formatting

Fix type, remove unnecessary null check.

* Annotations and UNIVERSAL bauble type

Added annotations missing from ItemMagnet and ItemTravelStaff for Baubles.
Added option 'UNIVERSAL' to description of magnet and travel staff Bauble type configs.
Changed default of staff to be 'UNIVERSAL', because bauble slots are limited enough as-is.
This commit is contained in:
Under authored and GitHub committed 2023-12-24 20:18:57 +01:00
1 parent 95daa9b035
commit 3639ade571
9 files changed
+246 -20

No files matched your search

@@ -154,11 +154,14 @@ public final class Config {
public static int travelStaffBlinkPauseTicks = 10;
public static boolean travelStaffEnabled = true;
public static boolean travelStaffAllowInBaublesSlot = true;
public static boolean travelStaffKeybindEnabled = true;
public static boolean travelStaffBlinkEnabled = true;
public static boolean travelStaffBlinkThroughSolidBlocksEnabled = true;
public static boolean travelStaffBlinkThroughClearBlocksEnabled = true;
public static boolean travelStaffBlinkThroughUnbreakableBlocksEnabled = false;
public static String[] travelStaffBlinkBlackList = new String[] { "minecraft:bedrock", "Thaumcraft:blockWarded" };
public static String travelStaffBaublesType = "UNIVERSAL";
public static float travelAnchorZoomScale = 0.2f;
public static boolean travelStaffSearchOptimize = true;
public static boolean validateTravelEventServerside = true;
@@ -1166,6 +1169,19 @@ public final class Config {
"travelStaffEnabled",
travelAnchorEnabled,
"If set to false: the travel staff will not be craftable.").getBoolean(travelStaffEnabled);
travelStaffAllowInBaublesSlot = config
.get(
sectionStaff.name,
"travelStaffAllowInBaublesSlot",
travelStaffAllowInBaublesSlot,
"If true the travel staff can be put into Baubles slots (requires Baubles to be installed)")
.getBoolean(travelStaffAllowInBaublesSlot);
travelStaffKeybindEnabled = config.get(
sectionStaff.name,
"travelStaffKeybindEnabled",
travelStaffKeybindEnabled,
"If set to false: the Travel Staff Blink keybind will not be useable. (keybind allows when staff is anywhere in inventory, might not be wanted)")
.getBoolean(travelStaffKeybindEnabled);
travelStaffBlinkEnabled = config
.get(
sectionStaff.name,
@@ -1199,6 +1215,13 @@ public final class Config {
sectionStaff.name,
travelStaffBlinkBlackList,
"Lists the blocks that cannot be teleported through in the form 'modID:blockName'");
travelStaffBaublesType = config.get(
sectionStaff.name,
"travelStaffBaublesType",
travelStaffBaublesType,
"The BaublesType the Travel Staff should be, 'AMULET', 'RING', 'BELT', or 'UNIVERSAL' (requires Baubles to be installed and travelStaffAllowInBaublesSlot to be on)")
.getString();
travelAnchorZoomScale = config.getFloat(
"travelAnchorZoomScale",
sectionStaff.name,
@@ -2091,7 +2114,7 @@ public final class Config {
sectionMagnet.name,
"magnetAllowDeactivatedInBaublesSlot",
magnetAllowDeactivatedInBaublesSlot,
"If true the magnet can be put into the 'amulet' Baubles slot even if switched off (requires Baubles to be installed and magnetAllowInBaublesSlot to be on)")
"If true the magnet can be put into a Baubles slot even if switched off (requires Baubles to be installed and magnetAllowInBaublesSlot to be on)")
.getBoolean(magnetAllowDeactivatedInBaublesSlot);
magnetAllowPowerExtraction = config.get(
@@ -2104,7 +2127,7 @@ public final class Config {
sectionMagnet.name,
"magnetBaublesType",
magnetBaublesType,
"The BaublesType the magnet should be, 'AMULET', 'RING' or 'BELT' (requires Baubles to be installed and magnetAllowInBaublesSlot to be on)")
"The BaublesType the magnet should be, 'AMULET', 'RING', 'BELT', or UNIVERSAL (requires Baubles to be installed and magnetAllowInBaublesSlot to be on)")
.getString();
useCombustionGenModel = config
@@ -27,6 +27,7 @@ public class PacketConfigSync implements IMessage, IMessageHandler<PacketConfigS
buf.writeInt(Config.teleportStaffFailedBlinkDistance);
buf.writeBoolean(Config.telepadLockCoords);
buf.writeBoolean(Config.telepadLockDimension);
buf.writeBoolean(Config.travelStaffKeybindEnabled);
}
@Override
@@ -46,6 +47,7 @@ public class PacketConfigSync implements IMessage, IMessageHandler<PacketConfigS
Config.teleportStaffFailedBlinkDistance = data.readInt();
Config.telepadLockCoords = data.readBoolean();
Config.telepadLockDimension = data.readBoolean();
Config.travelStaffKeybindEnabled = data.readBoolean();
}
@Override
@@ -206,6 +206,7 @@ public class ItemMagnet extends ItemEnergyContainer implements IResourceTooltipP
}
@Override
@Method(modid = "Baubles|API")
public void onWornTick(ItemStack itemstack, EntityLivingBase player) {
if (player instanceof EntityPlayer && isActive(itemstack)
&& hasPower(itemstack)
@@ -222,17 +223,21 @@ public class ItemMagnet extends ItemEnergyContainer implements IResourceTooltipP
}
@Override
@Method(modid = "Baubles|API")
public void onEquipped(ItemStack itemstack, EntityLivingBase player) {}
@Override
@Method(modid = "Baubles|API")
public void onUnequipped(ItemStack itemstack, EntityLivingBase player) {}
@Override
@Method(modid = "Baubles|API")
public boolean canEquip(ItemStack itemstack, EntityLivingBase player) {
return Config.magnetAllowInBaublesSlot && (Config.magnetAllowDeactivatedInBaublesSlot || isActive(itemstack));
}
@Override
@Method(modid = "Baubles|API")
public boolean canUnequip(ItemStack itemstack, EntityLivingBase player) {
return true;
}
@@ -8,6 +8,7 @@ import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentTranslation;
import org.lwjgl.input.Keyboard;
@@ -17,6 +18,7 @@ import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent;
import crazypants.enderio.EnderIO;
import crazypants.enderio.api.teleport.IItemOfTravel;
import crazypants.enderio.api.tool.IConduitControl;
import crazypants.enderio.conduit.ConduitDisplayMode;
import crazypants.enderio.config.Config;
@@ -30,6 +32,7 @@ import crazypants.enderio.item.darksteel.upgrade.JumpUpgrade;
import crazypants.enderio.item.darksteel.upgrade.SoundDetectorUpgrade;
import crazypants.enderio.item.darksteel.upgrade.SpeedUpgrade;
import crazypants.enderio.network.PacketHandler;
import crazypants.enderio.teleport.TravelController;
import crazypants.enderio.thaumcraft.GogglesOfRevealingUpgrade;
import crazypants.util.BaublesUtil;
@@ -55,6 +58,10 @@ public class KeyTracker {
private final KeyBinding magnetKey;
private final KeyBinding staffOfTravelingTPKey;
private static long lastBlinkTick = -1;
public KeyTracker() {
glideKey = new KeyBinding(
EnderIO.lang.localize("keybind.glidertoggle"),
@@ -106,6 +113,12 @@ public class KeyTracker {
Keyboard.KEY_NONE,
EnderIO.lang.localize("category.tools"));
ClientRegistry.registerKeyBinding(magnetKey);
staffOfTravelingTPKey = new KeyBinding(
EnderIO.lang.localize("keybind.staffoftravelingtp"),
Keyboard.KEY_NONE,
EnderIO.lang.localize("category.tools"));
ClientRegistry.registerKeyBinding(staffOfTravelingTPKey);
}
@SubscribeEvent
@@ -119,6 +132,7 @@ public class KeyTracker {
handleSpeed();
handleJump();
handleMagnet();
handleStaffOfTravelingTP();
}
private void sendEnabledChatMessage(String messageBase, boolean isActive) {
@@ -133,6 +147,37 @@ public class KeyTracker {
PacketHandler.INSTANCE.sendToServer(new PacketUpgradeState(type, isActive));
}
private void handleStaffOfTravelingTP() {
if (staffOfTravelingTPKey.isPressed()) {
if (Config.travelStaffKeybindEnabled) {
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if (player != null) {
ItemStack travelItem = player.getHeldItem();
if (travelItem == null || travelItem.getItem() == null
|| !(travelItem.getItem() instanceof IItemOfTravel)) {
travelItem = TravelController.instance.findTravelItemInInventoryOrBaubles(player);
}
if (travelItem != null && travelItem.getItem() != null) {
long ticksSinceBlink = EnderIO.proxy.getTickCount() - lastBlinkTick;
if (ticksSinceBlink < 0) {
lastBlinkTick = -1;
}
if (ticksSinceBlink >= Config.travelStaffBlinkPauseTicks) {
if (TravelController.instance.doBlink(travelItem, player)) {
lastBlinkTick = EnderIO.proxy.getTickCount();
}
}
}
}
} else {
TravelController.showMessage(
Minecraft.getMinecraft().thePlayer,
new ChatComponentTranslation("enderio.travelStaffKeybind.isDisabled"));
}
}
}
private void handleMagnet() {
if (magnetKey.isPressed()) {
EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
@@ -112,6 +112,6 @@ public class ItemTeleportStaff extends ItemTravelStaff {
@Override
public boolean isActive(EntityPlayer ep, ItemStack equipped) {
return isEquipped(ep);
return (ep != null && equipped != null);
}
}
@@ -4,6 +4,7 @@ import java.util.List;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -12,7 +13,11 @@ import net.minecraft.world.World;
import com.enderio.core.api.client.gui.IResourceTooltipProvider;
import baubles.api.BaubleType;
import baubles.api.IBauble;
import cofh.api.energy.ItemEnergyContainer;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.common.Optional.Method;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -24,7 +29,8 @@ import crazypants.enderio.api.teleport.TravelSource;
import crazypants.enderio.config.Config;
import crazypants.enderio.machine.power.PowerDisplayUtil;
public class ItemTravelStaff extends ItemEnergyContainer implements IItemOfTravel, IResourceTooltipProvider {
@Optional.Interface(iface = "baubles.api.IBauble", modid = "Baubles|API")
public class ItemTravelStaff extends ItemEnergyContainer implements IItemOfTravel, IResourceTooltipProvider, IBauble {
public static boolean isEquipped(EntityPlayer ep) {
if (ep == null || ep.getCurrentEquippedItem() == null) {
@@ -174,7 +180,7 @@ public class ItemTravelStaff extends ItemEnergyContainer implements IItemOfTrave
@Override
public boolean isActive(EntityPlayer ep, ItemStack equipped) {
return isEquipped(ep);
return (ep != null && equipped != null);
}
@Override
@@ -184,7 +190,45 @@ public class ItemTravelStaff extends ItemEnergyContainer implements IItemOfTrave
}
@Override
@Method(modid = "Baubles|API")
public BaubleType getBaubleType(ItemStack itemstack) {
BaubleType t = null;
try {
t = BaubleType.valueOf(Config.travelStaffBaublesType);
} catch (Exception e) {
// NOP
}
return t != null ? t : BaubleType.AMULET;
}
@Override
@Method(modid = "Baubles|API")
public void onWornTick(ItemStack itemstack, EntityLivingBase player) {}
@Override
@Method(modid = "Baubles|API")
public void onEquipped(ItemStack itemstack, EntityLivingBase player) {}
@Override
@Method(modid = "Baubles|API")
public void onUnequipped(ItemStack itemstack, EntityLivingBase player) {}
@Override
@Method(modid = "Baubles|API")
public boolean canEquip(ItemStack itemstack, EntityLivingBase player) {
return Config.travelStaffAllowInBaublesSlot;
}
@Override
@Method(modid = "Baubles|API")
public boolean canUnequip(ItemStack itemstack, EntityLivingBase player) {
return true;
}
@Override
@Method(modid = "Baubles|API")
public boolean showDurabilityBar(ItemStack stack) {
return Config.renderDurabilityBar && super.showDurabilityBar(stack);
}
}
@@ -16,6 +16,7 @@ import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
@@ -64,6 +65,7 @@ import crazypants.enderio.teleport.packet.PacketDrainStaff;
import crazypants.enderio.teleport.packet.PacketLongDistanceTravelEvent;
import crazypants.enderio.teleport.packet.PacketOpenAuthGui;
import crazypants.enderio.teleport.packet.PacketTravelEvent;
import crazypants.util.BaublesUtil;
public class TravelController {
@@ -156,6 +158,12 @@ public class TravelController {
return null;
case STAFF:
case STAFF_BLINK:
if (Config.travelStaffKeybindEnabled) {
if (equippedItem == null || equippedItem.getItem() == null
|| !(equippedItem.getItem() instanceof IItemOfTravel)) {
equippedItem = findTravelItemInInventoryOrBaubles(toTp);
}
}
if (equippedItem == null || !(equippedItem.getItem() instanceof IItemOfTravel)) return "not staff";
if (!((IItemOfTravel) equippedItem.getItem()).isActive(toTp, equippedItem)) return "staff not active";
int energy = ((IItemOfTravel) equippedItem.getItem()).canExtractInternal(equippedItem, powerUse);
@@ -611,25 +619,99 @@ public class TravelController {
return getTravelItemTravelSource(ep) != null;
}
/** Returns null if no travel item is equipped. */
/** Returns null if no travel item is in inventory/baubles. */
@Nullable
public TravelSource getTravelItemTravelSource(EntityPlayer ep) {
if (ep == null || ep.getCurrentEquippedItem() == null) {
if (ep == null) {
return null;
}
ItemStack equipped = ep.getCurrentEquippedItem();
if (equipped.getItem() instanceof ItemTeleportStaff) {
if (((ItemTeleportStaff) equipped.getItem()).isActive(ep, equipped)) {
return TravelSource.TELEPORT_STAFF;
}
} else if (equipped.getItem() instanceof IItemOfTravel) {
if (((IItemOfTravel) equipped.getItem()).isActive(ep, equipped)) {
return TravelSource.STAFF;
if (equipped == null || !(equipped.getItem() instanceof IItemOfTravel)) {
equipped = findTravelItemInInventoryOrBaubles(ep);
}
if (equipped != null) {
if (equipped.getItem() instanceof ItemTeleportStaff) {
if (((ItemTeleportStaff) equipped.getItem()).isActive(ep, equipped)) {
return TravelSource.TELEPORT_STAFF;
}
} else if (equipped.getItem() instanceof IItemOfTravel) {
if (((IItemOfTravel) equipped.getItem()).isActive(ep, equipped)) {
return TravelSource.STAFF;
}
}
}
return null;
}
/**
* Returns null if no Travel item found in inventory/baubles. <br>
* DO NOT CHANGE THIS CODE WITHOUT ALSO CHANGING
* TravelController.{@link #findTravelItemSlotInInventoryOrBaubles(EntityPlayer)}
*/
@Nullable
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) {
travelItem = stack;
break;
}
}
if (travelItem == null) {
IInventory baubles = BaublesUtil.instance().getBaubles(ep);
if (baubles != null) {
for (int i = 0; i < baubles.getSizeInventory(); i++) {
ItemStack stack = baubles.getStackInSlot(i);
if (stack != null && stack.getItem() instanceof IItemOfTravel) {
travelItem = stack;
break;
}
}
}
}
return travelItem;
}
/**
* Uses same code as {@link #findTravelItemInInventoryOrBaubles(EntityPlayer)}, but returns the slot of that
* item.<br>
* Baubles return value is unique/hacky, if <-1 return, then do the following to calculate the baubles slot:
* "Math.abs(returnval)-2" <br>
* Example: -3 return is Bauble slot 1, -2 return is Bauble slot 0
*
* @return -1 if no travel item found. 0 or more if item found in inventory. -2 or less if item found in Baubles.
*/
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)) {
travelItemSlot = i;
break;
}
}
if (travelItemSlot == -1) {
IInventory baubles = BaublesUtil.instance().getBaubles(ep);
if (baubles != null) {
for (int i = 0; i < baubles.getSizeInventory(); i++) {
ItemStack stack = baubles.getStackInSlot(i);
if (stack != null && stack.getItem() instanceof IItemOfTravel) {
travelItemSlot = -(i + 2);
break;
}
}
}
}
return travelItemSlot;
}
public boolean travelToSelectedTarget(EntityPlayer player, TravelSource source, boolean conserveMomentum) {
return travelToLocation(player, source, selectedCoord, conserveMomentum);
}
@@ -687,6 +769,10 @@ public class TravelController {
}
int requiredPower;
ItemStack staff = player.getCurrentEquippedItem();
if (staff == null || !(staff.getItem() instanceof IItemOfTravel)) {
staff = findTravelItemInInventoryOrBaubles(player);
}
requiredPower = getPower(player, source, coord, 0F);
int canUsePower = getEnergyInTravelItem(staff);
if (requiredPower > canUsePower) {
@@ -1013,7 +1099,7 @@ public class TravelController {
return null;
}
private static void showMessage(EntityPlayer player, IChatComponent chatComponent) {
public static void showMessage(EntityPlayer player, IChatComponent chatComponent) {
if (Loader.isModLoaded("gtnhlib")) {
if (player instanceof EntityPlayerMP) {
chatComponent.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.WHITE));
@@ -3,6 +3,7 @@ package crazypants.enderio.teleport.packet;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.server.S12PacketEntityVelocity;
import net.minecraftforge.common.MinecraftForge;
@@ -18,6 +19,7 @@ import crazypants.enderio.api.teleport.IItemOfTravel;
import crazypants.enderio.api.teleport.TeleportEntityEvent;
import crazypants.enderio.api.teleport.TravelSource;
import crazypants.enderio.teleport.TravelController;
import crazypants.util.BaublesUtil;
import io.netty.buffer.ByteBuf;
public class PacketTravelEvent implements IMessage, IMessageHandler<PacketTravelEvent, IMessage> {
@@ -128,18 +130,35 @@ public class PacketTravelEvent implements IMessage, IMessageHandler<PacketTravel
if (conserveMotion) {
Vector3d velocityVex = Util.getLookVecEio(player);
S12PacketEntityVelocity p = new S12PacketEntityVelocity(
toTp.getEntityId(),
player.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();
ItemStack travelItem = player.getCurrentEquippedItem();
int itemSlot = -1;
if (travelItem == null || travelItem.getItem() == null
|| !(travelItem.getItem() instanceof IItemOfTravel)) {
travelItem = TravelController.instance.findTravelItemInInventoryOrBaubles(player);
itemSlot = TravelController.instance.findTravelItemSlotInInventoryOrBaubles(player);
}
if (powerUse > 0 && travelItem != null && travelItem.getItem() instanceof IItemOfTravel) {
ItemStack item = travelItem.copy();
((IItemOfTravel) item.getItem()).extractInternal(item, powerUse);
toTp.setCurrentItemOrArmor(0, item);
if (itemSlot == -1) {
// Is held in players hand.
player.setCurrentItemOrArmor(0, item);
} else if (itemSlot > -1) {
// Greater than -1 is an inventory slot.
player.inventory.setInventorySlotContents(itemSlot, item);
} else if (itemSlot < -1) {
// Less than -1 is a bauble slot. Special calculation needed to determine ACTUAL Baubles slot
int baubleSlot = Math.abs(itemSlot) - 2;
IInventory baubles = BaublesUtil.instance().getBaubles(player);
baubles.setInventorySlotContents(baubleSlot, item);
}
}
}
@@ -731,6 +731,7 @@ item.itemTravelStaff.tooltip.detailed.line3=activated by R-Click
item.itemTravelStaff.tooltip.detailed.line4=Shift-R-Click will teleport the
item.itemTravelStaff.tooltip.detailed.line5=player a short distance
enderio.itemTravelStaff.notEnoughPower=Not enough power
enderio.travelStaffKeybind.isDisabled=Travel Staff Blink Keybind Disabled!
item.itemTeleportStaff.name=Staff of Teleportation
item.itemTeleportStaff.tooltip.detailed.line1=R-Click to teleport wherever you are looking
@@ -1391,6 +1392,7 @@ enderio.keybind.jump=Jump
enderio.keybind.stepassist=Step Assist
enderio.keybind.yetawrenchmode=Yeta Wrench Mode
enderio.keybind.magnet=Toggle Electromagnet
enderio.keybind.staffoftravelingtp=Travel Staff Blink
enderio.nei.alloysmelter=Alloy Smelter
enderio.nei.enchanter=Enchanter
enderio.nei.sagmill=SAG Mill