Search in sources :

Example 6 with IMixinCustomDataHolder

use of org.spongepowered.common.interfaces.data.IMixinCustomDataHolder in project SpongeCommon by SpongePowered.

the class MixinEntity method toContainer.

@Override
public DataContainer toContainer() {
    final Transform<World> transform = getTransform();
    final NBTTagCompound compound = new NBTTagCompound();
    writeToNBT(compound);
    // We must filter the custom data so it isn't stored twice
    NbtDataUtil.filterSpongeCustomData(compound);
    final DataContainer unsafeNbt = NbtTranslator.getInstance().translateFrom(compound);
    final DataContainer container = DataContainer.createNew().set(Queries.CONTENT_VERSION, getContentVersion()).set(DataQueries.ENTITY_CLASS, this.getClass().getName()).set(Queries.WORLD_ID, transform.getExtent().getUniqueId().toString()).createView(DataQueries.SNAPSHOT_WORLD_POSITION).set(Queries.POSITION_X, transform.getPosition().getX()).set(Queries.POSITION_Y, transform.getPosition().getY()).set(Queries.POSITION_Z, transform.getPosition().getZ()).getContainer().createView(DataQueries.ENTITY_ROTATION).set(Queries.POSITION_X, transform.getRotation().getX()).set(Queries.POSITION_Y, transform.getRotation().getY()).set(Queries.POSITION_Z, transform.getRotation().getZ()).getContainer().createView(DataQueries.ENTITY_SCALE).set(Queries.POSITION_X, transform.getScale().getX()).set(Queries.POSITION_Y, transform.getScale().getY()).set(Queries.POSITION_Z, transform.getScale().getZ()).getContainer().set(DataQueries.ENTITY_TYPE, this.entityType.getId()).set(DataQueries.UNSAFE_NBT, unsafeNbt);
    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 7 with IMixinCustomDataHolder

use of org.spongepowered.common.interfaces.data.IMixinCustomDataHolder in project SpongeCommon by SpongePowered.

the class MixinWorld method createSnapshot.

@Override
public BlockSnapshot createSnapshot(int x, int y, int z) {
    if (!containsBlock(x, y, z)) {
        return BlockSnapshot.NONE;
    }
    World world = this;
    BlockState state = world.getBlock(x, y, z);
    Optional<TileEntity> te = world.getTileEntity(x, y, z);
    SpongeBlockSnapshotBuilder builder = new SpongeBlockSnapshotBuilder().blockState(state).worldId(world.getUniqueId()).position(new Vector3i(x, y, z));
    Optional<UUID> creator = getCreator(x, y, z);
    Optional<UUID> notifier = getNotifier(x, y, z);
    if (creator.isPresent()) {
        builder.creator(creator.get());
    }
    if (notifier.isPresent()) {
        builder.notifier(notifier.get());
    }
    if (te.isPresent()) {
        final TileEntity tileEntity = te.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) IMixinTileEntity(org.spongepowered.common.interfaces.block.tile.IMixinTileEntity) BlockState(org.spongepowered.api.block.BlockState) IBlockState(net.minecraft.block.state.IBlockState) SpongeBlockSnapshotBuilder(org.spongepowered.common.block.SpongeBlockSnapshotBuilder) Vector3i(com.flowpowered.math.vector.Vector3i) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) World(org.spongepowered.api.world.World) IMixinWorld(org.spongepowered.common.interfaces.world.IMixinWorld) UUID(java.util.UUID) IMixinCustomDataHolder(org.spongepowered.common.interfaces.data.IMixinCustomDataHolder)

Example 8 with IMixinCustomDataHolder

use of org.spongepowered.common.interfaces.data.IMixinCustomDataHolder in project SpongeCommon by SpongePowered.

the class MixinWorldServer method createSpongeBlockSnapshot.

@Override
public SpongeBlockSnapshot createSpongeBlockSnapshot(IBlockState state, IBlockState extended, BlockPos pos, BlockChangeFlag updateFlag) {
    this.builder.reset();
    this.builder.blockState((BlockState) state).extendedState((BlockState) extended).worldId(this.getUniqueId()).position(VecHelper.toVector3i(pos));
    Optional<UUID> creator = getCreator(pos.getX(), pos.getY(), pos.getZ());
    Optional<UUID> notifier = getNotifier(pos.getX(), pos.getY(), pos.getZ());
    if (creator.isPresent()) {
        this.builder.creator(creator.get());
    }
    if (notifier.isPresent()) {
        this.builder.notifier(notifier.get());
    }
    if (state.getBlock() instanceof ITileEntityProvider) {
        // We MUST only check to see if a TE exists to avoid creating a new one.
        final net.minecraft.tileentity.TileEntity te = this.getChunkFromBlockCoords(pos).getTileEntity(pos, net.minecraft.world.chunk.Chunk.EnumCreateEntityType.CHECK);
        if (te != null) {
            TileEntity tile = (TileEntity) te;
            for (DataManipulator<?, ?> manipulator : ((IMixinCustomDataHolder) tile).getCustomManipulators()) {
                this.builder.add(manipulator);
            }
            NBTTagCompound nbt = new NBTTagCompound();
            // Some mods like OpenComputers assert if attempting to save robot while moving
            try {
                te.writeToNBT(nbt);
                this.builder.unsafeNbt(nbt);
            } catch (Throwable t) {
            // ignore
            }
        }
    }
    return new SpongeBlockSnapshot(this.builder, (SpongeBlockChangeFlag) updateFlag);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IMixinCustomDataHolder(org.spongepowered.common.interfaces.data.IMixinCustomDataHolder) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) IMixinTileEntity(org.spongepowered.common.interfaces.block.tile.IMixinTileEntity) SpongeBlockSnapshot(org.spongepowered.common.block.SpongeBlockSnapshot) ITileEntityProvider(net.minecraft.block.ITileEntityProvider) BlockState(org.spongepowered.api.block.BlockState) IBlockState(net.minecraft.block.state.IBlockState) UUID(java.util.UUID)

Example 9 with IMixinCustomDataHolder

use of org.spongepowered.common.interfaces.data.IMixinCustomDataHolder in project SpongeForge by SpongePowered.

the class MixinBlockSnapshot method createSpongeBlockSnapshot.

@Override
public BlockSnapshot createSpongeBlockSnapshot() {
    Location<World> location = new Location<>((World) this.getWorld(), VecHelper.toVector3i(this.pos));
    SpongeBlockSnapshotBuilder builder = new SpongeBlockSnapshotBuilder();
    builder.blockState((BlockState) this.replacedBlock).worldId(location.getExtent().getUniqueId()).position(location.getBlockPosition());
    if (this.nbt != null) {
        builder.unsafeNbt(this.nbt);
    }
    TileEntity te = getTileEntity();
    if (te != null) {
        if (!te.hasWorld()) {
            te.setWorld(this.getWorld());
        }
        for (DataManipulator<?, ?> manipulator : ((IMixinCustomDataHolder) te).getCustomManipulators()) {
            builder.add(manipulator);
        }
    }
    return builder.build();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) SpongeBlockSnapshotBuilder(org.spongepowered.common.block.SpongeBlockSnapshotBuilder) World(org.spongepowered.api.world.World) IMixinCustomDataHolder(org.spongepowered.common.interfaces.data.IMixinCustomDataHolder) Location(org.spongepowered.api.world.Location)

Example 10 with IMixinCustomDataHolder

use of org.spongepowered.common.interfaces.data.IMixinCustomDataHolder in project SpongeCommon by SpongePowered.

the class SpongeEntitySnapshotBuilder method from.

public SpongeEntitySnapshotBuilder from(net.minecraft.entity.Entity minecraftEntity) {
    this.entityType = ((Entity) minecraftEntity).getType();
    this.worldId = ((Entity) minecraftEntity).getWorld().getUniqueId();
    this.entityId = minecraftEntity.getUniqueID();
    final Transform<World> transform = ((Entity) minecraftEntity).getTransform();
    this.position = transform.getPosition();
    this.rotation = transform.getRotation();
    this.scale = transform.getScale();
    this.manipulators = Lists.newArrayList();
    for (DataManipulator<?, ?> manipulator : ((IMixinCustomDataHolder) minecraftEntity).getCustomManipulators()) {
        addManipulator(manipulator.asImmutable());
    }
    this.compound = new NBTTagCompound();
    minecraftEntity.writeToNBT(this.compound);
    return this;
}
Also used : Entity(org.spongepowered.api.entity.Entity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) World(org.spongepowered.api.world.World) 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