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 GlowPlayer method sendSignChange.
/**
* Send a sign change, similar to {@link #sendSignChange(Location, String[])},
* but using complete TextMessages instead of strings.
*
* @param location the location of the sign
* @param lines the new text on the sign or null to clear it
* @throws IllegalArgumentException if location is null
* @throws IllegalArgumentException if lines is non-null and has a length less than 4
*/
public void sendSignChange(SignEntity sign, Location location, TextMessage[] lines) throws IllegalArgumentException {
checkNotNull(location, "location cannot be null");
checkNotNull(lines, "lines cannot be null");
checkArgument(lines.length == 4, "lines.length must equal 4");
CompoundTag tag = new CompoundTag();
sign.saveNbt(tag);
afterBlockChanges.add(new UpdateBlockEntityMessage(location.getBlockX(), location.getBlockY(), location.getBlockZ(), GlowBlockEntity.SIGN.getValue(), tag));
}
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);
}
use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.
the class MojangsonParseTest method canParseType.
@Test
public void canParseType() {
try {
CompoundTag compound = Mojangson.parseCompound(testCase.getValue());
Tag value = compound.getValue().get("value");
// Checks if the TagType of the case and the parsed type are equal.
if (value.getType() != testCase.getKey()) {
fail("Incorrect type parsing for case " + testCase.getKey().getName() + " (Got " + value.getType().getName() + ") for Mojansgon: " + testCase.getValue());
}
} catch (MojangsonParseException e) {
// Catches a parse failure.
fail("Could not parse case for " + testCase.getKey().getName() + "( " + testCase.getValue() + "): " + e.getMessage());
}
}
use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.
the class SkullEntity method update.
@Override
public void update(GlowPlayer player) {
super.update(player);
CompoundTag nbt = new CompoundTag();
saveNbt(nbt);
player.sendBlockEntityChange(getBlock().getLocation(), GlowBlockEntity.SKULL, nbt);
}
Aggregations