private Entity getEntityLookingAt(World world, EntityPlayer player) { ChatHelper.send(player, "Getting entity looking at."); MovingObjectPosition mop = Minecraft.getMinecraft().objectMouseOver; if (mop != null && mop.entityHit instanceof EntityLivingBase) { return mop.entityHit; } return null; }
@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; }
/** 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; }