コード例 #1
0
 @Override
 public NBTTagCompound returnNBTData(
     EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z) {
   if (tag.hasKey("Energy")) {
     tag.removeTag("Energy");
     tag.removeTag("MaxStorage");
   }
   return tag;
 }
コード例 #2
0
 @Override
 public void writeToNbt(NBTTagCompound compound) {
   super.writeToNbt(compound);
   if (this.pluginPickupSet) {
     compound.setBoolean("infinitePickupDelay", this.infinitePickupDelay);
   } else {
     compound.removeTag("infinitePickupDelay");
   }
   if (this.pluginDespawnSet) {
     compound.setBoolean("infiniteDespawnDelay", this.infiniteDespawnDelay);
   } else {
     compound.removeTag("infiniteDespawnDelay");
   }
 }
コード例 #3
0
ファイル: ContainerTFC.java プロジェクト: Miner239/TFCraft
  public static boolean areCompoundsEqual(ItemStack is1, ItemStack is2) {
    ItemStack is3 = is1.copy();
    ItemStack is4 = is2.copy();
    NBTTagCompound is3Tags = is3.getTagCompound();
    NBTTagCompound is4Tags = is4.getTagCompound();

    if (is3Tags == null) return is4Tags == null || is4Tags.hasNoTags();

    if (is4Tags == null) return is3Tags.hasNoTags();

    float temp3 = TFC_ItemHeat.getTemp(is1);
    float temp4 = TFC_ItemHeat.getTemp(is2);
    is3Tags.removeTag("temp");
    is4Tags.removeTag("temp");

    return is3Tags.equals(is4Tags) && Math.abs(temp3 - temp4) < 5;
  }
コード例 #4
0
  /* === BUILD === */
  private void onDebugBuild(NBTTagCompound nbt, EntityPlayer player, Pos pos) {
    if (pos == null) nbt.removeTag("pos");
    else if (!nbt.hasKey("pos")) nbt.setLong("pos", pos.toLong());
    else if (player.isSneaking()) {
      ItemStack is = player.inventory.mainInventory[7];
      Block block =
          is == null || !(is.getItem() instanceof ItemBlock)
              ? Blocks.air
              : ((ItemBlock) is.getItem()).field_150939_a;
      int meta = block == Blocks.air ? 0 : is.getItemDamage();

      Pos.forEachBlock(
          pos,
          Pos.at(nbt.getLong("pos")),
          blockPos -> blockPos.setBlock(player.worldObj, block, meta));
      nbt.removeTag("pos");
    } else {
      final List<Pair<Block, Integer>> blocks = new ArrayList<>();

      Arrays.stream(player.inventory.mainInventory)
          .skip(9)
          .filter(is -> is != null && is.getItem() instanceof ItemBlock)
          .forEach(
              is -> {
                Pair<Block, Integer> data =
                    Pair.of(((ItemBlock) is.getItem()).field_150939_a, is.getItemDamage());
                for (int amt = 0; amt < is.stackSize; amt++) blocks.add(data);
              });

      final int blockCount = blocks.size();
      if (blockCount == 0) return;

      Pos.forEachBlock(
          pos,
          Pos.at(nbt.getLong("pos")),
          blockPos -> {
            Pair<Block, Integer> selectedBlock =
                blocks.get(player.worldObj.rand.nextInt(blockCount));
            blockPos.setBlock(player.worldObj, selectedBlock.getLeft(), selectedBlock.getRight());
          });

      nbt.removeTag("pos");
    }
  }
コード例 #5
0
 @Override
 public boolean onItemUse(
     ItemStack stack,
     EntityPlayer player,
     World world,
     int x,
     int y,
     int z,
     int side,
     float sx,
     float sy,
     float sz) {
   TileEntity te = world.getTileEntity(x, y, z);
   NBTTagCompound tagCompound = stack.getTagCompound();
   if (tagCompound == null) {
     tagCompound = new NBTTagCompound();
   }
   if (te instanceof CounterTileEntity) {
     tagCompound.setInteger("dim", world.provider.dimensionId);
     tagCompound.setInteger("monitorx", x);
     tagCompound.setInteger("monitory", y);
     tagCompound.setInteger("monitorz", z);
     Block block = player.worldObj.getBlock(x, y, z);
     String name = "<invalid>";
     if (block != null && !block.isAir(world, x, y, z)) {
       name = BlockInfo.getReadableName(block, world.getBlockMetadata(x, y, z));
     }
     tagCompound.setString("monitorname", name);
     if (world.isRemote) {
       Logging.message(player, "Counter module is set to block '" + name + "'");
     }
   } else {
     tagCompound.removeTag("dim");
     tagCompound.removeTag("monitorx");
     tagCompound.removeTag("monitory");
     tagCompound.removeTag("monitorz");
     tagCompound.removeTag("monitorname");
     if (world.isRemote) {
       Logging.message(player, "Counter module is cleared");
     }
   }
   stack.setTagCompound(tagCompound);
   return true;
 }
コード例 #6
0
ファイル: SmartWrenchItem.java プロジェクト: vidaj/RFTools
  public static void setCurrentBlock(ItemStack itemStack, GlobalCoordinate c) {
    NBTTagCompound tagCompound = itemStack.getTagCompound();
    if (tagCompound == null) {
      tagCompound = new NBTTagCompound();
      itemStack.setTagCompound(tagCompound);
    }

    if (c == null) {
      tagCompound.removeTag("selectedX");
      tagCompound.removeTag("selectedY");
      tagCompound.removeTag("selectedZ");
      tagCompound.removeTag("selectedDim");
    } else {
      tagCompound.setInteger("selectedX", c.getCoordinate().getX());
      tagCompound.setInteger("selectedY", c.getCoordinate().getY());
      tagCompound.setInteger("selectedZ", c.getCoordinate().getZ());
      tagCompound.setInteger("selectedDim", c.getDimension());
    }
  }
コード例 #7
0
 @Override
 public void onUnequipped(ItemStack stack, EntityLivingBase player) {
   player.setInvisible(false);
   if (!((EntityPlayer) player).capabilities.isCreativeMode)
     ((EntityPlayer) player).capabilities.disableDamage = false;
   NBTTagCompound tag = new NBTTagCompound();
   ((EntityPlayer) player).writeToNBT(tag);
   tag.removeTag("ForgeData");
   ((EntityPlayer) player).readFromNBT(tag);
   player.addPotionEffect(new PotionEffect(Potion.confusion.id, 500, 2, false));
 }
コード例 #8
0
ファイル: ItemArmor.java プロジェクト: leijurv/MineBot
  /** Remove the color from the specified armor ItemStack. */
  public void removeColor(ItemStack stack) {
    if (this.material == ItemArmor.ArmorMaterial.LEATHER) {
      NBTTagCompound nbttagcompound = stack.getTagCompound();

      if (nbttagcompound != null) {
        NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");

        if (nbttagcompound1.hasKey("color")) {
          nbttagcompound1.removeTag("color");
        }
      }
    }
  }
コード例 #9
0
  /* === CLEAR === */
  private void onDebugClear(NBTTagCompound nbt, EntityPlayer player, Pos pos) {
    if (pos == null) nbt.removeTag("pos");
    else if (!nbt.hasKey("pos")) nbt.setLong("pos", pos.toLong());
    else {
      final List<Block> blocks =
          Arrays.stream(player.inventory.mainInventory)
              .filter(is -> is != null && is.getItem() instanceof ItemBlock)
              .map(is -> ((ItemBlock) is.getItem()).field_150939_a)
              .collect(Collectors.toList());

      Pos.forEachBlock(
          pos,
          Pos.at(nbt.getLong("pos")),
          blockPos -> {
            if (blocks.contains(blockPos.getBlock(player.worldObj)))
              blockPos.setAir(player.worldObj);
            else if (player.isSneaking() && blockPos.getMaterial(player.worldObj).isLiquid())
              blockPos.setAir(player.worldObj);
          });

      nbt.removeTag("pos");
    }
  }
コード例 #10
0
  public void func_135074_t() {
    if (this.stackTagCompound != null) {
      if (this.stackTagCompound.hasKey("display", 10)) {
        NBTTagCompound nbttagcompound = this.stackTagCompound.getCompoundTag("display");
        nbttagcompound.removeTag("Name");

        if (nbttagcompound.hasNoTags()) {
          this.stackTagCompound.removeTag("display");

          if (this.stackTagCompound.hasNoTags()) {
            this.setTagCompound((NBTTagCompound) null);
          }
        }
      }
    }
  }
コード例 #11
0
 @Override
 public void readFromNBT(NBTTagCompound tag) {
   super.readFromNBT(tag);
   NBTTagCompound innerTag = new NBTTagCompound();
   if (tag.hasKey(NBT_TAG_MODULE_COMPUND)) {
     innerTag = tag.getCompoundTag(NBT_TAG_MODULE_COMPUND);
     int i = 0;
     while (!innerTag.hasNoTags()) {
       modules.add(innerTag.getString(Alphabet.values()[i].toString()));
       innerTag.removeTag(Alphabet.values()[i].toString());
       i++;
     }
     this.updateBoatAI();
     super.readEntityFromNBT(tag);
   }
 }
コード例 #12
0
ファイル: PlayerStorage.java プロジェクト: synelle/Pixelmon
 private void heal(NBTTagCompound nbt) {
   nbt.setShort("Health", (short) nbt.getInteger("StatsHP"));
   nbt.setBoolean("IsFainted", false);
   int numMoves = nbt.getInteger("PixelmonNumberMoves");
   for (int i = 0; i < numMoves; i++) {
     nbt.setInteger("PixelmonMovePP" + i, nbt.getInteger("PixelmonMovePPBase" + i));
   }
   int numStatus = nbt.getShort("EffectCount");
   for (int i = 0; i < numStatus; i++) {
     nbt.removeTag("Effect" + i);
   }
   nbt.setShort("EffectCount", (short) 0);
   if (mode == PokeballManagerMode.Player)
     player.playerNetServerHandler.sendPacketToPlayer(
         new PixelmonDataPacket(nbt, EnumPackets.UpdateStorage).getPacket());
 }
コード例 #13
0
  @Override
  public ItemStack getCraftingResult(InventoryCrafting inventorycrafting) {

    ItemStack item = null;
    ItemStack icon = null;

    for (int i = 0; i < inventorycrafting.getSizeInventory(); i++) {
      ItemStack stack = inventorycrafting.getStackInSlot(i);

      if (stack != null) {
        if (stack.getItem() == BattlegearConfig.heradricItem) {
          icon = stack;
        } else if (stack.getItem() == heraldricWeapon) {
          item = stack;
        } else if (stack.getItem() == Items.water_bucket) {
          icon = stack;
        }
      }
    }
    if (item == null) return null;

    item = item.copy();

    if (heraldricWeapon instanceof IHeraldryItem) {
      byte[] code = SigilHelper.getDefault();
      if (icon.getItem() == BattlegearConfig.heradricItem) {
        code = ((IHeraldryItem) icon.getItem()).getHeraldry(icon);
      }
      ((IHeraldryItem) heraldricWeapon).setHeraldry(item, code);
    } else {

      NBTTagCompound compound = item.getTagCompound();
      if (compound == null) {
        compound = new NBTTagCompound();
      }
      if (icon.getItem() == BattlegearConfig.heradricItem) {
        byte[] code = ((IHeraldryItem) icon.getItem()).getHeraldry(icon);
        compound.setByteArray("hc2", code);
        item.setTagCompound(compound);
      } else { // should be a bucket
        if (compound.hasKey("hc2")) {
          compound.removeTag("hc2");
        }
      }
    }
    return item;
  }
コード例 #14
0
  public void renderByItem(ItemStack p_179022_1_) {
    if (p_179022_1_.getItem() == Items.banner) {
      this.banner.setItemValues(p_179022_1_);
      TileEntityRendererDispatcher.instance.renderTileEntityAt(this.banner, 0.0D, 0.0D, 0.0D, 0.0F);
    } else if (p_179022_1_.getItem() == Items.skull) {
      GameProfile gameprofile = null;

      if (p_179022_1_.hasTagCompound()) {
        NBTTagCompound nbttagcompound = p_179022_1_.getTagCompound();

        if (nbttagcompound.hasKey("SkullOwner", 10)) {
          gameprofile = NBTUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("SkullOwner"));
        } else if (nbttagcompound.hasKey("SkullOwner", 8)
            && nbttagcompound.getString("SkullOwner").length() > 0) {
          gameprofile = new GameProfile((UUID) null, nbttagcompound.getString("SkullOwner"));
          gameprofile = TileEntitySkull.updateGameprofile(gameprofile);
          nbttagcompound.removeTag("SkullOwner");
          nbttagcompound.setTag(
              "SkullOwner", NBTUtil.writeGameProfile(new NBTTagCompound(), gameprofile));
        }
      }

      if (TileEntitySkullRenderer.instance != null) {
        GlStateManager.pushMatrix();
        GlStateManager.translate(-0.5F, 0.0F, -0.5F);
        GlStateManager.scale(2.0F, 2.0F, 2.0F);
        GlStateManager.disableCull();
        TileEntitySkullRenderer.instance.renderSkull(
            0.0F, 0.0F, 0.0F, EnumFacing.UP, 0.0F, p_179022_1_.getMetadata(), gameprofile, -1);
        GlStateManager.enableCull();
        GlStateManager.popMatrix();
      }
    } else {
      Block block = Block.getBlockFromItem(p_179022_1_.getItem());

      if (block == Blocks.ender_chest) {
        TileEntityRendererDispatcher.instance.renderTileEntityAt(
            this.field_147716_d, 0.0D, 0.0D, 0.0D, 0.0F);
      } else if (block == Blocks.trapped_chest) {
        TileEntityRendererDispatcher.instance.renderTileEntityAt(
            this.field_147718_c, 0.0D, 0.0D, 0.0D, 0.0F);
      } else {
        TileEntityRendererDispatcher.instance.renderTileEntityAt(
            this.field_147717_b, 0.0D, 0.0D, 0.0D, 0.0F);
      }
    }
  }
コード例 #15
0
ファイル: HeatIndex.java プロジェクト: raymondbh/TFCraft
 public ItemStack getOutput(ItemStack in, Random R) {
   ItemStack is = getOutput(R);
   if (is != null && this.keepNBT) {
     if (is.hasTagCompound()) {
       NBTTagCompound nbt = is.getTagCompound();
       for (Object o : in.getTagCompound().func_150296_c()) {
         NBTBase n = (NBTBase) o;
         if (nbt.hasKey(n.toString())) nbt.removeTag(n.toString());
         nbt.func_150296_c().add(o);
       }
     } else {
       is.setTagCompound(in.stackTagCompound);
       if (TFC_ItemHeat.HasTemp(is)) TFC_ItemHeat.SetTemp(is, TFC_ItemHeat.GetTemp(is) * 0.9f);
     }
   }
   return is;
 }
コード例 #16
0
  public static ItemStack setContainedMagic(ItemStack output, MagicAmounts amounts) {
    if (output == null) {
      return null;
    }

    if (output.stackSize != 1) {
      return null;
    }

    if (isInfiniteContainer(output)) return output;

    if (amounts != null) {
      if (amounts.isEmpty()) {
        amounts = null;
      }
    }

    if (amounts != null) {
      output = identifyQuality(output);

      NBTTagCompound nbt = output.getTagCompound();
      if (nbt == null) {
        nbt = new NBTTagCompound();
        output.setTagCompound(nbt);
      }

      for (int i = 0; i < MagicAmounts.ELEMENTS; i++) {
        nbt.setFloat("" + i, amounts.amounts[i]);
      }

      return output;
    } else {
      NBTTagCompound nbt = output.getTagCompound();

      if (nbt != null) {
        for (int i = 0; i < MagicAmounts.ELEMENTS; i++) {
          nbt.removeTag("" + i);
        }

        if (nbt.getKeySet().size() == 0) output.setTagCompound(null);
      }

      return output;
    }
  }
コード例 #17
0
ファイル: ReikaNBTHelper.java プロジェクト: TehporP/DragonAPI
 public static void clearTagCompound(NBTTagCompound dat) {
   Collection<String> tags = new ArrayList(dat.func_150296_c());
   for (String tag : tags) {
     dat.removeTag(tag);
   }
 }
コード例 #18
0
  public static void teleportPlayerToCoords(EntityPlayerMP player, int coord, boolean isReturning) {
    // LogHelper.info("Teleporting player to: " + coord);
    NBTTagCompound playerNBT = player.getEntityData();

    // Grab the CompactMachines entry from the player NBT data
    NBTTagCompound cmNBT;
    if (playerNBT.hasKey(Reference.MOD_ID)) {
      cmNBT = playerNBT.getCompoundTag(Reference.MOD_ID);
    } else {
      cmNBT = new NBTTagCompound();
      playerNBT.setTag(Reference.MOD_ID, cmNBT);
    }

    if (player.dimension != ConfigurationHandler.dimensionId) {
      cmNBT.setInteger("oldDimension", player.dimension);
      cmNBT.setDouble("oldPosX", player.posX);
      cmNBT.setDouble("oldPosY", player.posY);
      cmNBT.setDouble("oldPosZ", player.posZ);

      int oldDimension = player.dimension;

      WorldServer machineWorld =
          MinecraftServer.getServer().worldServerForDimension(ConfigurationHandler.dimensionId);
      MinecraftServer.getServer()
          .getConfigurationManager()
          .transferPlayerToDimension(
              player, ConfigurationHandler.dimensionId, new TeleporterCM(machineWorld));

      // If this is not being called teleporting from The End ends up without
      // the client knowing about any blocks, i.e. blank screen, no blocks, but
      // server collisions etc.
      if (oldDimension == 1) {
        machineWorld.spawnEntityInWorld(player);
      }

      // Since the player is currently not in the machine dimension, we want to clear
      // his coord history - in case he exited the machine world not via a shrinking device
      // which automatically clears the last entry in the coord history.
      if (playerNBT.hasKey("coordHistory")) {
        playerNBT.removeTag("coordHistory");
      }
    }

    if (!isReturning) {
      NBTTagList coordHistory;
      if (playerNBT.hasKey("coordHistory")) {
        coordHistory = playerNBT.getTagList("coordHistory", 10);
      } else {
        coordHistory = new NBTTagList();
      }
      NBTTagCompound toAppend = new NBTTagCompound();
      toAppend.setInteger("coord", coord);

      coordHistory.appendTag(toAppend);
      playerNBT.setTag("coordHistory", coordHistory);
    }

    MachineSaveData mHandler = CompactMachines.instance.machineHandler;
    double[] destination = mHandler.getSpawnLocation(coord);

    // Check whether the spawn location is blocked
    WorldServer machineWorld =
        MinecraftServer.getServer().worldServerForDimension(ConfigurationHandler.dimensionId);
    int dstX = (int) Math.floor(destination[0]);
    int dstY = (int) Math.floor(destination[1]);
    int dstZ = (int) Math.floor(destination[2]);

    if (!machineWorld.isAirBlock(dstX, dstY, dstZ)
        || !machineWorld.isAirBlock(dstX, dstY + 1, dstZ)) {
      // If it is blocked, try to find a better position
      double[] bestSpot = findBestSpawnLocation(machineWorld, coord);
      if (bestSpot != null) {
        destination = bestSpot;
      }

      // otherwise teleport to the default location... player will probably die though.
    }

    player.setPositionAndUpdate(destination[0], destination[1], destination[2]);

    if (destination.length == 5) {
      MessagePlayerRotation packet =
          new MessagePlayerRotation((float) destination[3], (float) destination[4]);
      PacketHandler.INSTANCE.sendTo(packet, player);
    }
  }
コード例 #19
0
ファイル: CommandCompare.java プロジェクト: leijurv/MineBot
  /** Callback when the command is invoked */
  public void processCommand(ICommandSender sender, String[] args) throws CommandException {
    if (args.length < 9) {
      throw new WrongUsageException("commands.compare.usage", new Object[0]);
    } else {
      sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
      BlockPos blockpos = parseBlockPos(sender, args, 0, false);
      BlockPos blockpos1 = parseBlockPos(sender, args, 3, false);
      BlockPos blockpos2 = parseBlockPos(sender, args, 6, false);
      StructureBoundingBox structureboundingbox = new StructureBoundingBox(blockpos, blockpos1);
      StructureBoundingBox structureboundingbox1 =
          new StructureBoundingBox(blockpos2, blockpos2.add(structureboundingbox.func_175896_b()));
      int i =
          structureboundingbox.getXSize()
              * structureboundingbox.getYSize()
              * structureboundingbox.getZSize();

      if (i > 524288) {
        throw new CommandException(
            "commands.compare.tooManyBlocks",
            new Object[] {Integer.valueOf(i), Integer.valueOf(524288)});
      } else if (structureboundingbox.minY >= 0
          && structureboundingbox.maxY < 256
          && structureboundingbox1.minY >= 0
          && structureboundingbox1.maxY < 256) {
        World world = sender.getEntityWorld();

        if (world.isAreaLoaded(structureboundingbox) && world.isAreaLoaded(structureboundingbox1)) {
          boolean flag = false;

          if (args.length > 9 && args[9].equals("masked")) {
            flag = true;
          }

          i = 0;
          BlockPos blockpos3 =
              new BlockPos(
                  structureboundingbox1.minX - structureboundingbox.minX,
                  structureboundingbox1.minY - structureboundingbox.minY,
                  structureboundingbox1.minZ - structureboundingbox.minZ);
          BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
          BlockPos.MutableBlockPos blockpos$mutableblockpos1 = new BlockPos.MutableBlockPos();

          for (int j = structureboundingbox.minZ; j <= structureboundingbox.maxZ; ++j) {
            for (int k = structureboundingbox.minY; k <= structureboundingbox.maxY; ++k) {
              for (int l = structureboundingbox.minX; l <= structureboundingbox.maxX; ++l) {
                blockpos$mutableblockpos.func_181079_c(l, k, j);
                blockpos$mutableblockpos1.func_181079_c(
                    l + blockpos3.getX(), k + blockpos3.getY(), j + blockpos3.getZ());
                boolean flag1 = false;
                IBlockState iblockstate = world.getBlockState(blockpos$mutableblockpos);

                if (!flag || iblockstate.getBlock() != Blocks.air) {
                  if (iblockstate == world.getBlockState(blockpos$mutableblockpos1)) {
                    TileEntity tileentity = world.getTileEntity(blockpos$mutableblockpos);
                    TileEntity tileentity1 = world.getTileEntity(blockpos$mutableblockpos1);

                    if (tileentity != null && tileentity1 != null) {
                      NBTTagCompound nbttagcompound = new NBTTagCompound();
                      tileentity.writeToNBT(nbttagcompound);
                      nbttagcompound.removeTag("x");
                      nbttagcompound.removeTag("y");
                      nbttagcompound.removeTag("z");
                      NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                      tileentity1.writeToNBT(nbttagcompound1);
                      nbttagcompound1.removeTag("x");
                      nbttagcompound1.removeTag("y");
                      nbttagcompound1.removeTag("z");

                      if (!nbttagcompound.equals(nbttagcompound1)) {
                        flag1 = true;
                      }
                    } else if (tileentity != null) {
                      flag1 = true;
                    }
                  } else {
                    flag1 = true;
                  }

                  ++i;

                  if (flag1) {
                    throw new CommandException("commands.compare.failed", new Object[0]);
                  }
                }
              }
            }
          }

          sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, i);
          notifyOperators(
              sender, this, "commands.compare.success", new Object[] {Integer.valueOf(i)});
        } else {
          throw new CommandException("commands.compare.outOfWorld", new Object[0]);
        }
      } else {
        throw new CommandException("commands.compare.outOfWorld", new Object[0]);
      }
    }
  }
コード例 #20
0
  @Override
  public boolean onBlockActivated(
      EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
    ItemStack held = player.getCurrentEquippedItem();
    if (held != null && held.itemID == Item.redstoneRepeater.itemID) {
      if (held.stackTagCompound != null) {
        if (held.stackTagCompound.hasKey("miscperipheralsLinkX")
            && held.stackTagCompound.hasKey("miscperipheralsLinkY")
            && held.stackTagCompound.hasKey("miscperipheralsLinkZ")
            && held.stackTagCompound.hasKey("miscperipheralsLinkDim")) {
          ChunkCoordinates link =
              new ChunkCoordinates(
                  held.stackTagCompound.getInteger("miscperipheralsLinkX"),
                  held.stackTagCompound.getInteger("miscperipheralsLinkY"),
                  held.stackTagCompound.getInteger("miscperipheralsLinkZ"));
          int linkDim = held.stackTagCompound.getInteger("miscperipheralsLinkDim");

          World srcWorld = MinecraftServer.getServer().worldServerForDimension(linkDim);
          if (srcWorld == null) {
            player.sendChatToPlayer("Link failed: World is missing");
          } else {
            TileEntity te = srcWorld.getBlockTileEntity(link.posX, link.posY, link.posZ);
            if (!(te instanceof TileTeleporter)) {
              player.sendChatToPlayer("Link failed: Teleporter no longer exists");
            } else {
              TileTeleporter src = (TileTeleporter) te;

              if (link.posX == xCoord && link.posY == yCoord && link.posZ == zCoord) {
                player.sendChatToPlayer("Link canceled");
              } else {
                boolean unlinked = false;
                for (int i = 0; i < src.links.size(); i++) {
                  LinkData rlink = src.links.get(i);
                  System.out.println(
                      "comparing: "
                          + rlink.link.posX
                          + " "
                          + xCoord
                          + " "
                          + rlink.link.posY
                          + " "
                          + yCoord
                          + " "
                          + rlink.link.posZ
                          + " "
                          + zCoord);
                  if (rlink.link.posX == xCoord
                      && rlink.link.posY == yCoord
                      && rlink.link.posZ == zCoord
                      && rlink.linkDim == worldObj.provider.dimensionId) {
                    player.sendChatToPlayer(
                        "Unlinked teleporter at "
                            + rlink.linkDim
                            + ":("
                            + rlink.link.posX
                            + ","
                            + rlink.link.posY
                            + ","
                            + rlink.link.posZ
                            + ") (link "
                            + (i + 1)
                            + ") from this teleporter");
                    src.links.remove(i);
                    unlinked = true;
                    break;
                  }
                }

                if (!unlinked) {
                  src.addLink(
                      worldObj.provider.dimensionId, new ChunkCoordinates(xCoord, yCoord, zCoord));
                  player.sendChatToPlayer(
                      "Linked teleporter at "
                          + linkDim
                          + ":("
                          + link.posX
                          + ","
                          + link.posY
                          + ","
                          + link.posZ
                          + ") (link "
                          + src.links.size()
                          + ") to this teleporter");
                }
              }
            }
          }

          held.stackTagCompound.removeTag("miscperipheralsLinkX");
          held.stackTagCompound.removeTag("miscperipheralsLinkY");
          held.stackTagCompound.removeTag("miscperipheralsLinkZ");
          held.stackTagCompound.removeTag("miscperipheralsLinkDim");
          if (held.stackTagCompound.hasKey("display")) {
            NBTTagCompound display = held.stackTagCompound.getCompoundTag("display");
            display.removeTag("Lore");
            if (display.getTags().isEmpty()) {
              held.stackTagCompound.removeTag("display");
            } else {
              held.stackTagCompound.setTag("display", display);
            }
          }

          return true;
        }
      }

      if (held.stackTagCompound == null) held.stackTagCompound = new NBTTagCompound();
      held.stackTagCompound.setInteger("miscperipheralsLinkX", xCoord);
      held.stackTagCompound.setInteger("miscperipheralsLinkY", yCoord);
      held.stackTagCompound.setInteger("miscperipheralsLinkZ", zCoord);
      held.stackTagCompound.setInteger("miscperipheralsLinkDim", worldObj.provider.dimensionId);
      NBTTagCompound display = new NBTTagCompound();
      NBTTagList lore = new NBTTagList();
      lore.appendTag(new NBTTagString("", "Turtle Teleporter Link"));
      lore.appendTag(
          new NBTTagString(
              "",
              worldObj.provider.dimensionId + ":(" + xCoord + "," + yCoord + "," + zCoord + ")"));
      display.setTag("Lore", lore);
      held.stackTagCompound.setTag("display", display);

      player.sendChatToPlayer("Link started");
      return true;
    }

    return false;
  }
	@Override
	public void readFromNBT(NBTTagCompound tag)
	{
		super.readFromNBT(tag);
		_inventory = new ItemStack[getSizeInventory()];
		NBTTagList nbttaglist;
		if (tag.hasKey("Items"))
		{
			nbttaglist = tag.getTagList("Items");
			for (int i = nbttaglist.tagCount(); i --> 0; )
			{
				NBTTagCompound slot = (NBTTagCompound)nbttaglist.tagAt(i);
				int j = slot.getByte("Slot") & 0xff;
				if(j >= 0 && j < _inventory.length)
				{
					_inventory[j] = ItemStack.loadItemStackFromNBT(slot);
					if (_inventory[j].stackSize <= 0)
						_inventory[j] = null;
				}
			}
		}
		onInventoryChanged();

		if (tag.hasKey("mTanks")) {
			IFluidTank[] _tanks = getTanks();
			
			nbttaglist = tag.getTagList("mTanks");
			for(int i = 0; i < nbttaglist.tagCount(); i++)
			{
				NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i);
				int j = nbttagcompound1.getByte("Tank") & 0xff;
				if(j >= 0 && j < _tanks.length)
				{
					FluidStack l = FluidStack.loadFluidStackFromNBT(nbttagcompound1);
					if(l != null)
					{
						((FluidTank)_tanks[j]).setFluid(l);
					}
				}
			}
		}
		else if (_tanks != null)
		{ // TODO: remove in 2.8
			IFluidTank tank = _tanks[0];
			if (tank != null && tag.hasKey("tankFluidName"))
			{
				int tankAmount = tag.getInteger("tankAmount");
				FluidStack fluid = FluidRegistry.
						getFluidStack(tag.getString("tankFluidName"), tankAmount);
				if (fluid != null)
				{
					if(fluid.amount > tank.getCapacity())
					{
						fluid.amount = tank.getCapacity();
					}

					((FluidTank)tank).setFluid(fluid);
				}
				tag.removeTag("tankFluidName");
				tag.removeTag("tankAmount");
			}
		}
		
		if (tag.hasKey("display"))
		{
			NBTTagCompound display = tag.getCompoundTag("display");
			if (display.hasKey("Name"))
			{
				this.setInvName(display.getString("Name"));
			}
		}

		if (tag.hasKey("DropItems"))
		{
			List<ItemStack> drops = new ArrayList<ItemStack>();
			nbttaglist = tag.getTagList("DropItems");
			for (int i = nbttaglist.tagCount(); i --> 0; )
			{
				NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i);
				ItemStack item = ItemStack.loadItemStackFromNBT(nbttagcompound1);
				if (item != null && item.stackSize > 0)
				{
					drops.add(item);
				}
			}
			if (drops.size() != 0)
			{
				failedDrops = drops;
			}
		}
	}
コード例 #22
0
  @Override
  public NBTTagCompound getExample() {
    NBTTagCompound root = new NBTTagCompound();
    NBTTagList shapesList = new NBTTagList();

    // Sphere
    {
      NBTTagCompound shapeNbt =
          Shapes.storeShape(new Sphere(10).setHollow(true).setReplaceableOnly(true));

      NBTTagList blockDataNbt = new NBTTagList();
      {
        NBTTagCompound compound = new NBTTagCompound();
        compound.setInteger(BLOCKID_KEY, 35);
        compound.setInteger(WEIGHT_KEY, 5);
        blockDataNbt.appendTag(compound);
      }
      {
        NBTTagCompound compound = new NBTTagCompound();
        compound.setInteger(BLOCKID_KEY, 35);
        compound.setInteger(META_KEY, 5);
        blockDataNbt.appendTag(compound);
      }

      shapeNbt.setTag(BLOCKDATA_KEY, blockDataNbt);

      shapesList.appendTag(shapeNbt);
    }

    // Box
    {
      NBTTagCompound shapeNbt =
          Shapes.storeShape(new Box(new PointI(-2, -3, 5), 5, 2, 3).setReplaceableOnly(true));

      NBTTagList blockDataNbt = new NBTTagList();
      {
        NBTTagCompound compound = new NBTTagCompound();
        compound.setInteger(BLOCKID_KEY, 98);
        blockDataNbt.appendTag(compound);
      }
      {
        NBTTagCompound compound = new NBTTagCompound();
        compound.setInteger(BLOCKID_KEY, 98);
        compound.setInteger(META_KEY, 1);
        blockDataNbt.appendTag(compound);
      }
      {
        NBTTagCompound compound = new NBTTagCompound();
        compound.setInteger(BLOCKID_KEY, 98);
        compound.setInteger(META_KEY, 2);
        blockDataNbt.appendTag(compound);
      }
      {
        NBTTagCompound compound = new NBTTagCompound();
        compound.setInteger(BLOCKID_KEY, 98);
        compound.setInteger(META_KEY, 3);
        blockDataNbt.appendTag(compound);
      }
      shapeNbt.setTag(BLOCKDATA_KEY, blockDataNbt);

      shapesList.appendTag(shapeNbt);
    }

    // Cylinder
    {
      NBTTagCompound shapeNbt = Shapes.storeShape(new Cylinder(new PointI(0, 3, 0), 12));

      NBTTagList blockDataNbt = new NBTTagList();
      {
        NBTTagCompound compound = new NBTTagCompound();
        compound.setInteger(BLOCKID_KEY, 99);
        compound.setInteger(META_KEY, 14);
        blockDataNbt.appendTag(compound);
      }
      {
        NBTTagCompound compound = new NBTTagCompound();
        compound.setInteger(BLOCKID_KEY, 100);
        compound.setInteger(META_KEY, 14);
        blockDataNbt.appendTag(compound);
      }
      shapeNbt.setTag(BLOCKDATA_KEY, blockDataNbt);

      shapesList.appendTag(shapeNbt);
    }

    // Pillar
    {
      NBTTagCompound shapeNbt = Shapes.storeShape(new Pillar(new PointI(-2, 0, -6), 15));

      NBTTagList blockDataNbt = new NBTTagList();
      for (int meta = 0; meta < 16; meta++) {
        NBTTagCompound compound = new NBTTagCompound();
        compound.setInteger(BLOCKID_KEY, 159);
        compound.setInteger(META_KEY, meta);
        blockDataNbt.appendTag(compound);
      }
      shapeNbt.setTag(BLOCKDATA_KEY, blockDataNbt);

      shapesList.appendTag(shapeNbt);
    }

    // Point
    {
      NBTTagCompound shapeNbt = Shapes.storeShape(new PointI(0, 0, 0));

      NBTTagList blockDataNbt = new NBTTagList();
      {
        NBTTagCompound compound = new NBTTagCompound();
        compound.setInteger(BLOCKID_KEY, 54);

        TileEntityChest chest = new TileEntityChest();
        chest.setInventorySlotContents(13, new ItemStack(Items.golden_apple));
        NBTTagCompound chestNbt = new NBTTagCompound();
        chest.writeToNBT(chestNbt);
        compound.setTag(TEDATA_KEY, chestNbt);

        blockDataNbt.appendTag(compound);
      }
      shapeNbt.setTag(BLOCKDATA_KEY, blockDataNbt);

      shapesList.appendTag(shapeNbt);
    }

    // Point
    {
      NBTTagCompound shapeNbt = Shapes.storeShape(new PointI(-1, -2, -1));

      NBTTagList blockDataNbt = new NBTTagList();
      for (Object mob : EntityList.entityEggs.keySet()) {
        NBTTagCompound compound = new NBTTagCompound();
        compound.setInteger(BLOCKID_KEY, 52);

        TileEntityMobSpawner mobSpawner = new TileEntityMobSpawner();
        mobSpawner.func_145881_a().setEntityName(EntityList.getStringFromID((Integer) mob));
        NBTTagCompound spawnerNbt = new NBTTagCompound();
        mobSpawner.writeToNBT(spawnerNbt);

        // Removes some clutter, not really necessary though
        spawnerNbt.removeTag("x");
        spawnerNbt.removeTag("y");
        spawnerNbt.removeTag("z");

        compound.setTag(TEDATA_KEY, spawnerNbt);

        blockDataNbt.appendTag(compound);
      }
      shapeNbt.setTag(BLOCKDATA_KEY, blockDataNbt);

      shapesList.appendTag(shapeNbt);
    }

    root.setTag(SHAPES_KEY, shapesList);
    return root;
  }
コード例 #23
0
ファイル: NbtDataUtil.java プロジェクト: Kiskae/SpongeCommon
 private static void cleanseInnerCompound(NBTTagCompound compound, String innerCompound) {
   final NBTTagCompound inner = compound.getCompoundTag(innerCompound);
   if (inner.hasNoTags()) {
     compound.removeTag(innerCompound);
   }
 }