use of com.bergerkiller.bukkit.common.nbt.CommonTagCompound in project BKCommonLib by bergerhealer.
the class ItemUtil method createPlayerHeadItem.
/**
* Creates a new player head item with the game profile information specified.
* This creates a player head with this profile's skin texture information.
*
* @param gameProfile
* @return Skull item
*/
@SuppressWarnings("deprecation")
public static ItemStack createPlayerHeadItem(GameProfileHandle gameProfile) {
ItemStack item = createItem(MaterialUtil.getFirst("PLAYER_HEAD", "LEGACY_SKULL_ITEM"), 1);
CommonTagCompound nbt = getMetaTag(item, true);
nbt.put("SkullOwner", gameProfile.serialize());
// For supporting MC 1.12.2 and before
item.setDurability((short) 3);
return item;
}
use of com.bergerkiller.bukkit.common.nbt.CommonTagCompound in project BKCommonLib by bergerhealer.
the class ForgeSupport method listDimensions.
private Set<LevelDimension> listDimensions(File worldFolder) {
File levelDatFile = new File(worldFolder, "level.dat");
if (!levelDatFile.exists()) {
return Collections.emptySet();
}
// Add folder name itself as a world name
String rootWorldName = worldFolder.getName();
// Parse level.dat and add all dimensions defined inside, if defined
try {
CommonTagCompound levelDat = CommonTagCompound.readFromFile(levelDatFile, true);
CommonTagCompound data = levelDat.get("Data", CommonTagCompound.class);
if (data != null) {
CommonTagCompound worldGenSettings = data.get("WorldGenSettings", CommonTagCompound.class);
if (worldGenSettings != null) {
CommonTagCompound dimensions = worldGenSettings.get("dimensions", CommonTagCompound.class);
if (dimensions != null) {
Set<LevelDimension> result = new HashSet<>(dimensions.size());
for (String modnameAndDimension : dimensions.keySet()) {
if (dimensions.get(modnameAndDimension, CommonTagCompound.class) != null) {
int modNameEnd = modnameAndDimension.indexOf(':');
String namespace, dimension;
if (modNameEnd == -1) {
namespace = "minecraft";
dimension = modnameAndDimension;
} else {
namespace = modnameAndDimension.substring(0, modNameEnd);
dimension = modnameAndDimension.substring(modNameEnd + 1);
}
result.add(new LevelDimension(rootWorldName, namespace, dimension));
}
}
// All dimensions accounted for - fallback not needed
return result;
}
}
}
} catch (Throwable t) {
Logging.LOGGER.log(Level.SEVERE, "Failed to read level.dat of world " + worldFolder.getName(), t);
}
// Fallback solution
Set<LevelDimension> result = new HashSet<>(3);
result.add(new LevelDimension(rootWorldName, "minecraft", "overworld"));
if ((new File(worldFolder, "DIM-1")).exists()) {
result.add(new LevelDimension(rootWorldName, "minecraft", "the_nether"));
}
if ((new File(worldFolder, "DIM1")).exists()) {
result.add(new LevelDimension(rootWorldName, "minecraft", "the_end"));
}
return result;
}
use of com.bergerkiller.bukkit.common.nbt.CommonTagCompound in project BKCommonLib by bergerhealer.
the class MapDisplay method createMapItem.
/**
* Creates a new Map Display item that will automatically initialize a particular Map Display class
* when viewed
*
* @param plugin owner of the display
* @param mapDisplayClass
* @return map item
*/
public static ItemStack createMapItem(Plugin plugin, Class<? extends MapDisplay> mapDisplayClass) {
ItemStack mapItem = ItemUtil.createItem(Material.MAP, 0, 1);
CommonTagCompound tag = ItemUtil.getMetaTag(mapItem, true);
tag.putValue("mapDisplayPlugin", plugin.getName());
tag.putValue("mapDisplayClass", mapDisplayClass.getName());
tag.putUUID("mapDisplay", CommonMapUUIDStore.generateDynamicMapUUID());
return mapItem;
}
use of com.bergerkiller.bukkit.common.nbt.CommonTagCompound in project BKCommonLib by bergerhealer.
the class CommonMapController method trimExtraData.
/**
* Removes all NBT data for map items that is unimportant for clients to know
*
* @param item
* @return new item copy with metadata trimmed
*/
public static ItemStack trimExtraData(ItemStack item) {
// If null, return null. Simples.
if (item == null) {
return null;
}
// Get rid of all custom metadata from the item
// Only Minecraft items are interesting (because its the Minecraft client)
CommonTagCompound oldTag = ItemUtil.getMetaTag(item, false);
CommonTagCompound newTag = new CommonTagCompound();
final String[] nbt_filter = { "ench", "display", "RepairCost", "AttributeModifiers", "CanDestroy", "CanPlaceOn", "Unbreakable", // This is important to prevent potential corruption
"mapDisplayUUIDMost", "mapDisplayUUIDLeast", "mapDisplayPlugin", "mapDisplayClass" };
for (String filter : nbt_filter) {
if (oldTag.containsKey(filter)) {
newTag.put(filter, oldTag.get(filter));
}
}
item = ItemUtil.cloneItem(item);
ItemUtil.setMetaTag(item, newTag);
return item;
}
use of com.bergerkiller.bukkit.common.nbt.CommonTagCompound in project BKCommonLib by bergerhealer.
the class BlockStateChangePacketHandler_1_9_3 method enable.
@Override
public void enable() {
register(PacketType.OUT_TILE_ENTITY_DATA, (player, commonPacket, listener) -> {
final PacketPlayOutTileEntityDataHandle packet = PacketPlayOutTileEntityDataHandle.createHandle(commonPacket.getHandle());
CommonTagCompound metadata = packet.getData();
if (metadata != null) {
// There's metadata, nothing special needs to be done
BlockStateChange change = BlockStateChange.deferred(packet.getPosition(), packet.getType(), LogicUtil.constantSupplier(metadata), () -> true);
// Handle it, if false, cancel the packet entirely
if (!listener.onBlockChange(player, change)) {
return false;
}
} else {
// Initialize metadata on first use
final DeferredSupplier<CommonTagCompound> metadataSupplier = DeferredSupplier.of(CommonTagCompound::new);
BlockStateChange change = BlockStateChange.deferred(packet.getPosition(), packet.getType(), metadataSupplier, metadataSupplier::isInitialized);
// Handle it, if false, cancel the packet entirely
if (!listener.onBlockChange(player, change)) {
return false;
}
// If metadata was created and it's not empty, apply it to the packet
if (metadataSupplier.isInitialized() && !metadataSupplier.get().isEmpty()) {
packet.setData(metadataSupplier.get());
}
}
return true;
});
register(PacketType.OUT_MAP_CHUNK, (player, commonPacket, listener) -> {
PacketPlayOutMapChunkHandle packet = PacketPlayOutMapChunkHandle.createHandle(commonPacket.getHandle());
Iterator<BlockStateChange> iter = packet.getBlockStates().iterator();
while (iter.hasNext()) {
BlockStateChange change = iter.next();
if (!listener.onBlockChange(player, change)) {
iter.remove();
}
}
return true;
});
}
Aggregations