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

CyclopsMC / IntegratedDynamics / 18595223322

17 Oct 2025 02:07PM UTC coverage: 53.038% (+0.01%) from 53.024%
18595223322

push

github

rubensworks
Fix broken block-update-based aspect invalidation

Was caused by 9bdd91138

2875 of 8772 branches covered (32.77%)

Branch coverage included in aggregate %.

17335 of 29333 relevant lines covered (59.1%)

3.07 hits per line

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

67.57
/src/main/java/org/cyclops/integrateddynamics/api/part/PartTypeAdapter.java
1
package org.cyclops.integrateddynamics.api.part;
2

3
import com.mojang.logging.LogUtils;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.core.Direction;
6
import net.minecraft.core.NonNullList;
7
import net.minecraft.core.Vec3i;
8
import net.minecraft.network.chat.Component;
9
import net.minecraft.util.ProblemReporter;
10
import net.minecraft.util.RandomSource;
11
import net.minecraft.world.InteractionHand;
12
import net.minecraft.world.InteractionResult;
13
import net.minecraft.world.entity.player.Player;
14
import net.minecraft.world.item.ItemStack;
15
import net.minecraft.world.level.BlockGetter;
16
import net.minecraft.world.level.Level;
17
import net.minecraft.world.level.storage.TagValueInput;
18
import net.minecraft.world.level.storage.TagValueOutput;
19
import net.minecraft.world.level.storage.ValueInput;
20
import net.minecraft.world.level.storage.ValueOutput;
21
import net.minecraft.world.phys.BlockHitResult;
22
import org.cyclops.integrateddynamics.RegistryEntries;
23
import org.cyclops.integrateddynamics.api.evaluate.variable.ValueDeseralizationContext;
24
import org.cyclops.integrateddynamics.api.network.INetwork;
25
import org.cyclops.integrateddynamics.api.network.IPartNetwork;
26
import org.cyclops.integrateddynamics.api.network.IPartNetworkElement;
27
import org.cyclops.integrateddynamics.api.network.event.INetworkEvent;
28
import org.slf4j.Logger;
29

30
import javax.annotation.Nullable;
31
import java.util.Collections;
32
import java.util.List;
33
import java.util.Map;
34
import java.util.Set;
35
import java.util.function.Consumer;
36

37
/**
38
 * Default implementation of {@link IPartType}.
39
 * @author rubensworks
40
 */
41
public abstract class PartTypeAdapter<P extends IPartType<P, S>, S extends IPartState<P>> implements IPartType<P, S> {
2✔
42

43
    private static final Logger LOGGER = LogUtils.getLogger();
3✔
44

45
    private String translationKey = null;
4✔
46

47
    @Override
48
    public final String getTranslationKey() {
49
        return translationKey != null ? translationKey : (translationKey = createTranslationKey());
12✔
50
    }
51

52
    protected abstract String createTranslationKey();
53

54
    @Override
55
    public boolean isSolid(S state) {
56
        return false;
×
57
    }
58

59
    @Override
60
    public void serializeState(ValueOutput valueOutput, S partState) {
61
        partState.serialize(valueOutput);
3✔
62
    }
1✔
63

64
    @Override
65
    public S deserializeState(ValueInput valueInput) {
66
        S partState = constructDefaultState();
3✔
67
        partState.deserialize(valueInput);
3✔
68
        partState.gatherCapabilities((P) this);
3✔
69
        return partState;
2✔
70
    }
71

72
    @Override
73
    public void setUpdateInterval(S state, int updateInterval) {
74
        state.setUpdateInterval(updateInterval);
×
75
    }
×
76

77
    @Override
78
    public int getUpdateInterval(S state) {
79
        return state.getUpdateInterval();
3✔
80
    }
81

82
    @Override
83
    public int getMinimumUpdateInterval(S state) {
84
        return 1;
×
85
    }
86

87
    @Override
88
    public void setPriorityAndChannel(INetwork network, IPartNetwork partNetwork, PartTarget target, S state, int priority, int channel) {
89
        //noinspection deprecation
90
        state.setPriority(priority);
×
91
        state.setChannel(channel);
×
92
    }
×
93

94
    @Override
95
    public int getPriority(S state) {
96
        return state.getPriority();
3✔
97
    }
98

99
    @Override
100
    public int getChannel(S state) {
101
        return state.getChannel();
×
102
    }
103

104
    @Override
105
    public Vec3i getTargetOffset(S state) {
106
        return state.getTargetOffset();
3✔
107
    }
108

109
    @Override
110
    public boolean setTargetOffset(S state, PartPos center, Vec3i offset) {
111
        int max = state.getMaxOffset();
3✔
112
        if (offset.getX() >= -max && offset.getY() >= -max && offset.getZ() >= -max
16!
113
                && offset.getX() <= max && offset.getY() <= max && offset.getZ() <= max) {
11!
114
            state.setTargetOffset(offset);
3✔
115
            return true;
2✔
116
        }
117
        return false;
2✔
118
    }
119

120
    @Override
121
    public void setTargetSideOverride(S state, @Nullable Direction side) {
122
        state.setTargetSideOverride(side);
3✔
123
    }
1✔
124

125
    @Nullable
126
    @Override
127
    public Direction getTargetSideOverride(S state) {
128
        return state.getTargetSideOverride();
3✔
129
    }
130

131
    @Override
132
    public PartTarget getTarget(PartPos pos, S state) {
133
        PartTarget target = PartTarget.fromCenter(pos);
3✔
134
        Direction sideOverride = getTargetSideOverride(state);
4✔
135
        if (sideOverride != null) {
2✔
136
            target = target.forTargetSide(sideOverride);
4✔
137
        }
138
        Vec3i offset = getTargetOffset(state);
4✔
139
        if (offset.compareTo(Vec3i.ZERO) != 0) {
4✔
140
            target = target.forOffset(offset);
4✔
141
        }
142
        return target;
2✔
143
    }
144

145
    protected boolean hasOffsetVariables(S state) {
146
        NonNullList<ItemStack> inventory = state.getInventoryNamed("offsetVariablesInventory");
4✔
147
        return inventory != null && inventory.stream().anyMatch(item -> !item.isEmpty());
4!
148
    }
149

150
    @Override
151
    public void onOffsetVariablesChanged(PartTarget target, S state) {
152
        state.markOffsetVariablesChanged();
×
153
    }
×
154

155
    @Override
156
    public boolean isUpdate(S state) {
157
        return hasOffsetVariables(state);
4✔
158
    }
159

160
    @Override
161
    public void update(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) {
162
        state.updateOffsetVariables((P) this, network, partNetwork, target);
6✔
163
    }
1✔
164

165
    @Override
166
    public void beforeNetworkKill(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) {
167

168
    }
1✔
169

170
    @Override
171
    public void afterNetworkAlive(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) {
172

173
    }
1✔
174

175
    @Override
176
    public void afterNetworkReAlive(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) {
177
        // This resets any errored offset variables and forces them to reload.
178
        state.markOffsetVariablesChanged();
2✔
179
    }
1✔
180

181
    @Override
182
    public ItemStack getItemStack(ValueDeseralizationContext valueDeseralizationContext, ProblemReporter.PathElement problemPath, S state, boolean saveState) {
183
        ItemStack itemStack = new ItemStack(getItem());
6✔
184
        if (saveState) {
2✔
185
            try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(problemPath, LOGGER)) {
6✔
186
                TagValueOutput valueOutput = TagValueOutput.createWithContext(scopedCollector, valueDeseralizationContext.holderLookupProvider());
5✔
187
                serializeState(valueOutput, state);
4✔
188
                itemStack.set(RegistryEntries.DATACOMPONENT_PART_STATE, valueOutput.buildResult());
6✔
189
            }
190
        }
191
        return itemStack;
2✔
192
    }
193

194
    @Override
195
    public ItemStack getCloneItemStack(Level world, BlockPos pos, S state) {
196
        return getItemStack(ValueDeseralizationContext.of(world), new PartPathElement(pos), state, false);
×
197
    }
198

199
    @Override
200
    public S getState(ValueDeseralizationContext valueDeseralizationContext, ProblemReporter.PathElement problemPath, ItemStack itemStack) {
201
        S partState = null;
2✔
202
        if(!itemStack.isEmpty() && itemStack.has(RegistryEntries.DATACOMPONENT_PART_STATE)) {
7!
203
            try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(problemPath, LOGGER)) {
6✔
204
                ValueInput input = TagValueInput.create(
4✔
205
                        scopedCollector,
206
                        valueDeseralizationContext.holderLookupProvider(),
3✔
207
                        itemStack.get(RegistryEntries.DATACOMPONENT_PART_STATE)
2✔
208
                );
209
                partState = deserializeState(input);
4✔
210
            }
211
        }
212
        if(partState == null) {
2✔
213
            partState = defaultBlockState();
3✔
214
        }
215
        return partState;
2✔
216
    }
217

218
    /**
219
     * @return Constructor call for a new default state for this part type.
220
     */
221
    protected abstract S constructDefaultState();
222

223
    @Override
224
    public S defaultBlockState() {
225
        S defaultState = constructDefaultState();
3✔
226
        defaultState.generateId();
2✔
227
        defaultState.gatherCapabilities((P) this);
3✔
228
        return defaultState;
2✔
229
    }
230

231
    @Override
232
    public void addDrops(PartTarget target, S state, List<ItemStack> itemStacks, boolean dropMainElement, boolean saveState) {
233
        if(dropMainElement) {
2✔
234
            itemStacks.add(getItemStack(ValueDeseralizationContext.of(target.getCenter().getPos().getLevel(true)), new PartPathElement(target.getCenter().getPos().getBlockPos()), state, saveState));
20✔
235
        }
236

237
        // Drop contents of named inventories
238
        for (Map.Entry<String, NonNullList<ItemStack>> entry : state.getInventoriesNamed().entrySet()) {
8!
239
            for (ItemStack itemStack : entry.getValue()) {
×
240
                if (!itemStack.isEmpty()) {
×
241
                    itemStacks.add(itemStack);
×
242
                }
243
            }
×
244
        }
×
245
        state.clearInventoriesNamed();
2✔
246
    }
1✔
247

248
    @Override
249
    public void onNetworkAddition(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) {
250
        state.initializeOffsets(target);
3✔
251
    }
1✔
252

253
    @Override
254
    public void onNetworkRemoval(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) {
255

256
    }
1✔
257

258
    @Override
259
    public InteractionResult onPartActivated(S partState, BlockPos pos, Level world, Player player, InteractionHand hand, ItemStack heldItem, BlockHitResult hit) {
260
        return InteractionResult.PASS;
×
261
    }
262

263
    @Override
264
    public void updateTick(Level world, BlockPos pos, S partState, RandomSource random) {
265

266
    }
×
267

268
    @Override
269
    public void onPreRemoved(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) {
270

271
    }
1✔
272

273
    @Override
274
    public void onPostRemoved(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) {
275

276
    }
1✔
277

278
    @Override
279
    public void onBlockNeighborChange(INetwork network, IPartNetwork partNetwork, PartTarget target, S state,
280
                                      BlockGetter world) {
281

282
    }
×
283

284
    @Override
285
    public void onBlockNeighborChange(INetwork network, IPartNetwork partNetwork, PartTarget target, S state,
286
                                      BlockGetter world, @Nullable Direction side) {
287

288
    }
1✔
289

290
    @Override
291
    public int getConsumptionRate(S state) {
292
        return 0;
×
293
    }
294

295
    @Override
296
    public void postUpdate(INetwork network, IPartNetwork partNetwork, PartTarget target, S state, boolean updated) {
297
        setEnabled(state, updated);
4✔
298
    }
1✔
299

300
    @Override
301
    public boolean isEnabled(S state) {
302
        return state.isEnabled();
×
303
    }
304

305
    @Override
306
    public void setEnabled(S state, boolean enabled) {
307
        state.setEnabled(enabled);
3✔
308
    }
1✔
309

310
    @Override
311
    public void loadTooltip(S state, List<Component> lines) {
312

313
    }
×
314

315
    @Override
316
    public void loadTooltip(ItemStack itemStack, Consumer<Component> tooltipAdder) {
317

318
    }
×
319

320
    @Override
321
    public boolean shouldTriggerBlockRenderUpdate(@Nullable S oldPartState, @Nullable S newPartState) {
322
        return oldPartState == null || newPartState == null || oldPartState.isForceBlockRenderUpdateAndReset();
×
323
    }
324

325
    @Override
326
    public boolean hasEventSubscriptions() {
327
        return false;
×
328
    }
329

330
    @Override
331
    public Set<Class<? extends INetworkEvent>> getSubscribedEvents() {
332
        return Collections.emptySet();
×
333
    }
334

335
    @Override
336
    public void onEvent(INetworkEvent event, IPartNetworkElement<P, S> networkElement) {
337

338
    }
×
339
}
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