• 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

3.4
/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());
9!
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);
×
62
    }
×
63

64
    @Override
65
    public S deserializeState(ValueInput valueInput) {
66
        S partState = constructDefaultState();
×
67
        partState.deserialize(valueInput);
×
68
        partState.gatherCapabilities((P) this);
×
69
        return partState;
×
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();
×
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();
×
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();
×
107
    }
108

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

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

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

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

145
    protected boolean hasOffsetVariables(S state) {
146
        NonNullList<ItemStack> inventory = state.getInventoryNamed("offsetVariablesInventory");
×
147
        return inventory != null && inventory.stream().anyMatch(item -> !item.isEmpty());
×
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);
×
158
    }
159

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

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

168
    }
×
169

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

173
    }
×
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();
×
179
    }
×
180

181
    @Override
182
    public ItemStack getItemStack(ValueDeseralizationContext valueDeseralizationContext, ProblemReporter.PathElement problemPath, S state, boolean saveState) {
183
        ItemStack itemStack = new ItemStack(getItem());
×
184
        if (saveState) {
×
185
            try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(problemPath, LOGGER)) {
×
186
                TagValueOutput valueOutput = TagValueOutput.createWithContext(scopedCollector, valueDeseralizationContext.holderLookupProvider());
×
187
                serializeState(valueOutput, state);
×
188
                itemStack.set(RegistryEntries.DATACOMPONENT_PART_STATE, valueOutput.buildResult());
×
189
            }
190
        }
191
        return itemStack;
×
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;
×
202
        if(!itemStack.isEmpty() && itemStack.has(RegistryEntries.DATACOMPONENT_PART_STATE)) {
×
203
            try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(problemPath, LOGGER)) {
×
204
                ValueInput input = TagValueInput.create(
×
205
                        scopedCollector,
206
                        valueDeseralizationContext.holderLookupProvider(),
×
207
                        itemStack.get(RegistryEntries.DATACOMPONENT_PART_STATE)
×
208
                );
209
                partState = deserializeState(input);
×
210
            }
211
        }
212
        if(partState == null) {
×
213
            partState = defaultBlockState();
×
214
        }
215
        return partState;
×
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();
×
226
        defaultState.generateId();
×
227
        defaultState.gatherCapabilities((P) this);
×
228
        return defaultState;
×
229
    }
230

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

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

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

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

256
    }
×
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
    }
×
272

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

276
    }
×
277

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

282
    }
×
283

284
    @Override
285
    public int getConsumptionRate(S state) {
286
        return 0;
×
287
    }
288

289
    @Override
290
    public void postUpdate(INetwork network, IPartNetwork partNetwork, PartTarget target, S state, boolean updated) {
291
        setEnabled(state, updated);
×
292
    }
×
293

294
    @Override
295
    public boolean isEnabled(S state) {
296
        return state.isEnabled();
×
297
    }
298

299
    @Override
300
    public void setEnabled(S state, boolean enabled) {
301
        state.setEnabled(enabled);
×
302
    }
×
303

304
    @Override
305
    public void loadTooltip(S state, List<Component> lines) {
306

307
    }
×
308

309
    @Override
310
    public void loadTooltip(ItemStack itemStack, Consumer<Component> tooltipAdder) {
311

312
    }
×
313

314
    @Override
315
    public boolean shouldTriggerBlockRenderUpdate(@Nullable S oldPartState, @Nullable S newPartState) {
316
        return oldPartState == null || newPartState == null || oldPartState.isForceBlockRenderUpdateAndReset();
×
317
    }
318

319
    @Override
320
    public boolean hasEventSubscriptions() {
321
        return false;
×
322
    }
323

324
    @Override
325
    public Set<Class<? extends INetworkEvent>> getSubscribedEvents() {
326
        return Collections.emptySet();
×
327
    }
328

329
    @Override
330
    public void onEvent(INetworkEvent event, IPartNetworkElement<P, S> networkElement) {
331

332
    }
×
333
}
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