Search in sources :

Example 6 with CompoundTag

use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.

the class GlowMetaFirework method readNbt.

@Override
void readNbt(CompoundTag tag) {
    CompoundTag firework = tag.getCompound("Fireworks");
    power = firework.getByte("Flight");
    List<CompoundTag> explosions = firework.getCompoundList("Explosions");
    effects.addAll(explosions.stream().map(GlowMetaFireworkEffect::toEffect).collect(Collectors.toList()));
}
Also used : CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 7 with CompoundTag

use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.

the class GlowMetaFirework method writeNbt.

@Override
void writeNbt(CompoundTag tag) {
    CompoundTag firework = new CompoundTag();
    tag.putCompound("Fireworks", firework);
    firework.putByte("Flight", power);
    List<CompoundTag> explosions = new ArrayList<>();
    if (hasEffects()) {
        explosions.addAll(effects.stream().map(GlowMetaFireworkEffect::toExplosion).collect(Collectors.toList()));
    }
    firework.putCompoundList("Explosions", explosions);
}
Also used : ArrayList(java.util.ArrayList) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 8 with CompoundTag

use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.

the class NbtScoreboardIoWriter method writeObjectives.

private static void writeObjectives(CompoundTag root, GlowScoreboard scoreboard) {
    List<CompoundTag> objectives = new ArrayList<>();
    for (Objective objective : scoreboard.getObjectives()) {
        CompoundTag objectiveNbt = new CompoundTag();
        objectiveNbt.putString("CriteriaName", objective.getCriteria());
        objectiveNbt.putString("DisplayName", objective.getDisplayName());
        objectiveNbt.putString("Name", objective.getName());
        objectiveNbt.putString("RenderType", objective.getType().name());
        objectives.add(objectiveNbt);
    }
    root.putCompoundList("Objectives", objectives);
}
Also used : Objective(org.bukkit.scoreboard.Objective) ArrayList(java.util.ArrayList) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 9 with CompoundTag

use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.

the class NbtScoreboardIoWriter method writeMainScoreboard.

public static void writeMainScoreboard(File path, GlowScoreboard scoreboard) throws IOException {
    CompoundTag root = new CompoundTag();
    CompoundTag data = new CompoundTag();
    root.putCompound("data", data);
    try (NBTOutputStream nbt = new NBTOutputStream(getDataOutputStream(path), true)) {
        writeObjectives(data, scoreboard);
        writeScores(data, scoreboard);
        writeTeams(data, scoreboard);
        writeDisplaySlots(data, scoreboard);
        nbt.writeTag(root);
        nbt.close();
    }
}
Also used : NBTOutputStream(net.glowstone.util.nbt.NBTOutputStream) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 10 with CompoundTag

use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.

the class ItemSpawn method rightClickBlock.

@Override
public void rightClickBlock(GlowPlayer player, GlowBlock against, BlockFace face, ItemStack holding, Vector clickedLoc) {
    Location location = against.getLocation().add(face.getModX(), face.getModY(), face.getModZ());
    // TODO: change mob spawner when clicked by monster egg
    if (holding.hasItemMeta() && holding.getItemMeta() instanceof GlowMetaSpawn) {
        GlowMetaSpawn meta = (GlowMetaSpawn) holding.getItemMeta();
        EntityType type = meta.getSpawnedType();
        CompoundTag tag = meta.getEntityTag();
        if (type != null) {
            GlowEntity entity = against.getWorld().spawn(location.add(0.5, 0, 0.5), EntityRegistry.getEntity(type), SpawnReason.SPAWNER_EGG);
            if (tag != null) {
                EntityStorage.load(entity, tag);
            }
        }
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) GlowEntity(net.glowstone.entity.GlowEntity) GlowMetaSpawn(net.glowstone.inventory.GlowMetaSpawn) CompoundTag(net.glowstone.util.nbt.CompoundTag) Location(org.bukkit.Location)

Aggregations

CompoundTag (net.glowstone.util.nbt.CompoundTag)58 ArrayList (java.util.ArrayList)9 NBTInputStream (net.glowstone.util.nbt.NBTInputStream)7 Location (org.bukkit.Location)7 IOException (java.io.IOException)6 NBTOutputStream (net.glowstone.util.nbt.NBTOutputStream)5 File (java.io.File)4 FileInputStream (java.io.FileInputStream)3 BlockEntity (net.glowstone.block.entity.BlockEntity)3 GlowEntity (net.glowstone.entity.GlowEntity)3 ByteBuf (io.netty.buffer.ByteBuf)2 FileOutputStream (java.io.FileOutputStream)2 UUID (java.util.UUID)2 ChunkSection (net.glowstone.chunk.ChunkSection)2 AttributeManager (net.glowstone.entity.AttributeManager)2 Modifier (net.glowstone.entity.AttributeManager.Modifier)2 GlowStructure (net.glowstone.generator.structures.GlowStructure)2 StructureBoundingBox (net.glowstone.generator.structures.util.StructureBoundingBox)2 MojangsonParseException (net.glowstone.util.mojangson.ex.MojangsonParseException)2 Material (org.bukkit.Material)2