use of org.spongepowered.common.bridge.data.SpongeDataHolderBridge in project SpongeCommon by SpongePowered.
the class DataUtil method serializeSpongeData.
public static <T extends SpongeDataHolderBridge & DataCompoundHolder> boolean serializeSpongeData(final T dataHolder) {
CompoundTag compound = dataHolder.data$getCompound();
if (compound == null) {
compound = new CompoundTag();
dataHolder.data$setCompound(compound);
}
// Remove all previous SpongeData
compound.remove(Constants.Sponge.Data.V3.SPONGE_DATA_ROOT.asString("."));
final DataContainer allData = NBTTranslator.INSTANCE.translate(compound);
// Clear old custom data root
final DataView customDataRoot = allData.createView(Constants.Sponge.Data.V3.SPONGE_DATA_ROOT);
// Add back failed data
dataHolder.bridge$getFailedData().forEach(customDataRoot::set);
final DataManipulator.Mutable manipulator = dataHolder.bridge$getManipulator();
final Type dataHolderType = dataHolder.getClass();
manipulator.getKeys().stream().map(key -> SpongeDataManager.getDatastoreRegistry().getDataStore(key, dataHolderType)).forEach(dataStore -> dataStore.serialize(manipulator, allData));
// If data is still present after cleanup merge it back into nbt
if (DataUtil.cleanupEmptySpongeData(allData)) {
compound.merge(NBTTranslator.INSTANCE.translate(allData));
}
if (compound.isEmpty()) {
dataHolder.data$setCompound(null);
return false;
}
return true;
}
use of org.spongepowered.common.bridge.data.SpongeDataHolderBridge in project SpongeCommon by SpongePowered.
the class EntityMaxAirMixin method bridge$setMaxAir.
@Override
public void bridge$setMaxAir(int maxAir) {
Entity entity = (Entity) (Object) this;
if (entity.getAirSupply() > maxAir) {
entity.setAirSupply(maxAir);
}
if (this.bridge$getDefaultMaxAir() == maxAir) {
this.impl$maxAir = null;
((SpongeDataHolderBridge) this).bridge$remove(Keys.MAX_AIR);
return;
}
this.impl$maxAir = maxAir;
((SpongeDataHolderBridge) this).bridge$offer(Keys.MAX_AIR, maxAir);
}
use of org.spongepowered.common.bridge.data.SpongeDataHolderBridge in project SpongeCommon by SpongePowered.
the class SpongeEntitySnapshotBuilder method from.
@Override
public SpongeEntitySnapshotBuilder from(final Entity entity) {
this.reset();
this.entityReference = new WeakReference<>(entity);
this.worldKey = entity.serverLocation().worldKey();
this.position = entity.transform().position();
this.rotation = entity.transform().rotation();
this.scale = entity.transform().scale();
this.entityType = entity.type();
this.uniqueId = entity.uniqueId();
this.manipulator = ((SpongeDataHolderBridge) entity).bridge$getManipulator().copy();
this.compound = new CompoundTag();
((net.minecraft.world.entity.Entity) entity).saveWithoutId(this.compound);
return this;
}
use of org.spongepowered.common.bridge.data.SpongeDataHolderBridge in project SpongeCommon by SpongePowered.
the class MapItemSavedDataMixin method bridge$setDecorations.
@SuppressWarnings("SuspiciousMethodCalls")
@Override
public void bridge$setDecorations(final Set<org.spongepowered.api.map.decoration.MapDecoration> newDecorations) {
this.decorations.clear();
for (final org.spongepowered.api.map.decoration.MapDecoration decoration : newDecorations) {
this.impl$addDecorationToDecorationsMapIfNotExists((MapDecoration) decoration);
}
for (final MapDecoration existingDecoration : this.decorations.values()) {
if (!newDecorations.contains(existingDecoration)) {
// Removed.
((MapDecorationBridge) existingDecoration).notifyRemovedFromMap((MapInfo) this);
this.setDirty();
}
}
if (newDecorations.isEmpty()) {
((SpongeDataHolderBridge) this).bridge$remove(Keys.MAP_DECORATIONS);
} else {
((SpongeDataHolderBridge) this).bridge$offer(Keys.MAP_DECORATIONS, newDecorations);
}
}
Aggregations