Пример #1
0
 /** Called upon block activation (right click on the block.) */
 @Override
 public boolean onBlockActivated(
     World world,
     int x,
     int y,
     int z,
     EntityPlayer player,
     int side,
     float hitX,
     float hitY,
     float hitZ) {
   if (!world.isRemote) {
     if (player.isSneaking()) {
       player.openGui(FullPower.instance, GuiHandler.GuiIDs.CAMO_MINE.ordinal(), world, x, y, z);
     }
     TileEntityCamoMine te = (TileEntityCamoMine) world.getTileEntity(x, y, z);
     if (te.getCamouflage(side) != null) {
       ItemStack camoStack = te.getCamouflage(side);
       te.setCamouflage(null, side);
       EntityItem itemEntity = new EntityItem(world, x, y, z, camoStack);
       LogHelper.info("StackSize=" + camoStack.stackSize);
       // Tell world this item needs to be spawned
       world.spawnEntityInWorld(itemEntity);
     } else {
       ItemStack playerItem = player.getCurrentEquippedItem();
       if (playerItem != null) {
         ItemStack camoStack = playerItem.splitStack(1); // Remove 1 from stack
         ChatHelper.send(camoStack.toString());
         te.setCamouflage(camoStack, side);
       }
     }
   }
   return true;
 }
Пример #2
0
 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;
 }
Пример #3
0
  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"));
  }
Пример #4
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;
  }
Пример #5
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);
  }
Пример #6
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;
  }
Пример #7
0
 public void sendMessage() {
   ChatHelper.send("<" + name + "> " + message);
 }