use of org.spongepowered.api.data.manipulator.ImmutableDataManipulator in project LanternServer by LanternPowered.
the class LanternBlockState method merge.
@Override
public BlockState merge(BlockState that, MergeFunction function) {
if (!getType().equals(that.getType())) {
return this;
} else {
BlockState temp = this;
for (ImmutableDataManipulator<?, ?> manipulator : that.getManipulators()) {
final ImmutableDataManipulator old = temp.get(manipulator.getClass()).orElse(null);
final 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.data.manipulator.ImmutableDataManipulator in project SpongeCommon by SpongePowered.
the class SpongeBlockSnapshot method with.
@Override
public Optional<BlockSnapshot> with(ImmutableDataManipulator<?, ?> valueContainer) {
if (((IMixinBlock) this.blockState.getType()).supports((Class<ImmutableDataManipulator<?, ?>>) valueContainer.getClass())) {
final BlockState newState;
boolean changeState = false;
if (this.blockState.supports((Class<ImmutableDataManipulator<?, ?>>) valueContainer.getClass())) {
newState = this.blockState.with(valueContainer).get();
changeState = true;
} else {
newState = this.blockState;
}
if (changeState) {
return Optional.of(createBuilder().blockState(newState).build());
}
final SpongeBlockSnapshotBuilder builder = createBuilder();
builder.add(valueContainer);
return Optional.of(builder.build());
}
return Optional.of(createBuilder().add(valueContainer).build());
}
use of org.spongepowered.api.data.manipulator.ImmutableDataManipulator in project SpongeCommon by SpongePowered.
the class MixinWorld_Data method supports.
@Override
public boolean supports(int x, int y, int z, Class<? extends DataManipulator<?, ?>> manipulatorClass) {
final BlockState blockState = getBlock(x, y, z);
final List<ImmutableDataManipulator<?, ?>> immutableDataManipulators = blockState.getManipulators();
boolean blockSupports = false;
for (ImmutableDataManipulator<?, ?> manipulator : immutableDataManipulators) {
if (manipulator.asMutable().getClass().isAssignableFrom(manipulatorClass)) {
blockSupports = true;
break;
}
}
if (!blockSupports) {
final Optional<TileEntity> tileEntity = getTileEntity(x, y, z);
final boolean tileEntitySupports;
tileEntitySupports = tileEntity.isPresent() && tileEntity.get().supports(manipulatorClass);
return tileEntitySupports;
}
return true;
}
Aggregations