• 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

8.77
/src/main/java/org/cyclops/integrateddynamics/block/shapes/VoxelShapeComponentsFactoryHandlerParts.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.shapes.CollisionContext;
14
import net.minecraft.world.phys.shapes.Shapes;
15
import net.minecraft.world.phys.shapes.VoxelShape;
16
import net.neoforged.neoforge.common.extensions.ILevelExtension;
17
import org.cyclops.integrateddynamics.api.part.IPartContainer;
18
import org.cyclops.integrateddynamics.api.part.IPartType;
19
import org.cyclops.integrateddynamics.core.block.BlockRayTraceResultComponent;
20
import org.cyclops.integrateddynamics.core.block.VoxelShapeComponents;
21
import org.cyclops.integrateddynamics.core.block.VoxelShapeComponentsFactory;
22
import org.cyclops.integrateddynamics.core.helper.CableHelpers;
23
import org.cyclops.integrateddynamics.core.helper.PartHelpers;
24
import org.cyclops.integrateddynamics.core.helper.WrenchHelpers;
25
import org.cyclops.integrateddynamics.item.ItemBlockCable;
26

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

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

37
    @Override
38
    public Collection<VoxelShapeComponents.IComponent> createComponents(BlockState blockState, BlockGetter world, BlockPos blockPos, CollisionContext selectionContext) {
39
        Collection<VoxelShapeComponents.IComponent> components = Lists.newArrayList();
2✔
40
        if (world instanceof ILevelExtension level) {
3!
41
            for (Direction direction : Direction.values()) {
×
42
                IPartContainer partContainer = PartHelpers.getPartContainer(level, blockPos, direction, blockState).orElse(null);
×
43
                if (partContainer != null && partContainer.hasPart(direction)) {
×
44
                    components.add(new Component(direction, partContainer));
×
45
                }
46
            }
47
        }
48
        return components;
2✔
49
    }
50

51
    public static class Component implements VoxelShapeComponents.IComponent {
52

53
        private final Direction direction;
54
        private final IPartContainer partContainer;
55

56
        public Component(Direction direction, IPartContainer partContainer) {
×
57
            this.direction = direction;
×
58
            this.partContainer = partContainer;
×
59
        }
×
60

61
        public Optional<IPartType> getPart() {
62
            return Optional.ofNullable(partContainer.getPart(direction));
×
63
        }
64

65
        @Override
66
        public String getStateId(BlockState blockState, BlockGetter world, BlockPos blockPos) {
67
            return getPart()
×
68
                    .map(part -> "part(" + part.getPartRenderPosition().toCompactString() + ")")
×
69
                    .orElse("part");
×
70
        }
71

72
        @Override
73
        public VoxelShape getShape(BlockState blockState, BlockGetter world, BlockPos blockPos, CollisionContext selectionContext) {
74
            return getPart()
×
75
                    .map(part -> part.getPartRenderPosition().getBoundingBox(direction, selectionContext))
×
76
                    .orElse(Shapes.empty());
×
77
        }
78

79
        @Override
80
        public ItemStack getCloneItemStack(Level world, BlockPos pos) {
81
            return getPart()
×
82
                    .map(part -> part.getCloneItemStack(world, pos, partContainer.getPartState(direction)))
×
83
                    .orElse(ItemStack.EMPTY);
×
84
        }
85

86
        @Override
87
        public boolean destroy(Level world, BlockPos pos, Player player, boolean saveState) {
88
            if(!world.isClientSide()) {
×
89
                return PartHelpers.removePart(world, pos, direction, player, true, true, saveState);
×
90
            }
91
            return false;
×
92
        }
93

94
        @Override
95
        public InteractionResult onBlockActivated(BlockState state, Level world, BlockPos blockPos, Player player, InteractionHand hand, BlockRayTraceResultComponent hit) {
96
            ItemStack heldItem = player.getItemInHand(hand);
×
97
            if(WrenchHelpers.isWrench(player, heldItem, world, blockPos, hit.getDirection()) && player.isSecondaryUseActive()) {
×
98
                // Remove part from cable
99
                if (!world.isClientSide()) {
×
100
                    destroy(world, blockPos, player, true);
×
101
                    ItemBlockCable.playBreakSound(world, blockPos, state);
×
102
                }
103
                return InteractionResult.SUCCESS;
×
104
            } else if(CableHelpers.isNoFakeCable(world, blockPos, hit.getDirection())) {
×
105
                // Delegate activated call to part
106
                return getPart()
×
107
                        .map(part -> part.onPartActivated(partContainer.getPartState(direction), blockPos, world,
×
108
                                player, hand, heldItem, hit.withDirection(direction)))
×
109
                        .orElse(InteractionResult.FAIL);
×
110
            }
111
            return InteractionResult.PASS;
×
112
        }
113

114
        @Nullable
115
        @Override
116
        public Direction getRaytraceDirection() {
117
            return direction;
×
118
        }
119

120
        @Override
121
        public boolean isRaytraceLastForFace() {
122
            return false;
×
123
        }
124

125
    }
126

127
}
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