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