Search in sources :

Example 1 with Facing

use of team.creative.creativecore.common.util.math.base.Facing in project CreativeCore by CreativeMD.

the class BoxUtils method includeMaxRotationInBox.

private static void includeMaxRotationInBox(IncludeBox box, Vec3d vec, Axis axis, CollisionCoordinator coordinator) {
    double rotation = coordinator.getRotationDegree(axis);
    if (rotation == 0)
        return;
    Matrix3 matrix = coordinator.getRotationMatrix(axis);
    Double length = null;
    BooleanRotation state = BooleanRotation.get(axis, vec);
    boolean positive = rotation > 0;
    int quarterRotation = 90;
    if (rotation >= 90) {
        while (quarterRotation <= Math.abs(rotation) && quarterRotation < 360) {
            Facing facing = positive ? state.clockwiseMaxFacing() : state.counterMaxClockwiseFacing();
            if (length == null)
                length = lengthIgnoreAxis(vec, axis);
            box.include(facing, length);
            if (coordinator.translation != null)
                box.include(facing, length + coordinator.translation.get(facing.axis));
            state = state.clockwise();
            quarterRotation += 90;
        }
    }
    matrix.transform(vec);
    box.include(vec);
    if (quarterRotation <= 360 && !state.is(vec)) {
        Facing facing = positive ? state.clockwiseMaxFacing() : state.counterMaxClockwiseFacing();
        if (length == null)
            length = lengthIgnoreAxis(vec, axis);
        box.include(facing, length);
        if (coordinator.translation != null)
            box.include(facing, length + coordinator.translation.get(facing.axis));
    }
}
Also used : BooleanRotation(team.creative.creativecore.common.util.math.transformation.BooleanRotation) Facing(team.creative.creativecore.common.util.math.base.Facing) Matrix3(team.creative.creativecore.common.util.math.matrix.Matrix3)

Example 2 with Facing

use of team.creative.creativecore.common.util.math.base.Facing 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

Facing (team.creative.creativecore.common.util.math.base.Facing)2 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 Matrix3 (team.creative.creativecore.common.util.math.matrix.Matrix3)1 BooleanRotation (team.creative.creativecore.common.util.math.transformation.BooleanRotation)1 SingletonList (team.creative.creativecore.common.util.type.list.SingletonList)1