use of org.spongepowered.api.block.BlockState in project SpongeCommon by SpongePowered.
the class MixinWorld_Data method getKeys.
@Override
public Set<Key<?>> getKeys(int x, int y, int z) {
final ImmutableSet.Builder<Key<?>> builder = ImmutableSet.builder();
final BlockState blockState = getBlock(x, y, z).withExtendedProperties(new Location<>(this, x, y, z));
builder.addAll(blockState.getKeys());
final Optional<TileEntity> tileEntity = getTileEntity(x, y, z);
if (tileEntity.isPresent()) {
builder.addAll(tileEntity.get().getKeys());
}
return builder.build();
}
use of org.spongepowered.api.block.BlockState in project SpongeCommon by SpongePowered.
the class MixinWorld_Data method supports.
@Override
public boolean supports(int x, int y, int z, Key<?> key) {
final BlockState blockState = getBlock(x, y, z);
final boolean blockSupports = blockState.supports(key);
final Optional<TileEntity> tileEntity = getTileEntity(x, y, z);
final boolean tileEntitySupports = tileEntity.isPresent() && tileEntity.get().supports(key);
return blockSupports || tileEntitySupports;
}
use of org.spongepowered.api.block.BlockState in project SpongeCommon by SpongePowered.
the class MixinWorld_Data method getValue.
@Override
public <E, V extends BaseValue<E>> Optional<V> getValue(int x, int y, int z, Key<V> key) {
final BlockState blockState = getBlock(x, y, z).withExtendedProperties(new Location<>(this, x, y, z));
if (blockState.supports(key)) {
return blockState.getValue(key);
}
final Optional<TileEntity> tileEntity = getTileEntity(x, y, z);
if (tileEntity.isPresent() && tileEntity.get().supports(key)) {
return tileEntity.get().getValue(key);
}
return Optional.empty();
}
use of org.spongepowered.api.block.BlockState in project SpongeCommon by SpongePowered.
the class MixinWorld_Data method offer.
@Override
public DataTransactionResult offer(int x, int y, int z, DataManipulator<?, ?> manipulator, MergeFunction function) {
final BlockState blockState = getBlock(x, y, z).withExtendedProperties(new Location<>(this, x, y, z));
final ImmutableDataManipulator<?, ?> immutableDataManipulator = manipulator.asImmutable();
if (blockState.supports((Class) immutableDataManipulator.getClass())) {
final List<ImmutableValue<?>> old = new ArrayList<>(blockState.getValues());
final BlockState newState = blockState.with(immutableDataManipulator).get();
old.removeAll(newState.getValues());
setBlock(x, y, z, newState);
return DataTransactionResult.successReplaceResult(old, manipulator.getValues());
}
return getTileEntity(x, y, z).map(tileEntity -> tileEntity.offer(manipulator, function)).orElseGet(() -> DataTransactionResult.failResult(manipulator.getValues()));
}
use of org.spongepowered.api.block.BlockState in project SpongeCommon by SpongePowered.
the class MixinWorld_Data method getValues.
@Override
public Set<ImmutableValue<?>> getValues(int x, int y, int z) {
final ImmutableSet.Builder<ImmutableValue<?>> builder = ImmutableSet.builder();
final BlockState blockState = getBlock(x, y, z).withExtendedProperties(new Location<>(this, x, y, z));
builder.addAll(blockState.getValues());
final Optional<TileEntity> tileEntity = getTileEntity(x, y, z);
if (tileEntity.isPresent()) {
builder.addAll(tileEntity.get().getValues());
}
return builder.build();
}
Aggregations