use of org.spongepowered.api.block.BlockState in project SpongeCommon by SpongePowered.
the class MixinWorld_Data method offer.
@Override
public <E> DataTransactionResult offer(int x, int y, int z, Key<? extends BaseValue<E>> key, E value) {
final BlockState blockState = getBlock(x, y, z).withExtendedProperties(new Location<>(this, x, y, z));
if (blockState.supports(key)) {
ImmutableValue<E> old = ((Value<E>) getValue(x, y, z, (Key) key).get()).asImmutable();
setBlock(x, y, z, blockState.with(key, value).get());
ImmutableValue<E> newVal = ((Value<E>) getValue(x, y, z, (Key) key).get()).asImmutable();
return DataTransactionResult.successReplaceResult(newVal, old);
}
return getTileEntity(x, y, z).map(tileEntity -> tileEntity.offer(key, value)).orElseGet(DataTransactionResult::failNoData);
}
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, 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;
}
use of org.spongepowered.api.block.BlockState in project SpongeCommon by SpongePowered.
the class MixinBiomeHills method buildPopulators.
@Override
public void buildPopulators(World world, SpongeBiomeGenerationSettings gensettings) {
super.buildPopulators(world, gensettings);
gensettings.getGroundCoverLayers().clear();
gensettings.getGroundCoverLayers().add(new GroundCoverLayer((stoneNoise) -> {
IBlockState result = Blocks.GRASS.getDefaultState();
if ((stoneNoise < -1.0D || stoneNoise > 2.0D) && this.type == BiomeHills.Type.MUTATED) {
result = Blocks.GRAVEL.getDefaultState();
} else if (stoneNoise > 1.0D && this.type != BiomeHills.Type.EXTRA_TREES) {
result = Blocks.STONE.getDefaultState();
}
return (BlockState) result;
}, SeededVariableAmount.fixed(1)));
gensettings.getGroundCoverLayers().add(new GroundCoverLayer((stoneNoise) -> {
IBlockState result = Blocks.DIRT.getDefaultState();
if ((stoneNoise < -1.0D || stoneNoise > 2.0D) && this.type == BiomeHills.Type.MUTATED) {
result = Blocks.GRAVEL.getDefaultState();
} else if (stoneNoise > 1.0D && this.type != BiomeHills.Type.EXTRA_TREES) {
result = Blocks.STONE.getDefaultState();
}
return (BlockState) result;
}, WorldGenConstants.GROUND_COVER_DEPTH));
BiomeDecorator theBiomeDecorator = this.decorator;
RandomBlock emerald = RandomBlock.builder().block((BlockState) Blocks.EMERALD_ORE.getDefaultState()).placementTarget(WorldGenConstants.STONE_LOCATION).perChunk(VariableAmount.baseWithRandomAddition(3, 6)).height(VariableAmount.baseWithRandomAddition(4, 28)).build();
gensettings.getPopulators().add(emerald);
Ore silverfish = Ore.builder().ore((BlockState) Blocks.MONSTER_EGG.getDefaultState().withProperty(BlockSilverfish.VARIANT, BlockSilverfish.EnumType.STONE)).perChunk(7).height(VariableAmount.baseWithRandomAddition(0, 64)).size(9).build();
gensettings.getPopulators().add(silverfish);
gensettings.getPopulators().removeAll(gensettings.getPopulators(Forest.class));
Forest.Builder forest = Forest.builder();
forest.perChunk(VariableAmount.baseWithOptionalAddition(theBiomeDecorator.treesPerChunk, 1, 0.1));
forest.type(BiomeTreeTypes.TALL_TAIGA.getPopulatorObject(), 20);
forest.type(BiomeTreeTypes.OAK.getPopulatorObject(), 9);
forest.type(BiomeTreeTypes.OAK.getLargePopulatorObject().get(), 1);
gensettings.getPopulators().add(0, forest.build());
}
use of org.spongepowered.api.block.BlockState in project SpongeCommon by SpongePowered.
the class EndBiomeGenerationPopulator method populate.
@Override
public void populate(World world, MutableBlockVolume buffer, ImmutableBiomeVolume biomes) {
Vector3i min = buffer.getBlockMin();
Vector3i max = buffer.getBlockMax();
BlockState iblockstate = BlockTypes.END_STONE.getDefaultState();
for (int x = min.getX(); x <= max.getX(); ++x) {
for (int z = min.getZ(); z <= max.getZ(); ++z) {
for (int y = max.getY(); y >= min.getY(); --y) {
BlockState iblockstate2 = buffer.getBlock(x, y, z);
if (iblockstate2.getType() == BlockTypes.STONE) {
buffer.setBlock(x, y, z, iblockstate);
}
}
}
}
}
use of org.spongepowered.api.block.BlockState in project SpongeCommon by SpongePowered.
the class SpongeLocatableBlockBuilder method buildContent.
@Override
protected Optional<LocatableBlock> buildContent(DataView container) throws InvalidDataException {
final int x = container.getInt(Queries.POSITION_X).orElseThrow(() -> new InvalidDataException("Could not locate an \"x\" coordinate in the container!"));
final int y = container.getInt(Queries.POSITION_Y).orElseThrow(() -> new InvalidDataException("Could not locate an \"y\" coordinate in the container!"));
final int z = container.getInt(Queries.POSITION_Z).orElseThrow(() -> new InvalidDataException("Could not locate an \"z\" coordinate in the container!"));
final BlockState blockState = container.getCatalogType(DataQueries.BLOCK_STATE, BlockState.class).orElseThrow(() -> new InvalidDataException("Could not locate a BlockState"));
final UUID worldId = container.getObject(Queries.WORLD_ID, UUID.class).orElseThrow(() -> new InvalidDataException("Could not locate a UUID"));
return Sponge.getServer().getWorld(worldId).map(world -> new SpongeLocatableBlockBuilder().position(x, y, z).world(world).state(blockState).build());
}
Aggregations