Example #1
0
  /** allows items to add custom lines of information to the mouseover description */
  @Override
  public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4) {

    if (NBTHelper.getBoolean(itemStack, "isSet")) {
      list.remove("Right Click to examine text");
      // String owner = NBTHelper.getString(itemStack, "owner");
      // String command = NBTHelper.getString(itemStack, "command");

      list.add("Owner: " + NBTHelper.getString(itemStack, "owner"));
      if (NBTHelper.getString(itemStack, "owner").equals(player.getDisplayName())) {
        list.add(EnumChatFormatting.GREEN + "Command:" + NBTHelper.getString(itemStack, "command"));
      } else {
        list.add(
            EnumChatFormatting.RED
                + "Command: "
                + EnumChatFormatting.OBFUSCATED
                + NBTHelper.getString(itemStack, "command"));
      }
    } else {
      list.add("Right Click to examine text");
    }
    /*
    String owner = itemStack.stackTagCompound.getString("owner");
    int code = itemStack.stackTagCompound.getInteger("code");
    list.add("owner: " + owner);
    if (owner.equals(player.username)) {
        list.add(EnumChatFormatting.GREEN + "code: " + code);
    } else {
        list.add(EnumChatFormatting.RED + "code: "
                + EnumChatFormatting.OBFUSCATED + code);
    }
    */

  }
Example #2
0
  public void runCommand(ItemStack itemStack, World world, EntityPlayer entityPlayer) {
    if (itemStack != null || NBTHelper.getBoolean(itemStack, "isSet")) {
      switch (NBTHelper.getInt(itemStack, "commandID")) {
        case 0: // toggleDownFall
          toggleDownfall();
          break;
        case 1: // give Random
          giveItem(entityPlayer);
          break;
        case 2: // kill Entity
          // EntityLivingBase entity = (EntityLivingBase) getEntityLookingAt(world, entityPlayer);

          break;
        case 3: // time set day
          setTime(world, entityPlayer, "day");
          break;
        case 4: // time set night
          setTime(world, entityPlayer, "night");
          break;
        default:
          LogHelper.error("Error running command in ItemCommandScroll");
          LogHelper.error("Case index out of bounds:" + NBTHelper.getInt(itemStack, "commandID"));
          break;
      }
    }
  }
Example #3
0
  @Override
  public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer entityPlayer) {
    LogHelper.info("CoolDown: " + coolDown);
    LogHelper.info("World.isRemote: " + world.isRemote);
    LogHelper.info("entityPlayer.worldObj.isRemote: " + entityPlayer.worldObj.isRemote);

    coolDown();

    if (entityPlayer.isSneaking()
        && entityPlayer.capabilities.isCreativeMode) // Change command in creative (MOVE THIS!)
    {
      NBTHelper.setInteger(itemStack, "commandID", NBTHelper.getInt(itemStack, "commandID") + 1);
      if (NBTHelper.getInt(itemStack, "commandID") > 4)
        NBTHelper.setInteger(itemStack, "commandID", 0);
    } else {
      if (!world.isRemote) {

        if (NBTHelper.getBoolean(itemStack, "isSet")) {
          LogHelper.info("Entered Function"); // DEBUG

          if (NBTHelper.getString(itemStack, "owner") == entityPlayer.getDisplayName()) {
            runCommand(itemStack, world, entityPlayer);
            ChatHelper.send(entityPlayer, "Command: " + NBTHelper.getString(itemStack, "command"));
            --itemStack.stackSize;
          } else {
            ChatHelper.send(entityPlayer, "You do not understand the symbols on the page.");
          }

        } else {
          NBTHelper.setBoolean(itemStack, "isSet", true);
          LogHelper.info("Entered Else"); // DEBUG
          ChatHelper.send(
              entityPlayer, EnumChatFormatting.BLUE + "The scroll reveals its true power!");
          NBTHelper.setBoolean(itemStack, "isSet", true);
          NBTHelper.setString(itemStack, "owner", entityPlayer.getDisplayName());
          NBTHelper.setString(itemStack, "command", getCommand(itemStack));
        }
      }
    }
    return itemStack;
  }