• 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/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.BlockGetter;
19
import net.minecraft.world.level.Level;
20
import net.minecraft.world.level.LevelReader;
21
import net.minecraft.world.level.ScheduledTickAccess;
22
import net.minecraft.world.level.block.Block;
23
import net.minecraft.world.level.block.state.BlockState;
24
import net.minecraft.world.level.redstone.Orientation;
25
import net.minecraft.world.level.storage.ValueInput;
26
import net.minecraft.world.level.storage.ValueOutput;
27
import net.minecraft.world.phys.BlockHitResult;
28
import org.cyclops.cyclopscore.datastructure.DimPos;
29
import org.cyclops.integrateddynamics.api.evaluate.variable.ValueDeseralizationContext;
30
import org.cyclops.integrateddynamics.api.network.*;
31

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

378
    /**
379
     * @param state The state
380
     * @return The consumption rate of this part for the given state.
381
     */
382
    public int getConsumptionRate(S state);
383

384
    /**
385
     * Called after the element was updated or not.
386
     * If the update was not called, this can be because the network did not contain
387
     * enough energy to let this element work.
388
     * @param network The network to update in.
389
     * @param partNetwork The part network to update in.
390
     * @param target The target block.
391
     * @param state The state
392
     * @param updated If the {@link INetworkElement#update(INetwork)} was called.
393
     */
394
    public void postUpdate(INetwork network, IPartNetwork partNetwork, PartTarget target, S state, boolean updated);
395

396
    /**
397
     * @param state The state
398
     * @return If this part is enabled.
399
     */
400
    public boolean isEnabled(S state);
401

402
    /**
403
     * Set if this part should work.
404
     * @param state The state
405
     * @param enabled If it should work.
406
     */
407
    public void setEnabled(S state, boolean enabled);
408

409
    /**
410
     * Add tooltip lines for this aspect when this part is being hovered by a mod like WAILA.
411
     * @param state The state.
412
     * @param lines The list to add lines to.
413
     */
414
    public void loadTooltip(S state, List<Component> lines);
415

416
    /**
417
     * Add tooltip lines for this aspect when this part's item is being hovered.
418
     *
419
     * @param itemStack    The itemstack.
420
     * @param tooltipAdder The list to add lines to.
421
     */
422
    public void loadTooltip(ItemStack itemStack, Consumer<Component> tooltipAdder);
423

424
    /**
425
     * Check if the given state change should trigger a block render update.
426
     * This is only called client-side.
427
     * The new and old partstates are never both null, at most one will be null.
428
     * @param oldPartState The old part state.
429
     * @param newPartState The new part state.
430
     * @return If it should trigger a block render update.
431
     */
432
    public boolean shouldTriggerBlockRenderUpdate(@Nullable S oldPartState, @Nullable S newPartState);
433

434
    /**
435
     * @param state The state.
436
     * @return If this part should force the block to be transparent to light.
437
     */
438
    public boolean forceLightTransparency(S state);
439

440
    /**
441
     * {@link #writeExtraGuiData(RegistryFriendlyByteBuf, PartPos, ServerPlayer)}.
442
     * @return The optional container provider for the part type gui.
443
     * @param pos The part position. May be null when called client-side, for checking presence.
444
     */
445
    public default Optional<MenuProvider> getContainerProvider(PartPos pos) {
446
        return Optional.empty();
×
447
    };
448

449
    /**
450
     * This method can be overridden for cases when additional data needs to be sent to clients when opening containers.
451
     * @param packetBuffer A packet buffer that can be written to.
452
     * @param pos A part position.
453
     * @param player The player opening the gui.
454
     */
455
    public default void writeExtraGuiData(RegistryFriendlyByteBuf packetBuffer, PartPos pos, ServerPlayer player) {
456

457
    }
×
458

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

468
    /**
469
     * {@link #writeExtraGuiDataOffsets(RegistryFriendlyByteBuf, PartPos, ServerPlayer)}.
470
     * @return The optional container provider for the part offsets gui.
471
     * @param pos The part position. May be null when called client-side, for checking presence.
472
     */
473
    public default Optional<MenuProvider> getContainerProviderOffsets(PartPos pos) {
474
        return Optional.empty();
×
475
    };
476

477
    /**
478
     * This method can be overridden for cases when additional data needs to be sent to clients
479
     * when opening settings containers.
480
     * @param packetBuffer A packet buffer that can be written to.
481
     * @param pos A part position.
482
     * @param player The player opening the settings gui.
483
     */
484
    public default void writeExtraGuiDataSettings(RegistryFriendlyByteBuf packetBuffer, PartPos pos, ServerPlayer player) {
485

486
    }
×
487

488
    /**
489
     * This method can be overridden for cases when additional data needs to be sent to clients
490
     * when opening offsets containers.
491
     * @param packetBuffer A packet buffer that can be written to.
492
     * @param pos A part position.
493
     * @param player The player opening the offsets gui.
494
     */
495
    public default void writeExtraGuiDataOffsets(RegistryFriendlyByteBuf packetBuffer, PartPos pos, ServerPlayer player) {
496

497
    }
×
498
}
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