@Override
 public void addInformation(
     ItemStack itemStack, EntityPlayer player, List list, boolean p_77624_4_) {
   super.addInformation(itemStack, player, list, p_77624_4_);
   if (!NBTHelper.hasTag(itemStack, "owner")) {
     list.add("Right Click to bind deck.");
   } else {
     list.remove("Right Click to bind deck.");
     list.add(1, "Owner: " + NBTHelper.getString(itemStack, "owner"));
     list.add(
         2,
         "Cards: "
             + (itemStack.getMaxDamage() - itemStack.getItemDamage() + 1)
             + "/"
             + (itemStack.getMaxDamage() + 1));
     list.add(
         3,
         "Current Timeout: "
             + (NBTHelper.getLong(itemStack, "timeout") == 0
                 ? TIMEOUT
                 : player.worldObj.getTotalWorldTime() - NBTHelper.getLong(itemStack, "timeout"))
             + "/"
             + TIMEOUT);
   }
 }
  /** 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);
    }
    */

  }
  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;
      }
    }
  }
  @Override
  public void onUpdate(
      ItemStack itemStack, World world, Entity entity, int p_77663_4_, boolean p_77663_5_) {
    super.onUpdate(itemStack, world, entity, p_77663_4_, p_77663_5_);

    /* If the deck is on timeout */
    if (NBTHelper.getLong(itemStack, "timeout") != 0) {
      /* Using world time to count time when player is offline. */
      long timeoutDifference = world.getTotalWorldTime() - NBTHelper.getLong(itemStack, "timeout");

      /* Handle the way Minecraft handles it's time value reaching the long limit */
      if (timeoutDifference > TIMEOUT || timeoutDifference < -(TIMEOUT)) {
        NBTHelper.setLong(itemStack, "timeout", 0);
      }
    }
  }
  /** Returns true if the item can be used on the given entity, e.g. shears on sheep. */
  @Override
  public boolean itemInteractionForEntity(
      ItemStack itemStack, EntityPlayer entityPlayer, EntityLivingBase entity) {
    if (itemStack != null) {
      onItemRightClick(itemStack, entity.worldObj, entityPlayer);
      if (NBTHelper.getString(itemStack, "command") != null
          && NBTHelper.getString(itemStack, "command") == "/kill Entity") {
        if (entity != null && !entity.worldObj.isRemote) {
          ChatHelper.send(entityPlayer, "Attempting to damage entity: " + entity.toString());
          entity.attackEntityFrom(
              DamageSource.outOfWorld, Float.MAX_VALUE); // MAKE A NEW DAMAGE SOURCE
          // entity.setHealth(0.0F);
          // entity.setDead();
        }
      }
    }

    return true;
  }
  private void drawCard(ItemStack itemStack, World world, EntityPlayer player) {
    ChatHelper.send(player, NBTHelper.getString(itemStack, "cards"));
    Random rand = new Random();
    int[] cards = ArrayHelper.stringToIntArray(NBTHelper.getString(itemStack, "cards"));
    int skip = rand.nextInt(cards.length);
    String card = cards[skip] + "";

    int[] newCards = new int[cards.length - 1];
    int index = 0;
    for (int i = 0; i < cards.length; i++) {
      if (i == skip) {
        continue;
      } else {
        newCards[index] = cards[i];
        index++;
      }
    }
    NBTHelper.setString(itemStack, "cards", ArrayHelper.arrayToString(newCards));
    ChatHelper.send(player, card + "; " + NBTHelper.getString(itemStack, "cards"));
  }
  public String getCommand(ItemStack itemStack) {
    Random random = new Random();

    NBTHelper.setInteger(itemStack, "commandID", random.nextInt(5));

    switch (NBTHelper.getInt(itemStack, "commandID")) {
      case 0:
        return "/toggleDownFall";
      case 1:
        return "/give Random";
      case 2:
        return "/kill Entity";
      case 3:
        return "/time set day";
      case 4:
        return "/time set night";
      default:
        return "ERROR";
    }
  }
  @Override
  public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
    if (!world.isRemote) {

      if (NBTHelper.hasTag(itemStack, "owner") && NBTHelper.hasTag(itemStack, "timeout")) {
        /* If the timeout is 0, draw a new card. */
        if (NBTHelper.getLong(itemStack, "timeout") == 0) {
          drawCard(itemStack, world, player);
          itemStack.damageItem(1, player);
          NBTHelper.setLong(itemStack, "timeout", world.getTotalWorldTime());
        } else {
          ChatHelper.send(player, "Timeout time: " + NBTHelper.getLong(itemStack, "timeout"));
          ChatHelper.send(player, "World time: " + world.getTotalWorldTime());
        }
      } else {
        /* Initialize NBT values */
        NBTHelper.setLong(itemStack, "timeout", 0);
        NBTHelper.setString(itemStack, "owner", player.getDisplayName());
        makeDeck(itemStack);
      }
    }
    return super.onItemRightClick(itemStack, world, player);
  }
 private void makeDeck(ItemStack itemStack) {
   String cards = "[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]";
   NBTHelper.setString(itemStack, "cards", cards);
 }
Beispiel #10
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;
  }