本文整理汇总了Java中org.spongepowered.api.data.DataView.createView方法的典型用法代码示例。如果您正苦于以下问题:Java DataView.createView方法的具体用法?Java DataView.createView怎么用?Java DataView.createView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.data.DataView
的用法示例。
在下文中一共展示了DataView.createView方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeTo
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
@Override
public void writeTo(DataView data) {
DataList<DataView> blockList = Utils.createListView();
for (Entry<Vector3i, BlockNature> entry : this.trackedBlocks.entrySet()) {
DataView blockDataView = blockList.next();
Vector3i pos = entry.getKey();
BlockNature block = entry.getValue();
blockDataView.set(of("position"), pos);
DataView blockView = blockDataView.createView(of("block"));
blockView.set(of("id"), block.getId());
block.writeDataAt(this, pos, blockView);
BlockData blockData = this.trackedBlockData.get(pos);
if (blockData != null) {
blockDataView.set(of("blockData"), blockData);
}
}
data.set(of("blocks"), blockList.getList());
DataList<DataView> entityList = Utils.createListView();
for (CustomEntity customEntity : this.trackedCustomEntities) {
customEntity.writeTo(entityList.next());
}
data.set(of("entities"), entityList.getList());
}
示例2: createView
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
@Override
public DataView createView(DataQuery path) {
checkNotNull(path, "path");
final List<String> queryParts = path.getParts();
final int sz = queryParts.size();
checkArgument(sz != 0, "The size of the query must be at least 1");
final String key = queryParts.get(0);
final DataQuery keyQuery = of(key);
if (sz == 1) {
final DataView result = new MemoryDataView(this, keyQuery, this.safety);
this.map.put(key, result);
return result;
}
final DataQuery subQuery = path.popFirst();
final DataView subView = (DataView) this.map.computeIfAbsent(key,
key1 -> new MemoryDataView(this.parent, keyQuery, this.safety));
return subView.createView(subQuery);
}
示例3: writeTo
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
@Override
public void writeTo(DataView data) {
super.writeTo(data);
this.tracker.writeTo(data);
DataView taskData = data.createView(of("task"));
this.task.writeTo(taskData);
}
示例4: serializeValues
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
@Override
public void serializeValues(ItemStack itemStack, SimpleValueContainer valueContainer, DataView dataView) {
super.serializeValues(itemStack, valueContainer, dataView);
final DataView fireworksView = dataView.createView(FIREWORKS);
valueContainer.remove(Keys.FIREWORK_EFFECTS).ifPresent(effects -> fireworksView.set(EXPLOSIONS,
effects.stream().map(FireworkChargeItemTypeObjectSerializer::serializeExplosion).collect(Collectors.toList())));
valueContainer.remove(Keys.FIREWORK_FLIGHT_MODIFIER).ifPresent(modifier -> fireworksView.set(FLIGHT_MODIFIER, modifier.byteValue()));
}
示例5: serialize
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
@Override
public void serialize(LanternItemStack object, DataView dataView) {
dataView.set(QUANTITY, (byte) object.getQuantity());
final DataView tag = dataView.createView(TAG);
super.serialize(object, tag);
dataView.set(DATA, tag.getShort(ItemTypeObjectSerializer.DATA_VALUE).orElse((short) 0));
tag.remove(ItemTypeObjectSerializer.DATA_VALUE);
if (tag.isEmpty()) {
dataView.remove(TAG);
}
}
示例6: writeTo
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
public void writeTo(DataView data) {
DataView view = data.createView(of("trackedEntities"));
for (Map.Entry<String, Entity> entry : this.entities.entrySet()) {
view.set(of(entry.getKey()), entry.getValue().getUniqueId());
}
}
示例7: serializeRawRegisteredKeyData
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
public static void serializeRawRegisteredKeyData(DataView dataView, IValueContainer valueContainer,
Set<Key> ignoredKeys) {
DataView view = null;
final ValueCollection valueCollection = valueContainer.getValueCollection();
final LanternDataManager dataManager = Lantern.getGame().getDataManager();
final DataTypeSerializerContext context = dataManager.getTypeSerializerContext();
for (KeyRegistration<?,?> registration : valueCollection.getAll()) {
final Key<?> key = registration.getKey();
if (!(registration instanceof Element)
|| ignoredKeys.contains(key)
|| key == LanternKeys.FAILED_DATA_MANIPULATORS
|| key == LanternKeys.FAILED_DATA_VALUES) {
continue;
}
final Element element = (Element) registration;
final TypeToken<?> typeToken = key.getElementToken();
final DataTypeSerializer typeSerializer = dataManager.getTypeSerializer(typeToken)
.orElseThrow(() -> new IllegalStateException(
"Wasn't able to find a type serializer for the element type: " + typeToken.toString()));
final Object object = element.get();
if (object == null) {
continue;
}
final Object value = typeSerializer.serialize(typeToken, context, object);
if (view == null) {
view = dataView.createView(DataQueries.DATA_VALUES);
}
view.set(key.getQuery(), value);
}
Element<DataView> holder = valueCollection.getElement(LanternKeys.FAILED_DATA_VALUES).orElse(null);
if (holder != null) {
if (view == null) {
view = dataView.createView(DataQueries.DATA_VALUES);
}
for (Map.Entry<DataQuery, Object> entry : holder.get().getValues(false).entrySet()) {
if (!view.contains(entry.getKey())) {
view.set(entry.getKey(), entry.getValue());
}
}
}
}
示例8: write
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
public static void write(Path folder, Scoreboard scoreboard) throws IOException {
final List<DataView> objectives = scoreboard.getObjectives().stream().map(objective -> DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED)
.set(NAME, objective.getName())
.set(DISPLAY_NAME, ((LanternObjective) objective).getLegacyDisplayName())
.set(CRITERION_NAME, objective.getCriterion().getId())
.set(DISPLAY_MODE, objective.getDisplayMode().getId())).collect(Collectors.toList());
final List<DataView> scores = new ArrayList<>();
for (Score score : scoreboard.getScores()) {
final Iterator<Objective> it = score.getObjectives().iterator();
final DataView baseView = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED)
.set(NAME, ((LanternScore) score).getLegacyName())
.set(SCORE, score.getScore());
// TODO: Locked state
final DataView mainView = baseView.copy()
.set(OBJECTIVE, it.next().getName());
final List<String> extraObjectives = new ArrayList<>();
while (it.hasNext()) {
final String extraObjectiveName = it.next().getName();
scores.add(baseView.copy()
.set(OBJECTIVE, extraObjectiveName)
.set(INVALID, (byte) 1));
extraObjectives.add(extraObjectiveName);
}
if (!extraObjectives.isEmpty()) {
mainView.set(EXTRA_OBJECTIVES, extraObjectives);
}
}
final List<DataView> teams = new ArrayList<>();
for (Team team : scoreboard.getTeams()) {
final DataView container = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED)
.set(ALLOW_FRIENDLY_FIRE, (byte) (team.allowFriendlyFire() ? 1 : 0))
.set(CAN_SEE_FRIENDLY_INVISIBLES, (byte) (team.canSeeFriendlyInvisibles() ? 1 : 0))
.set(NAME_TAG_VISIBILITY, team.getNameTagVisibility().getName())
.set(NAME, team.getName())
.set(DISPLAY_NAME, ((LanternTeam) team).getLegacyDisplayName())
.set(DEATH_MESSAGE_VISIBILITY, team.getDeathMessageVisibility().getName())
.set(COLLISION_RULE, team.getCollisionRule().getName())
.set(PREFIX, ((LanternTeam) team).getLegacyPrefix())
.set(SUFFIX, ((LanternTeam) team).getLegacySuffix());
final TextColor teamColor = team.getColor();
if (teamColor != TextColors.NONE) {
container.set(TEAM_COLOR, teamColor.getId());
}
final Set<Text> members = team.getMembers();
container.set(MEMBERS, members.stream().map(LanternTexts::toLegacy).collect(Collectors.toList()));
teams.add(container);
}
final DataContainer rootDataContainer = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
final DataView dataView = rootDataContainer.createView(DATA)
.set(OBJECTIVES, objectives)
.set(SCORES, scores)
.set(TEAMS, teams);
final DataView displaySlots = dataView.createView(DISPLAY_SLOTS);
((LanternScoreboard) scoreboard).getObjectivesInSlot().entrySet().forEach(entry ->
displaySlots.set(DataQuery.of("slot_" + ((LanternDisplaySlot) entry.getKey()).getInternalId()), entry.getValue().getName()));
IOHelper.write(folder.resolve(SCOREBOARD_DATA), file -> {
NbtStreamUtils.write(rootDataContainer, Files.newOutputStream(file), true);
return true;
});
}
示例9: serializeValues
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
@Override
public void serializeValues(T player, SimpleValueContainer valueContainer, DataView dataView) {
valueContainer.remove(Keys.IS_SPRINTING);
valueContainer.remove(Keys.IS_SNEAKING);
valueContainer.remove(LanternKeys.ACTIVE_HAND);
final DataView abilities = dataView.createView(ABILITIES);
abilities.set(FLYING, (byte) (valueContainer.remove(Keys.IS_FLYING).orElse(false) ? 1 : 0));
abilities.set(FLYING_SPEED, valueContainer.remove(Keys.FLYING_SPEED).orElse(0.1).floatValue());
abilities.set(CAN_FLY, (byte) (valueContainer.remove(Keys.CAN_FLY).orElse(false) ? 1 : 0));
final DataView spongeData = getOrCreateView(dataView, DataQueries.EXTENDED_SPONGE_DATA);
spongeData.set(FIRST_DATE_PLAYED, valueContainer.remove(Keys.FIRST_DATE_PLAYED).orElse(Instant.now()).toEpochMilli());
spongeData.set(LAST_DATE_PLAYED, valueContainer.remove(Keys.LAST_DATE_PLAYED).orElse(Instant.now()).toEpochMilli());
spongeData.set(UNIQUE_ID, player.getUniqueId().toString());
spongeData.set(Queries.CONTENT_VERSION, 1);
final Map<UUID, RespawnLocation> respawnLocations = valueContainer.remove(Keys.RESPAWN_LOCATIONS).get();
final List<DataView> respawnLocationViews = new ArrayList<>();
for (RespawnLocation respawnLocation : respawnLocations.values()) {
Lantern.getWorldManager().getWorldDimensionId(respawnLocation.getWorldUniqueId()).ifPresent(dimensionId -> {
// Overworld respawn location is saved in the root container
if (dimensionId == 0) {
serializeRespawnLocationTo(dataView, respawnLocation);
} else {
respawnLocationViews.add(serializeRespawnLocationTo(DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED), respawnLocation)
.set(RESPAWN_LOCATIONS_DIMENSION, dimensionId));
}
});
}
dataView.set(RESPAWN_LOCATIONS, respawnLocationViews);
dataView.set(GAME_MODE, ((LanternGameMode) valueContainer.remove(Keys.GAME_MODE).orElse(GameModes.NOT_SET)).getInternalId());
dataView.set(SELECTED_ITEM_SLOT, player.getInventory().getHotbar().getSelectedSlotIndex());
dataView.set(SCORE, valueContainer.remove(LanternKeys.SCORE).get());
// Serialize the player inventory
dataView.set(INVENTORY, serializePlayerInventory(player.getInventory()));
// Serialize the ender chest inventory
dataView.set(ENDER_CHEST_INVENTORY, serializeEnderChest(player.getEnderChestInventory()));
final DataView recipeBook = dataView.createView(RECIPE_BOOK);
recipeBook.set(RECIPE_BOOK_FILTER_ACTIVE, (byte) (valueContainer.remove(LanternKeys.RECIPE_BOOK_FILTER_ACTIVE).orElse(false) ? 1 : 0));
recipeBook.set(RECIPE_BOOK_GUI_OPEN, (byte) (valueContainer.remove(LanternKeys.RECIPE_BOOK_GUI_OPEN).orElse(false) ? 1 : 0));
valueContainer.remove(LanternKeys.OPEN_ADVANCEMENT_TREE).ifPresent(o -> {
if (o.isPresent()) {
dataView.set(OPEN_ADVANCEMENT_TREE, o.get().getId());
}
});
super.serializeValues(player, valueContainer, dataView);
}
示例10: serialize
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void serialize(T object, DataView dataView) {
if (object instanceof IValueContainer) {
final IValueContainer<S> valueContainer = (IValueContainer<S>) object;
final SimpleValueContainer simpleValueContainer = new SimpleValueContainer(new HashMap<>());
for (KeyRegistration<?,?> registration : valueContainer.getValueCollection().getAll()) {
if (!(registration instanceof Element)) {
continue;
}
final Key key = registration.getKey();
final Object element = ((Element) registration).get();
if (element != null) {
simpleValueContainer.set(key, element);
}
}
// Serialize the values, all written values will be removed from
// the simple value container
serializeValues(object, simpleValueContainer, dataView);
// Write the rest to the Values tag
final Map<Key<?>, Object> values = simpleValueContainer.getValues();
if (!values.isEmpty()) {
final DataView valuesView = dataView.createView(VALUES);
final DataTypeSerializerContext context = Lantern.getGame().getDataManager().getTypeSerializerContext();
for (Map.Entry<Key<?>, Object> entry : values.entrySet()) {
final TypeToken<?> typeToken = entry.getKey().getElementToken();
final DataTypeSerializer dataTypeSerializer = Lantern.getGame().getDataManager().getTypeSerializer(typeToken).orElse(null);
if (dataTypeSerializer == null) {
Lantern.getLogger().warn("Unable to serialize the data key value: " + entry.getKey());
} else {
valuesView.set(DataQuery.of(entry.getKey().getId()),
dataTypeSerializer.serialize(typeToken, context, entry.getValue()));
}
}
if (valuesView.isEmpty()) {
dataView.remove(VALUES);
}
}
DataHelper.serializeRawContainerData(getOrCreateView(dataView, DataQueries.SPONGE_DATA),
valueContainer, DataQueries.CUSTOM_MANIPULATORS);
} else {
// Not sure what to do
}
}