Search in sources :

Example 1 with UpdatesWithNeighboursFamily

use of org.terasology.world.block.family.UpdatesWithNeighboursFamily in project Terasology by MovingBlocks.

the class NeighbourBlockFamilyUpdateSystem method processUpdateForBlockLocation.

private void processUpdateForBlockLocation(Vector3i blockLocation) {
    for (Side side : Side.values()) {
        Vector3i neighborLocation = new Vector3i(blockLocation);
        neighborLocation.add(side.getVector3i());
        if (worldProvider.isBlockRelevant(neighborLocation)) {
            Block neighborBlock = worldProvider.getBlock(neighborLocation);
            final BlockFamily blockFamily = neighborBlock.getBlockFamily();
            if (blockFamily instanceof UpdatesWithNeighboursFamily) {
                UpdatesWithNeighboursFamily neighboursFamily = (UpdatesWithNeighboursFamily) blockFamily;
                Block neighborBlockAfterUpdate = neighboursFamily.getBlockForNeighborUpdate(worldProvider, blockEntityRegistry, neighborLocation, neighborBlock);
                if (neighborBlock != neighborBlockAfterUpdate) {
                    worldProvider.setBlock(neighborLocation, neighborBlockAfterUpdate);
                }
            }
        }
    }
}
Also used : Side(org.terasology.math.Side) UpdatesWithNeighboursFamily(org.terasology.world.block.family.UpdatesWithNeighboursFamily) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) OnChangedBlock(org.terasology.world.OnChangedBlock) BlockFamily(org.terasology.world.block.family.BlockFamily)

Aggregations

Side (org.terasology.math.Side)1 Vector3i (org.terasology.math.geom.Vector3i)1 OnChangedBlock (org.terasology.world.OnChangedBlock)1 Block (org.terasology.world.block.Block)1 BlockFamily (org.terasology.world.block.family.BlockFamily)1 UpdatesWithNeighboursFamily (org.terasology.world.block.family.UpdatesWithNeighboursFamily)1