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;
}
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();
}
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);
}
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();
}
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;
}
Aggregations