コード例 #1
0
  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;
      }
    }
  }
コード例 #2
0
ファイル: BlockCamoMine.java プロジェクト: tayjay/FullPower
 /** 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;
 }
コード例 #3
0
 public void onGuiTextfieldUpdate(int id, String text) {
   if (id == 0) {
     name = text;
     markDirty();
   } else if (id == 1) {
     message = text;
     markDirty();
   } else {
     LogHelper.error("Invalid TextField id in TileEntityChatBox: " + id);
   }
 }
コード例 #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
 private void setTime(World world, EntityPlayer entityPlayer, String timeStr) {
   long time;
   if (timeStr == "day") {
     time = 1000;
   } else if (timeStr == "night") {
     time = 13000;
   } else {
     time = 0;
     LogHelper.error("Improper setTime call in ItemCommandScroll");
   }
   for (int j = 0; j < MinecraftServer.getServer().worldServers.length; ++j) {
     MinecraftServer.getServer().worldServers[j].setWorldTime(time);
   }
 }