本文整理汇总了Java中org.spongepowered.api.data.DataView.set方法的典型用法代码示例。如果您正苦于以下问题:Java DataView.set方法的具体用法?Java DataView.set怎么用?Java DataView.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.data.DataView
的用法示例。
在下文中一共展示了DataView.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeSpongeStack
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
@Override
public ItemStack makeSpongeStack(BaseItemStack baseItemStack) {
final ItemType itemType = ItemRegistryModule.get().getTypeByInternalId(baseItemStack.getType())
.orElseThrow(() -> new IllegalStateException("Invalid item type: " + baseItemStack.getType()));
final LanternItemStack itemStack = new LanternItemStack(itemType, baseItemStack.getAmount());
final ObjectStore<LanternItemStack> store = ObjectStoreRegistry.get().get(LanternItemStack.class)
.orElseThrow(() -> new IllegalStateException("Unable to access the LanternItemStack store."));
final DataView view = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
view.set(DATA_VALUE, baseItemStack.getData());
store.deserialize(itemStack, view);
final Map<Integer, Integer> enchantments = baseItemStack.getEnchantments();
if (!enchantments.isEmpty()) {
itemStack.offer(Keys.ITEM_ENCHANTMENTS, enchantments.entrySet().stream()
.map(entry -> {
final Enchantment enchantment = EnchantmentRegistryModule.get().getByInternalId(entry.getKey())
.orElseThrow(() -> new IllegalStateException("Invalid enchantment type: " + entry.getKey()));
return new ItemEnchantment(enchantment, entry.getValue());
})
.collect(Collectors.toList()));
}
return itemStack;
}
示例2: from
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
private static Object from(Tag tag, @Nullable DataView view) {
if (tag instanceof CompoundTag) {
final Map<String, Tag> map = ((CompoundTag) tag).getValue();
if (view == null) {
view = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
}
for (Map.Entry<String, Tag> entry : map.entrySet()) {
if (entry.getValue() instanceof CompoundTag) {
from(tag, view.createView(DataQuery.of(entry.getKey())));
} else {
view.set(DataQuery.of(entry.getKey()), from(entry.getValue(), null));
}
}
return view;
} else if (tag instanceof ListTag) {
return ((ListTag) tag).getValue().stream().map(entry -> from(entry, null)).collect(Collectors.toList());
}
return tag.getValue();
}
示例3: 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());
}
示例4: read
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
@Override
public ItemStack read(ByteBuffer buf) throws CodecException {
final RawItemStack rawItemStack = buf.read(Types.RAW_ITEM_STACK);
//noinspection ConstantConditions
if (rawItemStack == null) {
return null;
}
final ItemType itemType = ItemRegistryModule.get().getTypeByInternalId(rawItemStack.getItemType()).orElse(null);
if (itemType == null) {
return null;
}
final LanternItemStack itemStack = new LanternItemStack(itemType, rawItemStack.getAmount());
final DataView dataView = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
dataView.set(ItemStackStore.DATA, rawItemStack.getData());
dataView.set(ItemStackStore.QUANTITY, rawItemStack.getAmount());
final DataView tag = rawItemStack.getDataView();
if (tag != null) {
dataView.set(ItemStackStore.TAG, tag);
}
this.store.deserialize(itemStack, dataView);
return itemStack;
}
示例5: serialize
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
public static DataView serialize(PotionEffect potionEffect) {
final DataView dataView = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
dataView.set(AMPLIFIER, (byte) potionEffect.getAmplifier());
dataView.set(DURATION, potionEffect.getDuration());
dataView.set(AMBIENT, (byte) (potionEffect.isAmbient() ? 1 : 0));
if (potionEffect.getShowParticles()) {
dataView.set(SHOW_PARTICLES, (byte) 1);
}
final LanternPotionEffectType potionEffectType = (LanternPotionEffectType) potionEffect.getType();
final int internalId = potionEffectType.getInternalId();
if (internalId > 0xff) {
dataView.set(IDENTIFIER, internalId);
} else {
dataView.set(IDENTIFIER, (byte) internalId);
}
return dataView;
}
示例6: writeTo
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
@Override
public void writeTo(DataView data) {
for (Entry<String, Entity> entry : this.entities.entrySet()) {
Object uuid = entry.getValue() != null ? entry.getValue().getUniqueId() : 0;
data.set(of(entry.getKey().toString()), uuid);
}
}
示例7: writeTo
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
@Override
public void writeTo(DataView data) {
data.set(of("code"), this.code);
data.set(of("pointer"), this.pointer);
Action active = getActive();
if (active != null) {
active.writeTo(data.createView(of("active")));
}
}
示例8: writeTo
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
@Override
public void writeTo(DataView data) {
data.set(of("item"), this.stack);
data.set(of("position"), this.pos);
data.set(of("from"), this.from.name());
data.set(of("destination"), this.dest.name());
data.set(of("speed"), this.speed);
data.set(of("reachedCenter"), this.reachedCenter);
if (this.itemStand != null && !this.itemStand.isRemoved()) {
data.set(of("entityRef"), this.itemStand.getUniqueId());
}
}
示例9: writeTo
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
@Override
public void writeTo(DataView data) {
super.writeTo(data);
List<DataView> itemDataList = Lists.newArrayList();
for (PipeObject obj : this.items) {
itemDataList.add(obj.toContainer());
}
data.set(of("items"), itemDataList);
}
示例10: writeTo
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
@Override
public void writeTo(DataView data) {
if (!this.inventory.isEmpty()) {
data.set(of("inventory"), this.inventory);
}
data.set(of("percent"), this.percentageLeft);
if (this.currentGoalOut != null) {
data.set(of("output"), this.currentGoalOut);
}
}
示例11: writeTo
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
@Override
public void writeTo(DataView data) {
List<DataView> itemDataList = Lists.newArrayList();
for (int i = 0; i < this.itemArray.length; i++) {
ItemStack itemStack = this.itemArray[i];
if (itemStack != null) {
itemDataList.add(itemStack.toContainer());
} else {
itemDataList.add(Utils.emptyData());
}
}
data.set(of("items"), itemDataList);
}
示例12: merge
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
public static void merge(DataView first, DataView... others) {
for (DataView other : others) {
for (Entry<DataQuery, Object> valueEntry : other.getValues(true).entrySet()) {
first.set(valueEntry.getKey(), valueEntry.getValue());
}
}
}
示例13: serializeExplosion
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
static DataView serializeExplosion(FireworkEffect effect) {
final DataView dataView = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
dataView.set(FLICKER, (byte) (effect.flickers() ? 1 : 0));
dataView.set(TRAIL, (byte) (effect.hasTrail() ? 1 : 0));
dataView.set(TYPE, (byte) ((LanternFireworkShape) effect.getShape()).getInternalId());
dataView.set(COLORS, effect.getColors().stream().mapToInt(Color::getRgb).toArray());
dataView.set(FADE_COLORS, effect.getFadeColors().stream().mapToInt(Color::getRgb).toArray());
return dataView;
}
示例14: serializeRawContainerData
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
public static void serializeRawContainerData(DataView dataView, IValueContainer valueContainer, DataQuery query) {
if (!(valueContainer instanceof AdditionalContainerHolder)) {
return;
}
final ValueCollection valueCollection = valueContainer.getValueCollection();
final AdditionalContainerCollection<ValueContainer<?>> containers =
((AdditionalContainerHolder) valueContainer).getAdditionalContainers();
final ImmutableList.Builder<DataView> builder = ImmutableList.builder();
final LanternDataManager dataManager = Lantern.getGame().getDataManager();
for (ValueContainer<?> manipulator : containers.getAll()) {
if (!(manipulator instanceof DataManipulator)) {
continue;
}
final Class<?> manipulatorType;
if (manipulator instanceof IDataManipulator) {
manipulatorType = ((IDataManipulator) manipulator).getMutableType();
} else {
manipulatorType = manipulator.getClass();
}
final Optional<DataRegistration> optRegistration = dataManager.get(manipulatorType);
if (!optRegistration.isPresent()) {
getLogger().error("Could not serialize {}. No registration could be found.", manipulatorType.getName());
} else {
builder.add(DataContainer.createNew()
.set(DataQueries.MANIPULATOR_ID, optRegistration.get().getId())
.set(DataQueries.MANIPULATOR_DATA, ((DataManipulator) manipulator).toContainer()));
}
}
Element<List<DataView>> holder = valueCollection.getElement(LanternKeys.FAILED_DATA_MANIPULATORS).orElse(null);
if (holder != null) {
builder.addAll(holder.get());
}
dataView.set(query, builder.build());
}
示例15: readView
import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
private static void readView(JsonReader reader, DataView view) throws IOException {
reader.beginObject();
while (reader.hasNext()) {
DataQuery key = DataQuery.of(reader.nextName());
if (reader.peek() == JsonToken.BEGIN_OBJECT) {
// Check this early so we don't need to copy the view
readView(reader, view.createView(key));
} else {
view.set(key, read0(reader));
}
}
reader.endObject();
}