Skip to content

Commit

Permalink
Staff Of Traveling Keybind Feature (#144)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
TheUnderTaker11 authored Dec 24, 2023
1 parent 95daa9b commit 3639ade
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 20 deletions.
27 changes: 25 additions & 2 deletions src/main/java/crazypants/enderio/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,14 @@ public String lc() {
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;
Expand Down Expand Up @@ -1166,6 +1169,19 @@ public static void processConfig(Configuration 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,
Expand Down Expand Up @@ -1199,6 +1215,13 @@ public static void processConfig(Configuration 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,
Expand Down Expand Up @@ -2091,7 +2114,7 @@ public static void processConfig(Configuration 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(
Expand All @@ -2104,7 +2127,7 @@ public static void processConfig(Configuration 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
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/crazypants/enderio/config/PacketConfigSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void toBytes(ByteBuf buf) {
buf.writeInt(Config.teleportStaffFailedBlinkDistance);
buf.writeBoolean(Config.telepadLockCoords);
buf.writeBoolean(Config.telepadLockDimension);
buf.writeBoolean(Config.travelStaffKeybindEnabled);
}

@Override
Expand All @@ -46,6 +47,7 @@ public void fromBytes(ByteBuf data) {
Config.teleportStaffFailedBlinkDistance = data.readInt();
Config.telepadLockCoords = data.readBoolean();
Config.telepadLockDimension = data.readBoolean();
Config.travelStaffKeybindEnabled = data.readBoolean();
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/crazypants/enderio/item/ItemMagnet.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public BaubleType getBaubleType(ItemStack itemstack) {
}

@Override
@Method(modid = "Baubles|API")
public void onWornTick(ItemStack itemstack, EntityLivingBase player) {
if (player instanceof EntityPlayer && isActive(itemstack)
&& hasPower(itemstack)
Expand All @@ -222,17 +223,21 @@ && hasPower(itemstack)
}

@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;
}
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/crazypants/enderio/item/KeyTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;

Expand All @@ -17,6 +18,7 @@
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;
Expand All @@ -30,6 +32,7 @@
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;

Expand All @@ -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"),
Expand Down Expand Up @@ -106,6 +113,12 @@ public 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
Expand All @@ -119,6 +132,7 @@ public void onKeyInput(KeyInputEvent event) {
handleSpeed();
handleJump();
handleMagnet();
handleStaffOfTravelingTP();
}

private void sendEnabledChatMessage(String messageBase, boolean isActive) {
Expand All @@ -133,6 +147,37 @@ private void toggleDarkSteelController(Type type, String messageBase) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ public String getUnlocalizedNameForTooltip(ItemStack stack) {

@Override
public boolean isActive(EntityPlayer ep, ItemStack equipped) {
return isEquipped(ep);
return (ep != null && equipped != null);
}
}
48 changes: 46 additions & 2 deletions src/main/java/crazypants/enderio/teleport/ItemTravelStaff.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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;
Expand All @@ -12,7 +13,11 @@

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;
Expand All @@ -24,7 +29,8 @@
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) {
Expand Down Expand Up @@ -174,7 +180,7 @@ public String getUnlocalizedNameForTooltip(ItemStack stack) {

@Override
public boolean isActive(EntityPlayer ep, ItemStack equipped) {
return isEquipped(ep);
return (ep != null && equipped != null);
}

@Override
Expand All @@ -184,7 +190,45 @@ public boolean isFull3D() {
}

@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);
}

}
Loading

0 comments on commit 3639ade

Please sign in to comment.