Esempio n. 1
0
  @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);
  }
Esempio n. 2
0
  @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);
      }
    }
  }