Search in sources :

Example 86 with BlockState

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);
}
Also used : SpongeImpl(org.spongepowered.common.SpongeImpl) Value(org.spongepowered.api.data.value.mutable.Value) ImmutableDataManipulator(org.spongepowered.api.data.manipulator.ImmutableDataManipulator) ImmutableValue(org.spongepowered.api.data.value.immutable.ImmutableValue) DataTransactionResult(org.spongepowered.api.data.DataTransactionResult) PropertyStore(org.spongepowered.api.data.property.PropertyStore) Key(org.spongepowered.api.data.key.Key) ArrayList(java.util.ArrayList) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) ImmutableList(com.google.common.collect.ImmutableList) Mixin(org.spongepowered.asm.mixin.Mixin) MergeFunction(org.spongepowered.api.data.merge.MergeFunction) Location(org.spongepowered.api.world.Location) ImmutableSet(com.google.common.collect.ImmutableSet) DirectionFacingProvider(org.spongepowered.common.registry.provider.DirectionFacingProvider) Collection(java.util.Collection) BaseValue(org.spongepowered.api.data.value.BaseValue) EnumFacing(net.minecraft.util.EnumFacing) Sponge(org.spongepowered.api.Sponge) Set(java.util.Set) InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException) DataHolder(org.spongepowered.api.data.DataHolder) BlockState(org.spongepowered.api.block.BlockState) Direction(org.spongepowered.api.util.Direction) List(java.util.List) DataView(org.spongepowered.api.data.DataView) World(org.spongepowered.api.world.World) Property(org.spongepowered.api.data.Property) DataManipulator(org.spongepowered.api.data.manipulator.DataManipulator) Optional(java.util.Optional) Collections(java.util.Collections) BlockState(org.spongepowered.api.block.BlockState) Value(org.spongepowered.api.data.value.mutable.Value) ImmutableValue(org.spongepowered.api.data.value.immutable.ImmutableValue) BaseValue(org.spongepowered.api.data.value.BaseValue) DataTransactionResult(org.spongepowered.api.data.DataTransactionResult)

Example 87 with BlockState

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;
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) BlockState(org.spongepowered.api.block.BlockState) ImmutableDataManipulator(org.spongepowered.api.data.manipulator.ImmutableDataManipulator)

Example 88 with BlockState

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());
}
Also used : WorldGenConstants(org.spongepowered.common.world.gen.WorldGenConstants) BiomeHills(net.minecraft.world.biome.BiomeHills) Blocks(net.minecraft.init.Blocks) SpongeBiomeGenerationSettings(org.spongepowered.common.world.biome.SpongeBiomeGenerationSettings) BiomeTreeTypes(org.spongepowered.api.world.gen.type.BiomeTreeTypes) World(net.minecraft.world.World) BiomeDecorator(net.minecraft.world.biome.BiomeDecorator) Forest(org.spongepowered.api.world.gen.populator.Forest) GroundCoverLayer(org.spongepowered.api.world.biome.GroundCoverLayer) SeededVariableAmount(org.spongepowered.api.util.weighted.SeededVariableAmount) VariableAmount(org.spongepowered.api.util.weighted.VariableAmount) Final(org.spongepowered.asm.mixin.Final) BlockState(org.spongepowered.api.block.BlockState) IBlockState(net.minecraft.block.state.IBlockState) Ore(org.spongepowered.api.world.gen.populator.Ore) Mixin(org.spongepowered.asm.mixin.Mixin) RandomBlock(org.spongepowered.api.world.gen.populator.RandomBlock) Shadow(org.spongepowered.asm.mixin.Shadow) BlockSilverfish(net.minecraft.block.BlockSilverfish) RandomBlock(org.spongepowered.api.world.gen.populator.RandomBlock) IBlockState(net.minecraft.block.state.IBlockState) Ore(org.spongepowered.api.world.gen.populator.Ore) Forest(org.spongepowered.api.world.gen.populator.Forest) GroundCoverLayer(org.spongepowered.api.world.biome.GroundCoverLayer) BiomeDecorator(net.minecraft.world.biome.BiomeDecorator)

Example 89 with BlockState

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);
                }
            }
        }
    }
}
Also used : BlockState(org.spongepowered.api.block.BlockState) Vector3i(com.flowpowered.math.vector.Vector3i)

Example 90 with BlockState

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());
}
Also used : BlockState(org.spongepowered.api.block.BlockState) InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException) UUID(java.util.UUID)

Aggregations

BlockState (org.spongepowered.api.block.BlockState)133 World (org.spongepowered.api.world.World)39 IBlockState (net.minecraft.block.state.IBlockState)29 BlockType (org.spongepowered.api.block.BlockType)27 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)22 Direction (org.spongepowered.api.util.Direction)21 Optional (java.util.Optional)20 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)20 Vector3i (com.flowpowered.math.vector.Vector3i)19 Location (org.spongepowered.api.world.Location)18 ItemStack (org.spongepowered.api.item.inventory.ItemStack)17 LocatableBlock (org.spongepowered.api.world.LocatableBlock)14 Sponge (org.spongepowered.api.Sponge)13 ItemType (org.spongepowered.api.item.ItemType)13 ArrayList (java.util.ArrayList)12 Player (org.spongepowered.api.entity.living.player.Player)12 List (java.util.List)11 InvalidDataException (org.spongepowered.api.data.persistence.InvalidDataException)11 Vector3d (com.flowpowered.math.vector.Vector3d)10 Listener (org.spongepowered.api.event.Listener)10