• 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

0.0
/src/main/java/org/cyclops/integrateddynamics/gametest/GameTestsAspectsReadNetwork.java
1
package org.cyclops.integrateddynamics.gametest;
2

3
import com.google.common.collect.Lists;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.core.Direction;
6
import net.minecraft.gametest.framework.GameTestHelper;
7
import net.minecraft.network.chat.Component;
8
import net.minecraft.world.item.ItemStack;
9
import org.apache.commons.lang3.tuple.Pair;
10
import org.cyclops.cyclopscore.gametest.GameTest;
11
import org.cyclops.integrateddynamics.GeneralConfig;
12
import org.cyclops.integrateddynamics.RegistryEntries;
13
import org.cyclops.integrateddynamics.api.part.PartPos;
14
import org.cyclops.integrateddynamics.api.part.aspect.IAspectVariable;
15
import org.cyclops.integrateddynamics.blockentity.BlockEntityEnergyBattery;
16
import org.cyclops.integrateddynamics.blockentity.BlockEntityVariablestore;
17
import org.cyclops.integrateddynamics.core.evaluate.operator.Operators;
18
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypeBoolean;
19
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypeInteger;
20
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypeLong;
21
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypes;
22
import org.cyclops.integrateddynamics.core.helper.L10NValues;
23
import org.cyclops.integrateddynamics.core.helper.PartHelpers;
24
import org.cyclops.integrateddynamics.core.part.PartTypes;
25
import org.cyclops.integrateddynamics.part.PartTypePanelDisplay;
26
import org.cyclops.integrateddynamics.part.aspect.Aspects;
27

28
import java.util.function.Supplier;
29

30
import static org.cyclops.integrateddynamics.gametest.GameTestHelpersIntegratedDynamics.*;
31

32
public class GameTestsAspectsReadNetwork {
×
33

34
    public static final String TEMPLATE_EMPTY = "integrateddynamics:empty10";
35
    public static final BlockPos POS = BlockPos.ZERO.offset(2, 0, 2);
×
36

37
    @GameTest(template = TEMPLATE_EMPTY)
38
    public void testAspectsReadNetworkApplicableTrue(GameTestHelper helper) {
39
        helper.setBlock(POS.west(), RegistryEntries.BLOCK_CABLE.get());
×
40
        testReadAspect(POS, helper, PartTypes.NETWORK_READER, Aspects.Read.Network.BOOLEAN_APPLICABLE, ValueTypeBoolean.ValueBoolean.of(true));
×
41
    }
×
42

43
    @GameTest(template = TEMPLATE_EMPTY)
44
    public void testAspectsReadNetworkApplicableFalse(GameTestHelper helper) {
45
        testReadAspect(POS, helper, PartTypes.NETWORK_READER, Aspects.Read.Network.BOOLEAN_APPLICABLE, ValueTypeBoolean.ValueBoolean.of(false));
×
46
    }
×
47

48
    @GameTest(template = TEMPLATE_EMPTY)
49
    public void testAspectsReadNetworkElementCountInvalid(GameTestHelper helper) {
50
        testReadAspect(POS, helper, PartTypes.NETWORK_READER, Aspects.Read.Network.INTEGER_ELEMENT_COUNT, ValueTypeInteger.ValueInteger.of(0));
×
51
    }
×
52

53
    @GameTest(template = TEMPLATE_EMPTY)
54
    public void testAspectsReadNetworkElementCountValid(GameTestHelper helper) {
55
        testReadAspect(POS, helper, PartTypes.NETWORK_READER, Aspects.Read.Network.INTEGER_ELEMENT_COUNT, ValueTypeInteger.ValueInteger.of(2));
×
56

57
        helper.setBlock(POS.west(), RegistryEntries.BLOCK_CABLE.get());
×
58
        PartHelpers.addPart(helper.getLevel(), helper.absolutePos(POS.west()), Direction.NORTH, PartTypes.REDSTONE_READER, new ItemStack(PartTypes.REDSTONE_READER.getItem()));
×
59
        PartHelpers.addPart(helper.getLevel(), helper.absolutePos(POS.west()), Direction.SOUTH, PartTypes.REDSTONE_READER, new ItemStack(PartTypes.REDSTONE_READER.getItem()));
×
60
    }
×
61

62
    @GameTest(template = TEMPLATE_EMPTY)
63
    public void testAspectsReadNetworkBatteryCountInvalid(GameTestHelper helper) {
64
        testReadAspect(POS, helper, PartTypes.NETWORK_READER, Aspects.Read.Network.INTEGER_ENERGY_BATTERY_COUNT, ValueTypeInteger.ValueInteger.of(0));
×
65
    }
×
66

67
    @GameTest(template = TEMPLATE_EMPTY)
68
    public void testAspectsReadNetworkBatteryCountValid(GameTestHelper helper) {
69
        helper.setBlock(POS.west(), RegistryEntries.BLOCK_ENERGY_BATTERY.get());
×
70
        helper.setBlock(POS.west().west(), RegistryEntries.BLOCK_ENERGY_BATTERY.get());
×
71
        testReadAspect(POS, helper, PartTypes.NETWORK_READER, Aspects.Read.Network.INTEGER_ENERGY_BATTERY_COUNT, ValueTypeInteger.ValueInteger.of(2));
×
72
    }
×
73

74
    @GameTest(template = TEMPLATE_EMPTY)
75
    public void testAspectsReadNetworkEnergyStoredInvalid(GameTestHelper helper) {
76
        testReadAspect(POS, helper, PartTypes.NETWORK_READER, Aspects.Read.Network.LONG_ENERGY_STORED, ValueTypeLong.ValueLong.of(0));
×
77
    }
×
78

79
    @GameTest(template = TEMPLATE_EMPTY)
80
    public void testAspectsReadNetworkEnergyStoredValid(GameTestHelper helper) {
81
        helper.setBlock(POS.west(), RegistryEntries.BLOCK_ENERGY_BATTERY.get());
×
82
        helper.setBlock(POS.west().west(), RegistryEntries.BLOCK_ENERGY_BATTERY.get());
×
83
        helper.getBlockEntity(POS.west(), BlockEntityEnergyBattery.class).setEnergyStored(100);
×
84
        helper.getBlockEntity(POS.west().west(), BlockEntityEnergyBattery.class).setEnergyStored(200);
×
85
        testReadAspect(POS, helper, PartTypes.NETWORK_READER, Aspects.Read.Network.LONG_ENERGY_STORED, ValueTypeLong.ValueLong.of(300));
×
86
    }
×
87

88
    @GameTest(template = TEMPLATE_EMPTY)
89
    public void testAspectsReadNetworkEnergyMaxInvalid(GameTestHelper helper) {
90
        testReadAspect(POS, helper, PartTypes.NETWORK_READER, Aspects.Read.Network.LONG_ENERGY_MAX, ValueTypeLong.ValueLong.of(0));
×
91
    }
×
92

93
    @GameTest(template = TEMPLATE_EMPTY)
94
    public void testAspectsReadNetworkEnergyMaxValid(GameTestHelper helper) {
95
        helper.setBlock(POS.west(), RegistryEntries.BLOCK_ENERGY_BATTERY.get());
×
96
        helper.setBlock(POS.west().west(), RegistryEntries.BLOCK_ENERGY_BATTERY.get());
×
97
        helper.getBlockEntity(POS.west(), BlockEntityEnergyBattery.class).setEnergyStored(100);
×
98
        helper.getBlockEntity(POS.west().west(), BlockEntityEnergyBattery.class).setEnergyStored(200);
×
99
        testReadAspect(POS, helper, PartTypes.NETWORK_READER, Aspects.Read.Network.LONG_ENERGY_MAX, ValueTypeLong.ValueLong.of(2_000_000));
×
100
    }
×
101

102
    @GameTest(template = TEMPLATE_EMPTY)
103
    public void testAspectsReadNetworkEnergConsumptionRateInvalid(GameTestHelper helper) {
104
        testReadAspect(POS, helper, PartTypes.NETWORK_READER, Aspects.Read.Network.INTEGER_ENERGY_CONSUMPTION_RATE, ValueTypeInteger.ValueInteger.of(0));
×
105
    }
×
106

107
    @GameTest(template = TEMPLATE_EMPTY)
108
    public void testAspectsReadNetworkEnergConsumptionRateValid(GameTestHelper helper) {
109
        GeneralConfig.energyConsumptionMultiplier = 1;
×
110

111
        Supplier<IAspectVariable> variableSupplier = testReadAspectSetup(POS, helper, PartTypes.NETWORK_READER, Aspects.Read.Network.INTEGER_ENERGY_CONSUMPTION_RATE);
×
112
        helper.succeedWhen(() -> {
×
113
            assertValueEqual(helper, variableSupplier.get(), ValueTypeInteger.ValueInteger.of(2));
×
114
            GeneralConfig.energyConsumptionMultiplier = 0;
×
115
        });
×
116

117
        helper.setBlock(POS.west(), RegistryEntries.BLOCK_CABLE.get());
×
118
        PartHelpers.addPart(helper.getLevel(), helper.absolutePos(POS.west()), Direction.NORTH, PartTypes.REDSTONE_READER, new ItemStack(PartTypes.REDSTONE_READER.getItem()));
×
119
        PartHelpers.addPart(helper.getLevel(), helper.absolutePos(POS.west()), Direction.SOUTH, PartTypes.REDSTONE_READER, new ItemStack(PartTypes.REDSTONE_READER.getItem()));
×
120
    }
×
121

122
    @GameTest(template = TEMPLATE_EMPTY)
123
    public void testAspectsReadNetworkValueInvalidNoNetwork(GameTestHelper helper) {
124
        testReadAspectThrows(POS, helper, PartTypes.NETWORK_READER, Aspects.Read.Network.ANY_VALUE);
×
125
    }
×
126

127
    @GameTest(template = TEMPLATE_EMPTY)
128
    public void testAspectsReadNetworkValueInvalidNoPart(GameTestHelper helper) {
129
        helper.setBlock(POS.west(), RegistryEntries.BLOCK_ENERGY_BATTERY.get());
×
130
        testReadAspectThrows(POS, helper, PartTypes.NETWORK_READER, Aspects.Read.Network.ANY_VALUE);
×
131
    }
×
132

133
    @GameTest(template = TEMPLATE_EMPTY)
134
    public void testAspectsReadNetworkValueInvalidWrongSide(GameTestHelper helper) {
135
        helper.setBlock(POS.west(), RegistryEntries.BLOCK_CABLE.get());
×
136
        PartHelpers.addPart(helper.getLevel(), helper.absolutePos(POS.west()), Direction.NORTH, PartTypes.REDSTONE_WRITER, new ItemStack(PartTypes.REDSTONE_WRITER.getItem()));
×
137
        placeVariableInWriter(helper, helper.getLevel(), PartPos.of(helper.getLevel(), helper.absolutePos(POS.west()), Direction.NORTH), Aspects.Write.Redstone.BOOLEAN, new ItemStack(RegistryEntries.ITEM_VARIABLE));
×
138
        testReadAspectThrows(POS, helper, PartTypes.NETWORK_READER, Aspects.Read.Network.ANY_VALUE);
×
139
    }
×
140

141
    @GameTest(template = TEMPLATE_EMPTY)
142
    public void testAspectsReadNetworkValueValid(GameTestHelper helper) {
143
        helper.setBlock(POS.west(), RegistryEntries.BLOCK_CABLE.get());
×
144
        PartHelpers.addPart(helper.getLevel(), helper.absolutePos(POS.west()), Direction.EAST, PartTypes.REDSTONE_WRITER, new ItemStack(PartTypes.REDSTONE_WRITER.getItem()));
×
145
        placeVariableInWriter(helper, helper.getLevel(), PartPos.of(helper.getLevel(), helper.absolutePos(POS.west()), Direction.EAST), Aspects.Write.Redstone.BOOLEAN, new ItemStack(RegistryEntries.ITEM_VARIABLE));
×
146
        testReadAspect(POS, helper, PartTypes.NETWORK_READER, Aspects.Read.Network.ANY_VALUE, ValueTypeBoolean.ValueBoolean.of(true));
×
147
    }
×
148

149
    @GameTest(template = TEMPLATE_EMPTY)
150
    public void testAspectsReadNetworkGetVariableByIdInvalidId(GameTestHelper helper) {
151
        // Create network reader and read OPERATOR_GETVARIABLEBYID
152
        testReadAspectSetup(POS, helper, PartTypes.NETWORK_READER, Aspects.Read.Network.OPERATOR_GETVARIABLEBYID);
×
153
        ItemStack variableAspect1 = createVariableFromReader(helper.getLevel(), PartPos.of(helper.getLevel(), helper.absolutePos(POS), Direction.WEST), Aspects.Read.Network.OPERATOR_GETVARIABLEBYID);
×
154

155
        // Add cables
156
        helper.setBlock(POS.west(), RegistryEntries.BLOCK_CABLE.get());
×
157
        helper.setBlock(POS.north().west(), RegistryEntries.BLOCK_CABLE.get());
×
158
        helper.setBlock(POS.north(), RegistryEntries.BLOCK_CABLE.get());
×
159

160
        // Add display panel
161
        PartHelpers.addPart(helper.getLevel(), helper.absolutePos(POS.north()), Direction.EAST, PartTypes.DISPLAY_PANEL, new ItemStack(PartTypes.DISPLAY_PANEL.getItem()));
×
162

163
        // Place variable store
164
        helper.setBlock(POS.north().north(), RegistryEntries.BLOCK_VARIABLE_STORE.get());
×
165
        BlockEntityVariablestore variableStore = helper.getBlockEntity(POS.north().north(), BlockEntityVariablestore.class);
×
166

167
        // Insert OPERATOR_GETVARIABLEBYID in variable store
168
        variableStore.getInventory().setItem(0, variableAspect1);
×
169

170
        // Create a constant value 10, and place it in variable store
171
        ItemStack variableConstant = createVariableForValue(helper.getLevel(), ValueTypes.INTEGER, ValueTypeInteger.ValueInteger.of(10));
×
172
        variableStore.getInventory().setItem(1, variableConstant);
×
173

174
        // Create a variable referring the constant variable id, and place it in variable store
175
        ItemStack variableConstantId = createVariableForValue(helper.getLevel(), ValueTypes.INTEGER, ValueTypeInteger.ValueInteger.of(-1));
×
176
        variableStore.getInventory().setItem(2, variableConstantId);
×
177

178
        // Create variable card for OPERATOR_GETVARIABLEBYID operator on variable aspect
179
        ItemStack variableApplied = createVariableForOperator(helper.getLevel(), Operators.OPERATOR_APPLY, new int[]{
×
180
                getVariableFacade(helper.getLevel(), variableAspect1).getId(),
×
181
                getVariableFacade(helper.getLevel(), variableConstantId).getId()
×
182
        });
183

184
        // Place applied variable in display panel
185
        Pair<PartTypePanelDisplay, PartTypePanelDisplay.State> partAndState = placeVariableInDisplayPanel(helper.getLevel(), PartPos.of(helper.getLevel(), helper.absolutePos(POS.north()), Direction.EAST), variableApplied);
×
186

187
        helper.succeedWhen(() -> {
×
188
            assertValueEqual(helper, partAndState.getRight().getDisplayValue(), null);
×
189
            helper.assertValueEqual(partAndState.getRight().getGlobalErrors(), Lists.newArrayList(
×
190
                    Component.translatable(L10NValues.OPERATOR_ERROR_VARIABLENOTINNETWORK, Integer.toString(-1))
×
191
            ), Component.literal("Display panel errors do not match"));
×
192
        });
×
193
    }
×
194

195
    @GameTest(template = TEMPLATE_EMPTY)
196
    public void testAspectsReadNetworkGetVariableByIdValid(GameTestHelper helper) {
197
        // Create network reader and read OPERATOR_GETVARIABLEBYID
198
        testReadAspectSetup(POS, helper, PartTypes.NETWORK_READER, Aspects.Read.Network.OPERATOR_GETVARIABLEBYID);
×
199
        ItemStack variableAspect1 = createVariableFromReader(helper.getLevel(), PartPos.of(helper.getLevel(), helper.absolutePos(POS), Direction.WEST), Aspects.Read.Network.OPERATOR_GETVARIABLEBYID);
×
200

201
        // Add cables
202
        helper.setBlock(POS.west(), RegistryEntries.BLOCK_CABLE.get());
×
203
        helper.setBlock(POS.north().west(), RegistryEntries.BLOCK_CABLE.get());
×
204
        helper.setBlock(POS.north(), RegistryEntries.BLOCK_CABLE.get());
×
205

206
        // Add display panel
207
        PartHelpers.addPart(helper.getLevel(), helper.absolutePos(POS.north()), Direction.EAST, PartTypes.DISPLAY_PANEL, new ItemStack(PartTypes.DISPLAY_PANEL.getItem()));
×
208

209
        // Place variable store
210
        helper.setBlock(POS.north().north(), RegistryEntries.BLOCK_VARIABLE_STORE.get());
×
211
        BlockEntityVariablestore variableStore = helper.getBlockEntity(POS.north().north(), BlockEntityVariablestore.class);
×
212

213
        // Insert OPERATOR_GETVARIABLEBYID in variable store
214
        variableStore.getInventory().setItem(0, variableAspect1);
×
215

216
        // Create a constant value 10, and place it in variable store
217
        ItemStack variableConstant = createVariableForValue(helper.getLevel(), ValueTypes.INTEGER, ValueTypeInteger.ValueInteger.of(10));
×
218
        variableStore.getInventory().setItem(1, variableConstant);
×
219

220
        // Create a variable referring the constant variable id, and place it in variable store
221
        ItemStack variableConstantId = createVariableForValue(helper.getLevel(), ValueTypes.INTEGER, ValueTypeInteger.ValueInteger.of(getVariableFacade(helper.getLevel(), variableConstant).getId()));
×
222
        variableStore.getInventory().setItem(2, variableConstantId);
×
223

224
        // Create variable card for OPERATOR_GETVARIABLEBYID operator on variable aspect
225
        ItemStack variableApplied = createVariableForOperator(helper.getLevel(), Operators.OPERATOR_APPLY, new int[]{
×
226
                getVariableFacade(helper.getLevel(), variableAspect1).getId(),
×
227
                getVariableFacade(helper.getLevel(), variableConstantId).getId()
×
228
        });
229

230
        // Place applied variable in display panel
231
        Pair<PartTypePanelDisplay, PartTypePanelDisplay.State> partAndState = placeVariableInDisplayPanel(helper.getLevel(), PartPos.of(helper.getLevel(), helper.absolutePos(POS.north()), Direction.EAST), variableApplied);
×
232

233
        helper.succeedWhen(() -> {
×
234
            assertValueEqual(helper, partAndState.getRight().getDisplayValue(), ValueTypeInteger.ValueInteger.of(10));
×
235
        });
×
236
    }
×
237

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