use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.
the class GlowMetaPotion method toNBT.
public static CompoundTag toNBT(PotionEffect effect) {
CompoundTag tag = new CompoundTag();
tag.putByte("Id", effect.getType().getId());
tag.putInt("Duration", effect.getDuration());
tag.putByte("Amplifier", effect.getAmplifier());
tag.putBool("Ambient", effect.isAmbient());
tag.putBool("ShowParticles", effect.hasParticles());
return tag;
}
use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.
the class GlowMetaSpawn method readNbt.
@Override
void readNbt(CompoundTag tag) {
super.readNbt(tag);
if (tag.isCompound("EntityTag")) {
CompoundTag entity = tag.getCompound("EntityTag");
if (entity.isString("id")) {
String id = entity.getString("id");
if (id.startsWith("minecraft:")) {
id = id.substring("minecraft:".length());
}
type = EntityType.fromName(id);
}
this.entityTag = entity;
}
}
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);
}
}
}
}
use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.
the class GlowChunk method toMessage.
/**
* Creates a new {@link ChunkDataMessage} which can be sent to a client to stream
* parts of this chunk to them.
*
* @param skylight Whether to include skylight data.
* @param entireChunk Whether to send all chunk sections.
* @return The {@link ChunkDataMessage}.
*/
public ChunkDataMessage toMessage(boolean skylight, boolean entireChunk) {
load();
int sectionBitmask = 0;
// filter sectionBitmask based on actual chunk contents
if (sections != null) {
int maxBitmask = (1 << sections.length) - 1;
if (entireChunk) {
sectionBitmask = maxBitmask;
} else {
sectionBitmask &= maxBitmask;
}
for (int i = 0; i < sections.length; ++i) {
if (sections[i] == null || sections[i].isEmpty()) {
// remove empty sections from bitmask
sectionBitmask &= ~(1 << i);
}
}
}
ByteBuf buf = Unpooled.buffer();
if (sections != null) {
// get the list of sections
for (int i = 0; i < sections.length; ++i) {
if ((sectionBitmask & 1 << i) == 0) {
continue;
}
sections[i].writeToBuf(buf, skylight);
}
}
// biomes
if (entireChunk && biomes != null) {
buf.writeBytes(biomes);
}
ArrayList<CompoundTag> blockEntities = new ArrayList<>();
for (BlockEntity blockEntity : getRawBlockEntities()) {
CompoundTag tag = new CompoundTag();
blockEntity.saveNbt(tag);
blockEntities.add(tag);
}
return new ChunkDataMessage(x, z, entireChunk, sectionBitmask, buf, blockEntities.toArray(new CompoundTag[blockEntities.size()]));
}
use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.
the class PlayerProfile method fromNBT.
public static PlayerProfile fromNBT(CompoundTag tag) {
// NBT: {Id: "", Name: "", Properties: {textures: [{Signature: "", Value: {}}]}}
String uuidStr = tag.getString("Id");
String name;
if (tag.containsKey("Name")) {
name = tag.getString("Name");
} else {
name = ProfileCache.getProfile(UUID.fromString(uuidStr)).getName();
}
List<PlayerProperty> properties = new ArrayList<>();
if (tag.containsKey("Properties")) {
CompoundTag texture = tag.getCompound("Properties").getCompoundList("textures").get(0);
if (texture.containsKey("Signature")) {
properties.add(new PlayerProperty("textures", texture.getString("Value"), texture.getString("Signature")));
} else {
properties.add(new PlayerProperty("textures", texture.getString("Value")));
}
}
return new PlayerProfile(name, UUID.fromString(uuidStr), properties);
}
Aggregations