Search in sources :

Example 1 with SingletonList

use of team.creative.creativecore.common.util.type.list.SingletonList in project CreativeCore by CreativeMD.

the class BlockUpdateLevelSystem method blockChanged.

public void blockChanged(BlockPos pos) {
    BlockState state = level.getBlockState(pos);
    if (state.isAir()) {
        // Shrinking
        if (allBlocks.remove(pos) && edgePositions.remove(pos)) {
            for (int i = 0; i < Facing.values().length; i++) {
                Facing facing = Facing.values()[i];
                Axis axis = facing.axis.toVanilla();
                int bound = getBound(facing);
                if (bound == pos.get(axis)) {
                    List<BlockPos> remaining = new ArrayList<>();
                    for (BlockPos edge : edgePositions) if (edge.get(axis) == bound)
                        remaining.add(edge);
                    if (remaining.isEmpty()) {
                        int newBound = facing.positive ? Integer.MIN_VALUE : Integer.MAX_VALUE;
                        for (BlockPos scan : allBlocks) newBound = facing.positive ? Math.max(newBound, scan.get(axis)) : Math.min(newBound, scan.get(axis));
                        for (BlockPos scan : allBlocks) if (scan.get(axis) == newBound) {
                            remaining.add(scan);
                            edgePositions.add(scan);
                        }
                        setBound(facing, newBound);
                    }
                    levelBoundListeners.forEach(x -> x.rescan(level, this, facing, remaining, facing.positive ? bound + 1 : bound));
                }
            }
        }
    } else if (allBlocks.add(pos) && !isWithinBoundsNoEdge(pos)) {
        // Expanding
        for (int i = 0; i < Facing.values().length; i++) {
            Facing facing = Facing.values()[i];
            Axis axis = facing.axis.toVanilla();
            int bound = getBound(facing);
            if (bound == pos.get(axis)) {
                List<BlockPos> remaining = new ArrayList<>();
                edgePositions.add(pos);
                for (BlockPos edge : edgePositions) if (edge.get(axis) == bound)
                    remaining.add(edge);
                levelBoundListeners.forEach(x -> x.rescan(level, this, facing, remaining, facing.positive ? bound + 1 : bound));
            } else if (bound > pos.get(axis)) {
                for (Iterator<BlockPos> itr = edgePositions.iterator(); itr.hasNext(); ) {
                    BlockPos edge = itr.next();
                    if (edge.get(axis) == bound && !isEdgeExcept(edge, facing))
                        itr.remove();
                }
                edgePositions.add(pos);
                levelBoundListeners.forEach(x -> x.rescan(level, this, facing, new SingletonList<>(pos), facing.positive ? bound + 1 : bound));
            }
        }
    }
}
Also used : HashSet(java.util.HashSet) Axis(net.minecraft.core.Direction.Axis) List(java.util.List) Facing(team.creative.creativecore.common.util.math.base.Facing) Iterator(java.util.Iterator) BlockPos(net.minecraft.core.BlockPos) SingletonList(team.creative.creativecore.common.util.type.list.SingletonList) BlockState(net.minecraft.world.level.block.state.BlockState) CreativeLevel(team.creative.creativecore.common.level.CreativeLevel) LevelBoundsListener(team.creative.creativecore.common.level.listener.LevelBoundsListener) ArrayList(java.util.ArrayList) Facing(team.creative.creativecore.common.util.math.base.Facing) BlockState(net.minecraft.world.level.block.state.BlockState) SingletonList(team.creative.creativecore.common.util.type.list.SingletonList) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.core.BlockPos) List(java.util.List) SingletonList(team.creative.creativecore.common.util.type.list.SingletonList) ArrayList(java.util.ArrayList) Axis(net.minecraft.core.Direction.Axis)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 BlockPos (net.minecraft.core.BlockPos)1 Axis (net.minecraft.core.Direction.Axis)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 CreativeLevel (team.creative.creativecore.common.level.CreativeLevel)1 LevelBoundsListener (team.creative.creativecore.common.level.listener.LevelBoundsListener)1 Facing (team.creative.creativecore.common.util.math.base.Facing)1 SingletonList (team.creative.creativecore.common.util.type.list.SingletonList)1