use of org.spongepowered.common.interfaces.data.IMixinCustomDataHolder in project SpongeCommon by SpongePowered.
the class MixinTileEntity method toContainer.
@Override
public DataContainer toContainer() {
final DataContainer container = DataContainer.createNew().set(Queries.CONTENT_VERSION, getContentVersion()).set(Queries.WORLD_ID, ((World) this.world).getUniqueId().toString()).set(Queries.POSITION_X, this.getPos().getX()).set(Queries.POSITION_Y, this.getPos().getY()).set(Queries.POSITION_Z, this.getPos().getZ()).set(DataQueries.BLOCK_ENTITY_TILE_TYPE, this.tileType.getId());
final NBTTagCompound compound = new NBTTagCompound();
this.writeToNBT(compound);
// We must filter the custom data so it isn't stored twice
NbtDataUtil.filterSpongeCustomData(compound);
container.set(DataQueries.UNSAFE_NBT, NbtTranslator.getInstance().translateFrom(compound));
final Collection<DataManipulator<?, ?>> manipulators = ((IMixinCustomDataHolder) this).getCustomManipulators();
if (!manipulators.isEmpty()) {
container.set(DataQueries.DATA_MANIPULATORS, DataUtil.getSerializedManipulatorList(manipulators));
}
return container;
}
use of org.spongepowered.common.interfaces.data.IMixinCustomDataHolder in project SpongeCommon by SpongePowered.
the class MixinStateImplementation method snapshotFor.
@Override
public BlockSnapshot snapshotFor(Location<World> location) {
final SpongeBlockSnapshotBuilder builder = new SpongeBlockSnapshotBuilder().blockState(this).position(location.getBlockPosition()).worldId(location.getExtent().getUniqueId());
if (this.block.hasTileEntity() && location.getBlockType().equals(this.block)) {
final TileEntity tileEntity = location.getTileEntity().get();
for (DataManipulator<?, ?> manipulator : ((IMixinCustomDataHolder) tileEntity).getCustomManipulators()) {
builder.add(manipulator);
}
final NBTTagCompound compound = new NBTTagCompound();
((net.minecraft.tileentity.TileEntity) tileEntity).writeToNBT(compound);
builder.unsafeNbt(compound);
}
return builder.build();
}
use of org.spongepowered.common.interfaces.data.IMixinCustomDataHolder in project SpongeCommon by SpongePowered.
the class MixinDataHolder method remove.
@Override
public DataTransactionResult remove(Key<?> key) {
TimingsManager.DATA_GROUP_HANDLER.startTimingIfSync();
SpongeTimings.dataRemoveKey.startTimingIfSync();
final Optional<ValueProcessor<?, ?>> optional = DataUtil.getWildValueProcessor(checkNotNull(key));
if (optional.isPresent()) {
final DataTransactionResult result = optional.get().removeFrom(this);
SpongeTimings.dataRemoveKey.stopTimingIfSync();
TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
return result;
} else if (this instanceof IMixinCustomDataHolder) {
final DataTransactionResult result = ((IMixinCustomDataHolder) this).removeCustom(key);
SpongeTimings.dataRemoveKey.stopTimingIfSync();
TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
return result;
}
SpongeTimings.dataRemoveKey.stopTimingIfSync();
TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
return DataTransactionResult.failNoData();
}
use of org.spongepowered.common.interfaces.data.IMixinCustomDataHolder in project SpongeCommon by SpongePowered.
the class MixinDataHolder method remove.
@Override
public DataTransactionResult remove(Class<? extends DataManipulator<?, ?>> containerClass) {
TimingsManager.DATA_GROUP_HANDLER.startTimingIfSync();
SpongeTimings.dataRemoveManipulator.startTimingIfSync();
final Optional<DataProcessor<?, ?>> optional = DataUtil.getWildProcessor(containerClass);
if (optional.isPresent()) {
final DataTransactionResult result = optional.get().remove(this);
SpongeTimings.dataRemoveManipulator.stopTimingIfSync();
TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
return result;
} else if (this instanceof IMixinCustomDataHolder) {
final DataTransactionResult result = ((IMixinCustomDataHolder) this).removeCustom(containerClass);
SpongeTimings.dataRemoveManipulator.stopTimingIfSync();
TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
return result;
}
SpongeTimings.dataOfferMultiManipulators.stopTimingIfSync();
TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
return DataTransactionResult.failNoData();
}
use of org.spongepowered.common.interfaces.data.IMixinCustomDataHolder in project SpongeCommon by SpongePowered.
the class MixinDataHolder method offer.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public DataTransactionResult offer(DataManipulator<?, ?> valueContainer, MergeFunction function) {
TimingsManager.DATA_GROUP_HANDLER.startTimingIfSync();
SpongeTimings.dataOfferManipulator.startTimingIfSync();
final Optional<DataProcessor> optional = DataUtil.getWildDataProcessor(valueContainer.getClass());
if (optional.isPresent()) {
final DataTransactionResult result = optional.get().set(this, valueContainer, checkNotNull(function));
SpongeTimings.dataOfferManipulator.stopTimingIfSync();
TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
return result;
} else if (this instanceof IMixinCustomDataHolder) {
final DataTransactionResult result = ((IMixinCustomDataHolder) this).offerCustom(valueContainer, function);
SpongeTimings.dataOfferManipulator.stopTimingIfSync();
TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
return result;
}
SpongeTimings.dataOfferManipulator.stopTimingIfSync();
TimingsManager.DATA_GROUP_HANDLER.stopTimingIfSync();
return DataTransactionResult.failResult(valueContainer.getValues());
}
Aggregations