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

CyclopsMC / IntegratedDynamics / 19579501784

21 Nov 2025 06:13PM UTC coverage: 53.055% (+0.03%) from 53.021%
19579501784

push

github

rubensworks
Delegate onBlockNeighborChange to old version for backwards-compat

2875 of 8774 branches covered (32.77%)

Branch coverage included in aggregate %.

17364 of 29373 relevant lines covered (59.12%)

3.07 hits per line

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

11.11
/src/main/java/org/cyclops/integrateddynamics/api/part/IPartType.java
1
package org.cyclops.integrateddynamics.api.part;
2

3
import net.minecraft.core.BlockPos;
4
import net.minecraft.core.Direction;
5
import net.minecraft.core.Vec3i;
6
import net.minecraft.network.RegistryFriendlyByteBuf;
7
import net.minecraft.network.chat.Component;
8
import net.minecraft.resources.ResourceLocation;
9
import net.minecraft.server.level.ServerPlayer;
10
import net.minecraft.util.ProblemReporter;
11
import net.minecraft.util.RandomSource;
12
import net.minecraft.world.InteractionHand;
13
import net.minecraft.world.InteractionResult;
14
import net.minecraft.world.MenuProvider;
15
import net.minecraft.world.entity.player.Player;
16
import net.minecraft.world.item.Item;
17
import net.minecraft.world.item.ItemStack;
18
import net.minecraft.world.level.*;
19
import net.minecraft.world.level.block.Block;
20
import net.minecraft.world.level.block.state.BlockState;
21
import net.minecraft.world.level.redstone.Orientation;
22
import net.minecraft.world.level.storage.ValueInput;
23
import net.minecraft.world.level.storage.ValueOutput;
24
import net.minecraft.world.phys.BlockHitResult;
25
import org.cyclops.cyclopscore.datastructure.DimPos;
26
import org.cyclops.integrateddynamics.api.evaluate.variable.ValueDeseralizationContext;
27
import org.cyclops.integrateddynamics.api.network.INetwork;
28
import org.cyclops.integrateddynamics.api.network.INetworkElement;
29
import org.cyclops.integrateddynamics.api.network.INetworkEventListener;
30
import org.cyclops.integrateddynamics.api.network.IPartNetwork;
31
import org.cyclops.integrateddynamics.api.network.IPartNetworkElement;
32

33
import javax.annotation.Nullable;
34
import java.util.List;
35
import java.util.Optional;
36
import java.util.function.Consumer;
37

38
/**
39
 * A type of part that can be inserted into a {@link IPartContainer}.
40
 * Only one unique instance for each part should exist, the values are stored inside an
41
 * {@link IPartState}.
42
 * @param <P> The part type.
43
 * @param <S> The part state type.
44
 * @author rubensworks
45
 */
46
public interface IPartType<P extends IPartType<P, S>, S extends IPartState<P>> extends INetworkEventListener<IPartNetworkElement<P, S>> {
47

48
    /**
49
     * @return The unique name for this part type.
50
     */
51
    public ResourceLocation getUniqueName();
52

53
    /**
54
     * @return The unlocalized name of this part.
55
     */
56
    public String getTranslationKey();
57

58
    /**
59
     * @return JSON facadeModel path for the block representation of this part.
60
     */
61
    public ResourceLocation getBlockModelPath();
62

63
    /**
64
     * @return The item associated with this part type.
65
     */
66
    public Item getItem();
67

68
    /**
69
     * @param state The state
70
     * @return If this element is solid.
71
     */
72
    public boolean isSolid(S state);
73

74
    /**
75
     * @return The position part occupies, used to calculate the required render lengths.
76
     *         This part is assumed to be aligned at the edge of the block for the depth, while centered on width and height.
77
     */
78
    public PartRenderPosition getPartRenderPosition();
79

80
    /**
81
     * Write the properties of this part to NBT.
82
     * An identificator for this part is not required, this is written somewhere else.
83
     *
84
     * @param valueOutput The value to write to.
85
     * @param partState   The state of this part.
86
     */
87
    public void serializeState(ValueOutput valueOutput, S partState);
88

89
    /**
90
     * Read the properties of this part from nbt.
91
     * This tag is guaranteed to only contain data for this part.
92
     *
93
     * @param valueInput The input to read from.
94
     * @return The state of this part.
95
     */
96
    public S deserializeState(ValueInput valueInput);
97

98
    /**
99
     * @return The default state of this part.
100
     */
101
    public S defaultBlockState();
102

103
    /**
104
     * Set the update interval for this part.
105
     * @param state The state
106
     * @param updateInterval The tick interval to update this element.
107
     */
108
    public void setUpdateInterval(S state, int updateInterval);
109

110
    /**
111
     * @param state The state
112
     * @return The tick interval to update this element.
113
     */
114
    public int getUpdateInterval(S state);
115

116
    /**
117
     * @param state The state
118
     * @return The minimum allowed tick interval to update this element.
119
     */
120
    public int getMinimumUpdateInterval(S state);
121

122
    /**
123
     * Set the priority and channel of this part in the network.
124
     * @deprecated Should only be called from {@link INetwork#setPriorityAndChannel(INetworkElement, int, int)}!
125
     * @param network The network to update in.
126
     * @param partNetwork The part network to update in.
127
     * @param target The target block.
128
     * @param state The state
129
     * @param priority The new priority
130
     * @param channel The new channel
131
     */
132
    @Deprecated
133
    public void setPriorityAndChannel(INetwork network, IPartNetwork partNetwork, PartTarget target, S state, int priority, int channel);
134

135
    /**
136
     * @param state The state
137
     * @return The priority of this part in the network.
138
     */
139
    public int getPriority(S state);
140

141
    /**
142
     * @param state The state
143
     * @return The channel of this part in the network.
144
     */
145
    public int getChannel(S state);
146

147
    /**
148
     * @return If this part can handle custom offsets.
149
     */
150
    public default boolean supportsOffsets() {
151
        return true;
2✔
152
    }
153

154
    /**
155
     * @param state The state
156
     * @return The target position offset.
157
     */
158
    public Vec3i getTargetOffset(S state);
159

160
    /**
161
     * @param state The state
162
     * @param center The center position.
163
     * @param offset The target position offset.
164
     * @return True if the offset was valid
165
     */
166
    public boolean setTargetOffset(S state, PartPos center, Vec3i offset);
167

168
    /**
169
     * Indicate that the given part should interact with the given side of the target.
170
     * @param state The state
171
     * @param side The side of the target block to interact with.
172
     *             Null removes the side override.
173
     */
174
    public void setTargetSideOverride(S state, @Nullable Direction side);
175

176
    /**
177
     * @param state The state
178
     * @return The overridden side of the target block to interact with. Can be null.
179
     */
180
    @Nullable
181
    public Direction getTargetSideOverride(S state);
182

183
    /**
184
     * Get the part target for this part.
185
     * @param pos The center position of this part.
186
     * @param state The state.
187
     * @return The part target.
188
     */
189
    public PartTarget getTarget(PartPos pos, S state);
190

191
    /**
192
     * Called when an offset variable was inserted or removed from a slot.
193
     * @param target The target block.
194
     * @param state The state.
195
     */
196
    public void onOffsetVariablesChanged(PartTarget target, S state);
197

198
    /**
199
     * @param state The state
200
     * @return If this element should be updated. This method is only called once during network initialization.
201
     */
202
    public boolean isUpdate(S state);
203

204
    /**
205
     * Update at the tick interval specified.
206
     * @param network The network to update in.
207
     * @param partNetwork The part network to update in.
208
     * @param target The target block.
209
     * @param state The state
210
     */
211
    public void update(INetwork network, IPartNetwork partNetwork, PartTarget target, S state);
212

213
    /**
214
     * Called right before the network is terminated or will be reset.
215
     * @param network The network to update in.
216
     * @param partNetwork The part network to update in.
217
     * @param target The target block.
218
     * @param state The state
219
     */
220
    public void beforeNetworkKill(INetwork network, IPartNetwork partNetwork, PartTarget target, S state);
221

222
    /**
223
     * Called right after this network is initialized.
224
     * @param network The network to update in.
225
     * @param partNetwork The part network to update in.
226
     * @param target The target block.
227
     * @param state The state
228
     */
229
    public void afterNetworkAlive(INetwork network, IPartNetwork partNetwork, PartTarget target, S state);
230

231
    /**
232
     * Called right after this network has come alive again,
233
     * for example after a network restart.
234
     * @param network The network to update in.
235
     * @param partNetwork The part network to update in.
236
     * @param target The target block.
237
     * @param state The state
238
     */
239
    public void afterNetworkReAlive(INetwork network, IPartNetwork partNetwork, PartTarget target, S state);
240

241
    /**
242
     * Get the itemstack from the given state.
243
     *
244
     * @param valueDeseralizationContext
245
     * @param problemPath
246
     * @param state                      The state
247
     * @param saveState                  If the part state should be saved in the item.
248
     * @return The itemstack possibly containing the state information.
249
     */
250
    public ItemStack getItemStack(ValueDeseralizationContext valueDeseralizationContext, ProblemReporter.PathElement problemPath, S state, boolean saveState);
251

252
    /**
253
     * Get the itemstack from the given state.
254
     * @param world The world.
255
     * @param pos The position.
256
     * @param state The state.
257
     * @return The itemstack possibly containing the state information.
258
     */
259
    public ItemStack getCloneItemStack(Level world, BlockPos pos, S state);
260

261
    /**
262
     * Get the part state from the given itemstack.
263
     *
264
     * @param valueDeseralizationContext
265
     * @param problemPath
266
     * @param itemStack                  The itemstack possibly containing state information.
267
     * @return The state contained in the itemstack or the default part state.
268
     */
269
    public S getState(ValueDeseralizationContext valueDeseralizationContext, ProblemReporter.PathElement problemPath, ItemStack itemStack);
270

271
    /**
272
     * Add the itemstacks to drop when this element is removed.
273
     * @param target The target.
274
     * @param state The state
275
     * @param itemStacks The itemstack list to add to.
276
     * @param dropMainElement If the part itself should also be dropped.
277
     * @param saveState If the part state should be saved in the item.
278
     */
279
    public void addDrops(PartTarget target, S state, List<ItemStack> itemStacks, boolean dropMainElement, boolean saveState);
280

281
    /**
282
     * Called when this element is added to the network.
283
     * @param network The network to update in.
284
     * @param partNetwork The part network to update in.
285
     * @param target The target block.
286
     * @param state The state
287
     */
288
    public void onNetworkAddition(INetwork network, IPartNetwork partNetwork, PartTarget target, S state);
289

290
    /**
291
     * Called when this element is removed from the network.
292
     * @param network The network to update in.
293
     * @param partNetwork The part network to update in.
294
     * @param target The target block.
295
     * @param state The state
296
     */
297
    public void onNetworkRemoval(INetwork network, IPartNetwork partNetwork, PartTarget target, S state);
298

299
    /**
300
     * Create a network element for this part type.
301
     * @param partContainer The container this part is/will be part of.
302
     * @param pos The position this network element is/will be placed at.
303
     * @param side The side this network element is/will be placed at.
304
     * @return A new network element instance.
305
     */
306
    public INetworkElement createNetworkElement(IPartContainer partContainer, DimPos pos, Direction side);
307

308
    /**
309
     * Called when a part is right-clicked.
310
     * @param partState The state of this part.
311
     * @param pos The position of the block this part is part of.
312
     * @param world The world.
313
     * @param player The player activating the part.
314
     * @param hand The hand in use by the player.
315
     * @param heldItem The held item.
316
     * @param hit The ray trace hit result.
317
     * @return The action result.
318
     */
319
    public InteractionResult onPartActivated(S partState, BlockPos pos, Level world, Player player, InteractionHand hand,
320
                                            ItemStack heldItem, BlockHitResult hit);
321

322
    /**
323
     * Get the base block state that will be rendered for this part.
324
     * An appropriate {@link org.cyclops.integrateddynamics.core.block.IgnoredBlock#FACING} property will be set.
325
     * @param partContainer The part entity.
326
     * @param side The position of the part.
327
     * @return The block state to render with.
328
     */
329
    public BlockState getBlockState(IPartContainer partContainer, Direction side);
330

331
    /**
332
     * @return The default block state representation of this part.
333
     */
334
    public BlockState getBaseBlockState();
335

336
    /**
337
     * Called when a block update occurs
338
     * @param world The world.
339
     * @param pos The position.
340
     * @param partState The part state.
341
     * @param random A random instance.
342
     */
343
    public void updateTick(Level world, BlockPos pos, S partState, RandomSource random);
344

345
    /**
346
     * Called when this element is about to be removed.
347
     * @param network The network.
348
     * @param partNetwork The part network to update in.
349
     * @param target The target block.
350
     * @param state The state
351
     */
352
    public void onPreRemoved(INetwork network, IPartNetwork partNetwork, PartTarget target, S state);
353

354
    /**
355
     * Called after this element has been removed.
356
     * @param network The network.
357
     * @param partNetwork The part network to update in.
358
     * @param target The target block.
359
     * @param state The state
360
     */
361
    public void onPostRemoved(INetwork network, IPartNetwork partNetwork, PartTarget target, S state);
362

363
    /**
364
     * Called when a neighbouring block is updated, more specifically when
365
     * {@link Block#neighborChanged(BlockState, Level, BlockPos, Block, Orientation, boolean)},
366
     * {@link Block#onNeighborChange(BlockState, LevelReader, BlockPos, BlockPos)}
367
     * or {@link Block#updateShape(BlockState, LevelReader, ScheduledTickAccess, BlockPos, Direction, BlockPos, BlockState, RandomSource)} is called.
368
     *
369
     * @param network     The network to update in.
370
     * @param partNetwork The part network to update in.
371
     * @param target      The target block.
372
     * @param state       The state
373
     * @param world       The world in which the neighbour was updated.
374
     */
375
    @Deprecated // TODO: rm in next major
376
    public void onBlockNeighborChange(@Nullable INetwork network, @Nullable IPartNetwork partNetwork, PartTarget target,
377
                                      S state, BlockGetter world);
378

379
    /**
380
     * Called when a neighbouring block is updated, more specifically when
381
     * {@link Block#neighborChanged(BlockState, Level, BlockPos, Block, Orientation, boolean)},
382
     * {@link Block#onNeighborChange(BlockState, LevelReader, BlockPos, BlockPos)}
383
     * or {@link Block#updateShape(BlockState, LevelReader, ScheduledTickAccess, BlockPos, Direction, BlockPos, BlockState, RandomSource)} is called.
384
     *
385
     * @param network     The network to update in.
386
     * @param partNetwork The part network to update in.
387
     * @param target      The target block.
388
     * @param state       The state
389
     * @param world       The world in which the neighbour was updated.
390
     * @param side        The side at the center block.
391
     */
392
    // TODO: rm default impl in next major
393
    public default void onBlockNeighborChange(@Nullable INetwork network, @Nullable IPartNetwork partNetwork, PartTarget target,
394
                                              S state, BlockGetter world, @Nullable Direction side) {
395
        this.onBlockNeighborChange(network, partNetwork, target, state, world);
×
396
    }
×
397

398
    /**
399
     * @param state The state
400
     * @return The consumption rate of this part for the given state.
401
     */
402
    public int getConsumptionRate(S state);
403

404
    /**
405
     * Called after the element was updated or not.
406
     * If the update was not called, this can be because the network did not contain
407
     * enough energy to let this element work.
408
     * @param network The network to update in.
409
     * @param partNetwork The part network to update in.
410
     * @param target The target block.
411
     * @param state The state
412
     * @param updated If the {@link INetworkElement#update(INetwork)} was called.
413
     */
414
    public void postUpdate(INetwork network, IPartNetwork partNetwork, PartTarget target, S state, boolean updated);
415

416
    /**
417
     * @param state The state
418
     * @return If this part is enabled.
419
     */
420
    public boolean isEnabled(S state);
421

422
    /**
423
     * Set if this part should work.
424
     * @param state The state
425
     * @param enabled If it should work.
426
     */
427
    public void setEnabled(S state, boolean enabled);
428

429
    /**
430
     * Add tooltip lines for this aspect when this part is being hovered by a mod like WAILA.
431
     * @param state The state.
432
     * @param lines The list to add lines to.
433
     */
434
    public void loadTooltip(S state, List<Component> lines);
435

436
    /**
437
     * Add tooltip lines for this aspect when this part's item is being hovered.
438
     *
439
     * @param itemStack    The itemstack.
440
     * @param tooltipAdder The list to add lines to.
441
     */
442
    public void loadTooltip(ItemStack itemStack, Consumer<Component> tooltipAdder);
443

444
    /**
445
     * Check if the given state change should trigger a block render update.
446
     * This is only called client-side.
447
     * The new and old partstates are never both null, at most one will be null.
448
     * @param oldPartState The old part state.
449
     * @param newPartState The new part state.
450
     * @return If it should trigger a block render update.
451
     */
452
    public boolean shouldTriggerBlockRenderUpdate(@Nullable S oldPartState, @Nullable S newPartState);
453

454
    /**
455
     * @param state The state.
456
     * @return If this part should force the block to be transparent to light.
457
     */
458
    public boolean forceLightTransparency(S state);
459

460
    /**
461
     * {@link #writeExtraGuiData(RegistryFriendlyByteBuf, PartPos, ServerPlayer)}.
462
     * @return The optional container provider for the part type gui.
463
     * @param pos The part position. May be null when called client-side, for checking presence.
464
     */
465
    public default Optional<MenuProvider> getContainerProvider(PartPos pos) {
466
        return Optional.empty();
×
467
    };
468

469
    /**
470
     * This method can be overridden for cases when additional data needs to be sent to clients when opening containers.
471
     * @param packetBuffer A packet buffer that can be written to.
472
     * @param pos A part position.
473
     * @param player The player opening the gui.
474
     */
475
    public default void writeExtraGuiData(RegistryFriendlyByteBuf packetBuffer, PartPos pos, ServerPlayer player) {
476

477
    }
×
478

479
    /**
480
     * {@link #writeExtraGuiDataSettings(RegistryFriendlyByteBuf, PartPos, ServerPlayer)}.
481
     * @return The optional container provider for the part settings gui.
482
     * @param pos The part position. May be null when called client-side, for checking presence.
483
     */
484
    public default Optional<MenuProvider> getContainerProviderSettings(PartPos pos) {
485
        return Optional.empty();
×
486
    };
487

488
    /**
489
     * {@link #writeExtraGuiDataOffsets(RegistryFriendlyByteBuf, PartPos, ServerPlayer)}.
490
     * @return The optional container provider for the part offsets gui.
491
     * @param pos The part position. May be null when called client-side, for checking presence.
492
     */
493
    public default Optional<MenuProvider> getContainerProviderOffsets(PartPos pos) {
494
        return Optional.empty();
×
495
    };
496

497
    /**
498
     * This method can be overridden for cases when additional data needs to be sent to clients
499
     * when opening settings containers.
500
     * @param packetBuffer A packet buffer that can be written to.
501
     * @param pos A part position.
502
     * @param player The player opening the settings gui.
503
     */
504
    public default void writeExtraGuiDataSettings(RegistryFriendlyByteBuf packetBuffer, PartPos pos, ServerPlayer player) {
505

506
    }
×
507

508
    /**
509
     * This method can be overridden for cases when additional data needs to be sent to clients
510
     * when opening offsets containers.
511
     * @param packetBuffer A packet buffer that can be written to.
512
     * @param pos A part position.
513
     * @param player The player opening the offsets gui.
514
     */
515
    public default void writeExtraGuiDataOffsets(RegistryFriendlyByteBuf packetBuffer, PartPos pos, ServerPlayer player) {
516

517
    }
×
518
}
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