use of org.spongepowered.api.data.DataContainer in project modules-extra by CubeEngine.
the class Observe method blockSnapshot.
// Observe
public static Map<String, Object> blockSnapshot(BlockSnapshot block) {
Map<String, Object> info = new HashMap<>();
info.put(BLOCK_STATE.asString("_"), toRawData(block.getState().toContainer()));
DataContainer blockContainer = block.toContainer();
Optional<List<DataView>> data = blockContainer.getViewList(BLOCK_DATA);
if (data.isPresent()) {
info.put(BLOCK_DATA.asString("_"), toRawData(data.get()));
}
Optional<Object> unsafe = blockContainer.get(BLOCK_UNSAFE_DATA);
if (unsafe.isPresent()) {
info.put(BLOCK_UNSAFE_DATA.asString("_"), toRawData(unsafe.get()));
}
return info;
}
use of org.spongepowered.api.data.DataContainer in project modules-extra by CubeEngine.
the class ReportUtil method name.
public static Text name(BlockSnapshot snapshot, Receiver receiver) {
BlockType type = snapshot.getState().getType();
Translation trans = type.getTranslation();
if (snapshot.getState().getType().getItem().isPresent()) {
trans = ItemStack.builder().fromBlockSnapshot(snapshot).build().getTranslation();
}
Builder builder = Text.builder();
builder.append(Text.of(GOLD, trans).toBuilder().onHover(showText(Text.of(type.getName()))).build());
Optional<List<DataView>> items = snapshot.toContainer().getViewList(BlockReport.BLOCK_ITEMS);
if (items.isPresent() && !items.get().isEmpty()) {
// TODO lookup config : detailed inventory? click on ∋ to activate/deactivate or using cmd
builder.append(Text.of(" ∋ ["));
if (receiver.getLookup().getSettings().showDetailedInventory()) {
builder.append(Text.of(" "));
for (DataView dataView : items.get()) {
DataContainer itemData = DataContainer.createNew();
itemData.set(DataQuery.of("Count"), dataView.get(DataQuery.of("Count")).get());
itemData.set(DataQuery.of("ItemType"), dataView.get(DataQuery.of("id")).get());
Optional<DataView> tag = dataView.getView(DataQuery.of("tag"));
if (tag.isPresent()) {
itemData.set(DataQuery.of("UnsafeData"), tag.get().getValues(false));
}
itemData.set(DataQuery.of("UnsafeDamage"), dataView.get(DataQuery.of("Damage")).get());
ItemStack item = ItemStack.builder().fromContainer(itemData).build();
builder.append(Text.of(dataView.getInt(DataQuery.of("Slot")).get()).toBuilder().onHover(showItem(item.createSnapshot())).build());
builder.append(Text.of(" "));
}
} else {
builder.append(Text.of("..."));
}
builder.append(Text.of("]"));
}
Optional<List<Text>> sign = snapshot.get(Keys.SIGN_LINES);
if (sign.isPresent()) {
builder.append(Text.of(" "), Text.of("[I]").toBuilder().onHover(showText(Text.joinWith(Text.NEW_LINE, sign.get()))).build());
}
return builder.build();
}
use of org.spongepowered.api.data.DataContainer in project modules-extra by CubeEngine.
the class ImmutableKitData method toContainer.
@Override
public DataContainer toContainer() {
DataContainer container = DataContainer.createNew();
container.set(TIMES, this.times);
container.set(TIME, this.time);
return container;
}
use of org.spongepowered.api.data.DataContainer in project core by CubeEngine.
the class DataContainerConverter method fromNode.
@Override
public DataContainer fromNode(Node node, Class<? extends DataContainer> type, ConverterManager manager) throws ConversionException {
DataContainer data = DataContainer.createNew();
for (Entry<String, Node> entry : ((MapNode) node).getValue().entrySet()) {
DataQuery key = DataQuery.of('_', ((MapNode) node).getOriginalKey(entry.getKey()));
data.set(key, toObject(entry.getValue(), manager));
}
return data;
}
use of org.spongepowered.api.data.DataContainer in project LanternServer by LanternPowered.
the class MemoryDataView method copy.
@Override
public DataContainer copy() {
final DataContainer container = new MemoryDataContainer(this.safety);
getKeys(false).forEach(query -> get(query).ifPresent(obj -> container.set(query, obj)));
return container;
}
Aggregations