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