Beispiel #1
0
 public void load(T state, CompoundTag compound) {
   String checkId = ((StringTag) compound.getValue().get("id")).getValue();
   if (!id.equalsIgnoreCase(checkId)) {
     throw new IllegalArgumentException(
         "Invalid ID loading tile entity, expected " + id + " got " + checkId);
   }
   int checkX = ((IntTag) compound.getValue().get("x")).getValue(), x = state.getX();
   int checkY = ((IntTag) compound.getValue().get("y")).getValue(), y = state.getY();
   int checkZ = ((IntTag) compound.getValue().get("z")).getValue(), z = state.getZ();
   if (x != checkX || y != checkY || z != checkZ) {
     throw new IllegalArgumentException(
         "Invalid coords loading tile entity, expected ("
             + x
             + ","
             + y
             + ","
             + z
             + ") got ("
             + checkX
             + ","
             + checkY
             + ","
             + checkZ
             + ")");
   }
 }
 @Override
 public void loadNbt(CompoundTag tag) {
   super.loadNbt(tag);
   if (tag.isInt("BrewTime")) {
     brewTime = tag.getInt("BrewTime");
   }
 }
 public static CompoundTag getTag() {
   CompoundTag tag = new CompoundTag();
   tag.putInt("int", 5);
   tag.putString("string", "text");
   tag.putList("list", TagType.FLOAT, Arrays.asList(1.f, 2.f, 3.f));
   tag.putCompound("compound", new CompoundTag());
   return tag;
 }
 public static BannerPattern fromNBT(List<CompoundTag> tag) {
   BannerPattern.Builder builder = BannerPattern.builder();
   for (CompoundTag layer : tag) {
     BannerPattern.LayerTexture type =
         BannerPattern.LayerTexture.getByCode(layer.getString("Pattern"));
     DyeColor color = DyeColor.getByDyeData((byte) layer.getInt("Color"));
     builder.layer(type, color);
   }
   return builder.build();
 }
 public static List<CompoundTag> toNBT(BannerPattern pattern) {
   List<CompoundTag> patterns = new ArrayList<>();
   for (BannerPattern.BannerLayer layer : pattern.getLayers()) {
     CompoundTag layerTag = new CompoundTag();
     layerTag.putString("Pattern", layer.getTexture().getCode());
     layerTag.putInt("Color", layer.getColor().getDyeData());
     patterns.add(layerTag);
   }
   return patterns;
 }
Beispiel #6
0
 public ItemStack readItemStack(CompoundTag compound) {
   ItemStack stack = null;
   Tag idTag = compound.getValue().get("id");
   Tag damageTag = compound.getValue().get("Damage");
   Tag countTag = compound.getValue().get("Count");
   short id = (idTag == null) ? 0 : ((ShortTag) idTag).getValue();
   short damage = (damageTag == null) ? 0 : ((ShortTag) damageTag).getValue();
   byte count = (countTag == null) ? 0 : ((ByteTag) countTag).getValue();
   if (id != 0 && count != 0) {
     stack = new ItemStack(id, count, damage);
   }
   return stack;
 }
Beispiel #7
0
 @Override
 public void load(GlowItem entity, CompoundTag compound) {
   if (compound.getValue().containsKey("Item")) {
     ItemStack stack = readItemStack((CompoundTag) compound.getValue().get("Item"));
     entity.setItemStack(stack);
   }
   if (compound.getValue().containsKey("Health")) {
     // item.setHealth(((IntTag)compound.getValue().get("Health")).getValue());
   }
   if (compound.getValue().containsKey("Age")) {
     // item.setAge(((IntTag)compound.getValue().get("Age")).getValue());
   }
 }
 /**
  * Save information about this structure piece to the given tag.
  *
  * @param structurePiece The structure piece to save.
  * @param compound The target tag.
  */
 public void save(T structurePiece, CompoundTag compound) {
   compound.putInt("GD", structurePiece.getGD());
   compound.putInt("O", structurePiece.getNumericOrientation());
   StructureBoundingBox boundingBox = structurePiece.getBoundingBox();
   int[] bb = new int[6];
   bb[0] = boundingBox.getMin().getBlockX();
   bb[1] = boundingBox.getMin().getBlockY();
   bb[2] = boundingBox.getMin().getBlockZ();
   bb[3] = boundingBox.getMax().getBlockX();
   bb[4] = boundingBox.getMax().getBlockY();
   bb[5] = boundingBox.getMax().getBlockZ();
   compound.putIntArray("BB", bb);
 }
Beispiel #9
0
 @Override
 public GlowItem load(GlowServer server, GlowWorld world, CompoundTag compound) {
   ItemStack stack = null;
   if (compound.getValue().containsKey("Item")) {
     stack = readItemStack((CompoundTag) compound.getValue().get("Item"));
   }
   GlowItem item = new GlowItem(server, world, stack);
   if (compound.getValue().containsKey("Health")) {
     // item.setHealth(((IntTag)compound.getValue().get("Health")).getValue());
   }
   if (compound.getValue().containsKey("Age")) {
     // item.setAge(((IntTag)compound.getValue().get("Age")).getValue());
   }
   return item;
 }
  public void readPlayerData(GlowPlayer player) {
    Map<String, Tag> playerData = new HashMap<String, Tag>();
    CompoundTag playerTag = null;
    // Map<PlayerData, Object> ret = new HashMap<PlayerData, Object>();

    File playerDir = new File(world.getName(), "players");
    if (!playerDir.exists()) playerDir.mkdirs();

    File playerFile = new File(playerDir, player.getName() + ".dat");
    if (!playerFile.exists()) {
      try {
        playerFile.createNewFile();
      } catch (IOException e) {
        e.printStackTrace();
      }
    } else {
      try {
        NBTInputStream in = new NBTInputStream(new FileInputStream(playerFile));
        playerTag = (CompoundTag) in.readTag();
        in.close();
        if (playerTag != null) playerData.putAll(playerTag.getValue());
      } catch (EOFException e) {
      } catch (IOException e) {
        player.kickPlayer("Failed to read " + player.getName() + ".dat!");
        server
            .getLogger()
            .severe(
                "Failed to read player.dat for player "
                    + player.getName()
                    + " in world "
                    + world.getName()
                    + "!");
        e.printStackTrace();
      }
    }

    if (playerTag == null) playerTag = new CompoundTag("", new HashMap<String, Tag>());
    EntityStoreLookupService.find(GlowPlayer.class).load(player, playerTag);
  }
 /**
  * Load structure piece data of the appropriate type from the given compound tag.
  *
  * @param structurePiece The target structure piece.
  * @param compound The structure piece's tag.
  */
 public void load(T structurePiece, CompoundTag compound) {
   if (compound.isInt("GD")) {
     structurePiece.setGD(compound.getInt("GD"));
   }
   if (compound.isInt("O")) {
     structurePiece.setNumericOrientation(compound.getInt("O"));
   }
   if (compound.isIntArray("BB")) {
     int[] bb = compound.getIntArray("BB");
     if (bb.length == 6) {
       final StructureBoundingBox boundingBox =
           new StructureBoundingBox(
               new Vector(bb[0], bb[1], bb[2]), new Vector(bb[3], bb[4], bb[5]));
       structurePiece.setBoundingBox(boundingBox);
     }
   }
 }
  public WorldFinalValues readWorldData() throws IOException {
    Map<String, Tag> level = new HashMap<String, Tag>();

    File levelFile = new File(dir, "level.dat");
    if (!levelFile.exists()) {
      try {
        levelFile.createNewFile();
      } catch (IOException e) {
        handleWorldException("level.dat", e);
      }
    } else {
      try {
        NBTInputStream in = new NBTInputStream(new FileInputStream(levelFile));
        CompoundTag levelTag = (CompoundTag) in.readTag();
        in.close();
        if (levelTag != null) level.putAll(levelTag.getValue());
      } catch (EOFException e) {
      } catch (IOException e) {
        handleWorldException("level.dat", e);
      }
    }
    UUID uid = null;
    File uuidFile = new File(dir, "uid.dat");
    if (!uuidFile.exists()) {
      try {
        uuidFile.createNewFile();
      } catch (IOException e) {
        handleWorldException("uid.dat", e);
      }
    } else {
      DataInputStream str = null;
      try {
        str = new DataInputStream(new FileInputStream(uuidFile));
        uid = new UUID(str.readLong(), str.readLong());
      } catch (EOFException e) {
      } finally {
        if (str != null) {
          str.close();
        }
      }
    }
    long seed = 0L;
    if (level.containsKey("thundering")) {
      ByteTag thunderTag = (ByteTag) level.remove("thundering");
      world.setThundering(thunderTag.getValue() == 1);
    }
    if (level.containsKey("raining")) {
      ByteTag rainTag = (ByteTag) level.remove("raining");
      world.setStorm(rainTag.getValue() == 1);
    }
    if (level.containsKey("thunderTime")) {
      IntTag thunderTimeTag = (IntTag) level.remove("thunderTime");
      world.setThunderDuration(thunderTimeTag.getValue());
    }
    if (level.containsKey("rainTime")) {
      IntTag rainTimeTag = (IntTag) level.remove("rainTime");
      world.setWeatherDuration(rainTimeTag.getValue());
    }
    if (level.containsKey("RandomSeed")) {
      LongTag seedTag = (LongTag) level.remove("RandomSeed");
      seed = seedTag.getValue();
    }
    if (level.containsKey("Time")) {
      LongTag timeTag = (LongTag) level.remove("Time");
      world.setTime(timeTag.getValue());
    }
    if (level.containsKey("SpawnX") && level.containsKey("SpawnY") && level.containsKey("SpawnZ")) {
      IntTag spawnXTag = (IntTag) level.remove("SpawnX");
      IntTag spawnYTag = (IntTag) level.remove("SpawnY");
      IntTag spawnZTag = (IntTag) level.remove("SpawnZ");
      world.setSpawnLocation(spawnXTag.getValue(), spawnYTag.getValue(), spawnZTag.getValue());
    }
    unknownTags.putAll(level);
    if (uid == null) uid = UUID.randomUUID();
    return new WorldFinalValues(seed, uid);
  }
 public CompoundTag writeNbt(ItemMeta meta) {
   CompoundTag result = new CompoundTag();
   toGlowMeta(meta).writeNbt(result);
   return result.isEmpty() ? null : result;
 }
 @Override
 public void saveNbt(CompoundTag tag) {
   super.saveNbt(tag);
   tag.putInt("BrewTime", brewTime);
 }