• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CyclopsMC / IntegratedDynamics / 20210191346

14 Dec 2025 03:32PM UTC coverage: 19.514% (-33.5%) from 53.061%
20210191346

push

github

rubensworks
Remove deprecations

663 of 8728 branches covered (7.6%)

Branch coverage included in aggregate %.

6786 of 29445 relevant lines covered (23.05%)

1.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

23.08
/src/main/java/org/cyclops/integrateddynamics/block/shapes/VoxelShapeComponentsFactoryHandlerCableConnections.java
1
package org.cyclops.integrateddynamics.block.shapes;
2

3
import com.google.common.collect.Lists;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.core.Direction;
6
import net.minecraft.world.InteractionHand;
7
import net.minecraft.world.InteractionResult;
8
import net.minecraft.world.entity.player.Player;
9
import net.minecraft.world.item.ItemStack;
10
import net.minecraft.world.level.BlockGetter;
11
import net.minecraft.world.level.Level;
12
import net.minecraft.world.level.block.state.BlockState;
13
import net.minecraft.world.phys.AABB;
14
import net.minecraft.world.phys.shapes.CollisionContext;
15
import net.minecraft.world.phys.shapes.Shapes;
16
import net.minecraft.world.phys.shapes.VoxelShape;
17
import net.neoforged.neoforge.common.extensions.ILevelExtension;
18
import org.cyclops.cyclopscore.datastructure.EnumFacingMap;
19
import org.cyclops.integrateddynamics.api.part.IPartContainer;
20
import org.cyclops.integrateddynamics.api.part.IPartType;
21
import org.cyclops.integrateddynamics.client.model.CableModel;
22
import org.cyclops.integrateddynamics.core.block.BlockRayTraceResultComponent;
23
import org.cyclops.integrateddynamics.core.block.VoxelShapeComponents;
24
import org.cyclops.integrateddynamics.core.block.VoxelShapeComponentsFactory;
25
import org.cyclops.integrateddynamics.core.helper.CableHelpers;
26
import org.cyclops.integrateddynamics.core.helper.PartHelpers;
27

28
import javax.annotation.Nullable;
29
import java.util.Collection;
30

31
/**
32
 * Shape handler for cable connections.
33
 * @author rubensworks
34
 */
35
public class VoxelShapeComponentsFactoryHandlerCableConnections implements VoxelShapeComponentsFactory.IHandler {
3✔
36

37
    private final static EnumFacingMap<VoxelShape> BOUNDS = EnumFacingMap.forAllValues(
12✔
38
            Shapes.create(new AABB(CableModel.MIN, 0, CableModel.MIN, CableModel.MAX, CableModel.MIN, CableModel.MAX)), // DOWN
10✔
39
            Shapes.create(new AABB(CableModel.MIN, CableModel.MAX, CableModel.MIN, CableModel.MAX, 1, CableModel.MAX)), // UP
10✔
40
            Shapes.create(new AABB(CableModel.MIN, CableModel.MIN, 0, CableModel.MAX, CableModel.MAX, CableModel.MIN)), // NORTH
10✔
41
            Shapes.create(new AABB(CableModel.MIN, CableModel.MAX, CableModel.MAX, CableModel.MAX, CableModel.MIN, 1)), // SOUTH
10✔
42
            Shapes.create(new AABB(0, CableModel.MIN, CableModel.MIN, CableModel.MIN, CableModel.MAX, CableModel.MAX)), // WEST
10✔
43
            Shapes.create(new AABB(CableModel.MAX, CableModel.MIN, CableModel.MIN, 1, CableModel.MAX, CableModel.MAX)) // EAST
1✔
44
    );
45

46
    @Override
47
    public Collection<VoxelShapeComponents.IComponent> createComponents(BlockState blockState, BlockGetter world, BlockPos blockPos, CollisionContext selectionContext) {
48
        Collection<VoxelShapeComponents.IComponent> components = Lists.newArrayList();
2✔
49
        if (world instanceof ILevelExtension level) {
3!
50
            if (CableHelpers.isNoFakeCable(level, blockPos, null, blockState)) {
×
51
                for (Direction direction : Direction.values()) {
×
52
                    IPartContainer partContainer = null;
×
53
                    if (CableHelpers.isCableConnected((Level) world, blockPos, direction, blockState) ||
×
54
                            (partContainer = PartHelpers.getPartContainer(level, blockPos, direction, blockState).orElse(null)) != null
×
55
                                    && partContainer.hasPart(direction)) {
×
56
                        components.add(new Component(direction, partContainer));
×
57
                    }
58
                }
59
            }
60
        }
61
        return components;
2✔
62
    }
63

64
    public static class Component extends VoxelShapeComponentsFactoryHandlerCableCenter.Component {
65

66
        private final Direction direction;
67
        @Nullable
68
        private final IPartContainer partContainer;
69

70
        public Component(Direction direction, @Nullable IPartContainer partContainer) {
×
71
            this.direction = direction;
×
72
            this.partContainer = partContainer;
×
73
        }
×
74

75
        @Override
76
        public String getStateId(BlockState blockState, BlockGetter world, BlockPos blockPos) {
77
            return "conn(" + direction.ordinal() + ")";
×
78
        }
79

80
        @Override
81
        public VoxelShape getShape(BlockState blockState, BlockGetter world, BlockPos blockPos, CollisionContext selectionContext) {
82
            if (partContainer == null) { // equivalent to: CableHelpers.isCableConnected(world, blockPos, direction)
×
83
                return BOUNDS.get(direction);
×
84
            }
85
            IPartType part = partContainer.getPart(direction);
×
86
            if (part == null) {
×
87
                // Can happen rarely on client desyncs
88
                return BOUNDS.get(direction);
×
89
            }
90
            return part.getPartRenderPosition().getSidedCableBoundingBox(direction);
×
91
        }
92

93
        @Override
94
        public InteractionResult onBlockActivated(BlockState state, Level world, BlockPos blockPos, Player player, InteractionHand hand, BlockRayTraceResultComponent hit) {
95
            ItemStack heldItem = player.getItemInHand(hand);
×
96
            InteractionResult actionResult = CableHelpers.onCableActivated(world, blockPos, state, player, heldItem, hit.getDirection(), direction);
×
97
            if(actionResult.consumesAction()) {
×
98
                return actionResult;
×
99
            }
100
            return InteractionResult.PASS;
×
101
        }
102

103
    }
104

105
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc