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

CyclopsMC / IntegratedDynamics / 20634822687

01 Jan 2026 07:38AM UTC coverage: 45.043% (-0.2%) from 45.223%
20634822687

push

github

web-flow
Add translations through Crowdin (#1581)

Co-authored-by: Crowdin Bot <support+bot@crowdin.com>

2614 of 8582 branches covered (30.46%)

Branch coverage included in aggregate %.

11869 of 23572 relevant lines covered (50.35%)

2.39 hits per line

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

79.55
/src/main/java/org/cyclops/integrateddynamics/core/blockentity/BlockEntityCableConnectable.java
1
package org.cyclops.integrateddynamics.core.blockentity;
2

3
import net.minecraft.core.BlockPos;
4
import net.minecraft.core.HolderLookup;
5
import net.minecraft.nbt.CompoundTag;
6
import net.minecraft.world.level.Level;
7
import net.minecraft.world.level.block.entity.BlockEntityType;
8
import net.minecraft.world.level.block.state.BlockState;
9
import org.cyclops.cyclopscore.blockentity.BlockEntityTickerDelayed;
10
import org.cyclops.cyclopscore.blockentity.CyclopsBlockEntity;
11
import org.cyclops.cyclopscore.capability.registrar.BlockEntityCapabilityRegistrar;
12
import org.cyclops.cyclopscore.datastructure.EnumFacingMap;
13
import org.cyclops.cyclopscore.persist.nbt.NBTPersist;
14
import org.cyclops.integrateddynamics.Capabilities;
15
import org.cyclops.integrateddynamics.api.block.cable.ICable;
16
import org.cyclops.integrateddynamics.api.network.INetwork;
17
import org.cyclops.integrateddynamics.api.network.INetworkCarrier;
18
import org.cyclops.integrateddynamics.api.network.INetworkElementProvider;
19
import org.cyclops.integrateddynamics.capability.cable.CableTile;
20
import org.cyclops.integrateddynamics.capability.network.NetworkCarrierDefault;
21
import org.cyclops.integrateddynamics.capability.path.PathElementTile;
22
import org.cyclops.integrateddynamics.core.helper.NetworkHelpers;
23

24
import java.util.function.Supplier;
25

26
/**
27
 * A part entity whose block can connect with cables.
28
 * @author rubensworks
29
 */
30
public abstract class BlockEntityCableConnectable extends CyclopsBlockEntity {
31

32
    @NBTPersist
1✔
33
    private EnumFacingMap<Boolean> connected = EnumFacingMap.newMap();
2✔
34

35
    private final ICable cable;
36
    private final INetworkCarrier networkCarrier;
37

38
    public BlockEntityCableConnectable(BlockEntityType<?> type, BlockPos blockPos, BlockState blockState) {
39
        super(type, blockPos, blockState);
5✔
40
        cable = new CableTile<BlockEntityCableConnectable>(this) {
11✔
41

42
            @Override
43
            protected boolean isForceDisconnectable() {
44
                return false;
2✔
45
            }
46

47
            @Override
48
            protected EnumFacingMap<Boolean> getForceDisconnected() {
49
                return null;
×
50
            }
51

52
            @Override
53
            protected EnumFacingMap<Boolean> getConnected() {
54
                return tile.connected;
5✔
55
            }
56
        };
57
        networkCarrier = new NetworkCarrierDefault();
5✔
58
    }
1✔
59

60
    public static class CapabilityRegistrar<T extends BlockEntityCableConnectable> extends BlockEntityCapabilityRegistrar<T> {
61
        public CapabilityRegistrar(Supplier<BlockEntityType<? extends T>> blockEntityType) {
62
            super(blockEntityType);
3✔
63
        }
1✔
64

65
        @Override
66
        public void populate() {
67
            add(
4✔
68
                    Capabilities.Cable.BLOCK,
69
                    (blockEntity, context) -> blockEntity.getCable()
3✔
70
            );
71
            add(
4✔
72
                    Capabilities.NetworkCarrier.BLOCK,
73
                    (blockEntity, context) -> blockEntity.getNetworkCarrier()
3✔
74
            );
75
            add(
4✔
76
                    Capabilities.PathElement.BLOCK,
77
                    (blockEntity, context) -> new PathElementTile<>(blockEntity, blockEntity.getCable())
7✔
78
            );
79
        }
1✔
80
    }
81

82
    public EnumFacingMap<Boolean> getConnected() {
83
        return connected;
3✔
84
    }
85

86
    public ICable getCable() {
87
        return cable;
3✔
88
    }
89

90
    public INetworkCarrier getNetworkCarrier() {
91
        return networkCarrier;
3✔
92
    }
93

94
    public abstract INetworkElementProvider getNetworkElementProvider();
95

96
    @Override
97
    public void read(CompoundTag tag, HolderLookup.Provider provider) {
98
        super.read(tag, provider);
×
99
        connected.clear();
×
100
    }
×
101

102
    @Override
103
    public void onChunkUnloaded() {
104
        super.onChunkUnloaded();
2✔
105
        if (getLevel() != null && !getLevel().isClientSide) {
7!
106
            INetwork network = getNetworkCarrier().getNetwork();
4✔
107
            if (network != null) {
2!
108
                NetworkHelpers.invalidateNetworkElements(getLevel(), getBlockPos(), network, getNetworkElementProvider());
8✔
109
            }
110
        }
111
    }
1✔
112

113
    public static class Ticker<T extends BlockEntityCableConnectable> extends BlockEntityTickerDelayed<T> {
3✔
114
        @Override
115
        protected void update(Level level, BlockPos pos, BlockState blockState, T blockEntity) {
116
            super.update(level, pos, blockState, blockEntity);
6✔
117

118
            if (blockEntity.getConnected().isEmpty()) {
4!
119
                blockEntity.getCable().updateConnections();
×
120
            }
121
            NetworkHelpers.revalidateNetworkElements(level, pos);
4✔
122
        }
1✔
123
    }
124
}
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