diff --git a/src/main/java/crazypants/enderio/config/Config.java b/src/main/java/crazypants/enderio/config/Config.java index 783eb227..a377ea0f 100644 --- a/src/main/java/crazypants/enderio/config/Config.java +++ b/src/main/java/crazypants/enderio/config/Config.java @@ -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 diff --git a/src/main/java/crazypants/enderio/config/PacketConfigSync.java b/src/main/java/crazypants/enderio/config/PacketConfigSync.java index af128f8b..9028d3d1 100644 --- a/src/main/java/crazypants/enderio/config/PacketConfigSync.java +++ b/src/main/java/crazypants/enderio/config/PacketConfigSync.java @@ -27,6 +27,7 @@ public class PacketConfigSync implements IMessage, IMessageHandler= 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; diff --git a/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java b/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java index 67ab4d34..a0d50c98 100644 --- a/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java +++ b/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java @@ -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); } } diff --git a/src/main/java/crazypants/enderio/teleport/ItemTravelStaff.java b/src/main/java/crazypants/enderio/teleport/ItemTravelStaff.java index 2312fc51..5547af0c 100644 --- a/src/main/java/crazypants/enderio/teleport/ItemTravelStaff.java +++ b/src/main/java/crazypants/enderio/teleport/ItemTravelStaff.java @@ -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); } + } diff --git a/src/main/java/crazypants/enderio/teleport/TravelController.java b/src/main/java/crazypants/enderio/teleport/TravelController.java index b2426e45..9d78104c 100644 --- a/src/main/java/crazypants/enderio/teleport/TravelController.java +++ b/src/main/java/crazypants/enderio/teleport/TravelController.java @@ -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.
+ * 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.
+ * Baubles return value is unique/hacky, if <-1 return, then do the following to calculate the baubles slot: + * "Math.abs(returnval)-2"
+ * 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)); diff --git a/src/main/java/crazypants/enderio/teleport/packet/PacketTravelEvent.java b/src/main/java/crazypants/enderio/teleport/packet/PacketTravelEvent.java index d2fdb5d2..cb31e488 100644 --- a/src/main/java/crazypants/enderio/teleport/packet/PacketTravelEvent.java +++ b/src/main/java/crazypants/enderio/teleport/packet/PacketTravelEvent.java @@ -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 { @@ -128,18 +130,35 @@ public class PacketTravelEvent implements IMessage, IMessageHandler 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); + } } } diff --git a/src/main/resources/assets/enderio/lang/en_US.lang b/src/main/resources/assets/enderio/lang/en_US.lang index f3a456c9..25cef34f 100644 --- a/src/main/resources/assets/enderio/lang/en_US.lang +++ b/src/main/resources/assets/enderio/lang/en_US.lang @@ -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