Search in sources :

Example 21 with BlockState

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);
}
Also used : TreeType(org.spongepowered.api.data.type.TreeType) BlockState(org.spongepowered.api.block.BlockState) IBlockState(net.minecraft.block.state.IBlockState) BlockPlanks(net.minecraft.block.BlockPlanks)

Example 22 with BlockState

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;
}
Also used : IMixinBlockState(org.spongepowered.common.interfaces.block.IMixinBlockState) BlockState(org.spongepowered.api.block.BlockState) Nullable(javax.annotation.Nullable)

Example 23 with BlockState

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();
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) IMixinTileEntity(org.spongepowered.common.interfaces.block.tile.IMixinTileEntity) BlockState(org.spongepowered.api.block.BlockState) IBlockState(net.minecraft.block.state.IBlockState) SpongeBlockSnapshotBuilder(org.spongepowered.common.block.SpongeBlockSnapshotBuilder) Vector3i(com.flowpowered.math.vector.Vector3i) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) World(org.spongepowered.api.world.World) IMixinWorld(org.spongepowered.common.interfaces.world.IMixinWorld) UUID(java.util.UUID) IMixinCustomDataHolder(org.spongepowered.common.interfaces.data.IMixinCustomDataHolder)

Example 24 with BlockState

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);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IMixinCustomDataHolder(org.spongepowered.common.interfaces.data.IMixinCustomDataHolder) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) IMixinTileEntity(org.spongepowered.common.interfaces.block.tile.IMixinTileEntity) SpongeBlockSnapshot(org.spongepowered.common.block.SpongeBlockSnapshot) ITileEntityProvider(net.minecraft.block.ITileEntityProvider) BlockState(org.spongepowered.api.block.BlockState) IBlockState(net.minecraft.block.state.IBlockState) UUID(java.util.UUID)

Example 25 with BlockState

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);
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) MutableBlockVolume(org.spongepowered.api.world.extent.MutableBlockVolume) BlockState(org.spongepowered.api.block.BlockState) SpongeArchetypeVolume(org.spongepowered.common.world.schematic.SpongeArchetypeVolume) Extent(org.spongepowered.api.world.extent.Extent) Vector3i(com.flowpowered.math.vector.Vector3i) BimapPalette(org.spongepowered.common.world.schematic.BimapPalette) TileEntityArchetype(org.spongepowered.api.block.tileentity.TileEntityArchetype) ArrayMutableBlockBuffer(org.spongepowered.common.util.gen.ArrayMutableBlockBuffer)

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