Search in sources :

Example 1 with IMixinCustomDataHolder

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;
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) DataManipulator(org.spongepowered.api.data.manipulator.DataManipulator) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) World(org.spongepowered.api.world.World) IMixinCustomDataHolder(org.spongepowered.common.interfaces.data.IMixinCustomDataHolder)

Example 2 with IMixinCustomDataHolder

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();
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) SpongeBlockSnapshotBuilder(org.spongepowered.common.block.SpongeBlockSnapshotBuilder) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IMixinCustomDataHolder(org.spongepowered.common.interfaces.data.IMixinCustomDataHolder)

Example 3 with IMixinCustomDataHolder

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();
}
Also used : ValueProcessor(org.spongepowered.common.data.ValueProcessor) DataTransactionResult(org.spongepowered.api.data.DataTransactionResult) IMixinCustomDataHolder(org.spongepowered.common.interfaces.data.IMixinCustomDataHolder)

Example 4 with IMixinCustomDataHolder

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();
}
Also used : DataTransactionResult(org.spongepowered.api.data.DataTransactionResult) DataProcessor(org.spongepowered.common.data.DataProcessor) IMixinCustomDataHolder(org.spongepowered.common.interfaces.data.IMixinCustomDataHolder)

Example 5 with IMixinCustomDataHolder

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());
}
Also used : DataTransactionResult(org.spongepowered.api.data.DataTransactionResult) DataProcessor(org.spongepowered.common.data.DataProcessor) IMixinCustomDataHolder(org.spongepowered.common.interfaces.data.IMixinCustomDataHolder)

Aggregations

IMixinCustomDataHolder (org.spongepowered.common.interfaces.data.IMixinCustomDataHolder)16 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)9 DataManipulator (org.spongepowered.api.data.manipulator.DataManipulator)6 World (org.spongepowered.api.world.World)5 DataTransactionResult (org.spongepowered.api.data.DataTransactionResult)4 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)3 DataView (org.spongepowered.api.data.DataView)3 SpongeBlockSnapshotBuilder (org.spongepowered.common.block.SpongeBlockSnapshotBuilder)3 UUID (java.util.UUID)2 ITileEntityProvider (net.minecraft.block.ITileEntityProvider)2 IBlockState (net.minecraft.block.state.IBlockState)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockState (org.spongepowered.api.block.BlockState)2 DataContainer (org.spongepowered.api.data.DataContainer)2 ImmutableDataManipulator (org.spongepowered.api.data.manipulator.ImmutableDataManipulator)2 ItemStack (org.spongepowered.api.item.inventory.ItemStack)2 DataProcessor (org.spongepowered.common.data.DataProcessor)2 ValueProcessor (org.spongepowered.common.data.ValueProcessor)2 SerializedDataTransaction (org.spongepowered.common.data.persistence.SerializedDataTransaction)2