use of org.spongepowered.api.block.BlockState in project SpongeCommon by SpongePowered.
the class MixinBlockLog method getStateWithValue.
@Override
public <E> Optional<BlockState> getStateWithValue(IBlockState blockState, Key<? extends BaseValue<E>> key, E value) {
if (key.equals(Keys.TREE_TYPE)) {
final TreeType treeType = (TreeType) value;
final BlockPlanks.EnumType type = TreeTypeResolver.getFor(treeType);
return processLogType(blockState, type, treeType);
} else if (key.equals(Keys.LOG_AXIS)) {
return Optional.of((BlockState) blockState.withProperty(BlockLog.LOG_AXIS, (BlockLog.EnumAxis) value));
}
return super.getStateWithValue(blockState, key, value);
}
use of org.spongepowered.api.block.BlockState in project SpongeCommon by SpongePowered.
the class MixinStateImplementation method merge.
@Override
public BlockState merge(BlockState that, MergeFunction function) {
if (!getType().equals(that.getType())) {
return this;
}
BlockState temp = this;
for (ImmutableDataManipulator<?, ?> manipulator : that.getManipulators()) {
@Nullable ImmutableDataManipulator<?, ?> old = temp.get(manipulator.getClass()).orElse(null);
Optional<BlockState> optional = temp.with(checkNotNull(function.merge(old, manipulator)));
if (optional.isPresent()) {
temp = optional.get();
} else {
return temp;
}
}
return temp;
}
use of org.spongepowered.api.block.BlockState 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.api.block.BlockState 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.api.block.BlockState in project SpongeCommon by SpongePowered.
the class DefaultedExtent method createArchetypeVolume.
@Override
default ArchetypeVolume createArchetypeVolume(Vector3i min, Vector3i max, Vector3i origin) {
Vector3i tmin = min.min(max);
Vector3i tmax = max.max(min);
min = tmin;
max = tmax;
Extent volume = getExtentView(min, max);
BimapPalette palette = new BimapPalette();
volume.getBlockWorker().iterate((v, x, y, z) -> {
palette.getOrAssign(v.getBlock(x, y, z));
});
int ox = origin.getX();
int oy = origin.getY();
int oz = origin.getZ();
final MutableBlockVolume backing = new ArrayMutableBlockBuffer(min.sub(origin), max.sub(min).add(1, 1, 1));
Map<Vector3i, TileEntityArchetype> tiles = Maps.newHashMap();
volume.getBlockWorker().iterate((extent, x, y, z) -> {
BlockState state = extent.getBlock(x, y, z);
backing.setBlock(x - ox, y - oy, z - oz, state);
Optional<TileEntity> tile = extent.getTileEntity(x, y, z);
if (tile.isPresent()) {
tiles.put(new Vector3i(x - ox, y - oy, z - oz), tile.get().createArchetype());
}
});
return new SpongeArchetypeVolume(backing, tiles);
}
Aggregations