• 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/IPartState.java
1
package org.cyclops.integrateddynamics.api.part;
2

3
import net.minecraft.core.Direction;
4
import net.minecraft.core.NonNullList;
5
import net.minecraft.core.Vec3i;
6
import net.minecraft.network.chat.MutableComponent;
7
import net.minecraft.world.Container;
8
import net.minecraft.world.item.ItemStack;
9
import net.minecraft.world.level.storage.ValueInput;
10
import net.minecraft.world.level.storage.ValueOutput;
11
import org.cyclops.integrateddynamics.api.network.INetwork;
12
import org.cyclops.integrateddynamics.api.network.INetworkElement;
13
import org.cyclops.integrateddynamics.api.network.IPartNetwork;
14
import org.cyclops.integrateddynamics.api.part.aspect.IAspect;
15
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
16

17
import javax.annotation.Nullable;
18
import java.util.Map;
19
import java.util.Optional;
20

21
/**
22
 * A value holder for an {@link IPartType}.
23
 * This is what will be serialized from and to NBT.
24
 * This object is mutable and should not be recreated.
25
 * Note that you should be careful when passing around this state, because when the server sends an update to the
26
 * client, this state could be overwritten with a new version, so always try to use the part container to get the state.
27
 * @author rubensworks
28
 */
29
public interface IPartState<P extends IPartType> {
30

31
    public static final String GLOBALCOUNTER_KEY = "part";
32

33
    /**
34
     * Write a state to NBT.
35
     *
36
     * @param valueOutput The value to write to.
37
     */
38
    public void serialize(ValueOutput valueOutput);
39

40
    /**
41
     * Read a state from NBT.
42
     *
43
     * @param valueInput The value to read from.
44
     */
45
    public void deserialize(ValueInput valueInput);
46

47
    /**
48
     * Generate a server-wide unique ID for this part state.
49
     */
50
    public void generateId();
51

52
    /**
53
     * A server-wide unique ID for this part that is persisted when the part is broken and moved.
54
     * @return The unique ID
55
     */
56
    public int getId();
57

58
    /**
59
     * Set the update interval for this state.
60
     * @param updateInterval The tick interval to update this element.
61
     */
62
    public void setUpdateInterval(int updateInterval);
63

64
    /**
65
     * @return The tick interval to update this element.
66
     */
67
    public int getUpdateInterval();
68

69
    /**
70
     * Set the priority of this part in the network.
71
     * @deprecated Should only be called from {@link org.cyclops.integrateddynamics.api.network.INetwork#setPriorityAndChannel(INetworkElement, int, int)}}!
72
     * @param priority The new priority
73
     */
74
    @Deprecated
75
    public void setPriority(int priority);
76

77
    /**
78
     * @return The priority of this part in the network.
79
     */
80
    public int getPriority();
81

82
    /**
83
     * Set the channel for this state.
84
     * @deprecated Should only be called from {@link org.cyclops.integrateddynamics.api.network.INetwork#setPriorityAndChannel(INetworkElement, int, int)}}!
85
     * @param channel The new channel
86
     */
87
    @Deprecated
88
    public void setChannel(int channel);
89

90
    /**
91
     * @return This part's channel.
92
     */
93
    public int getChannel();
94

95
    /**
96
     * @return The target position offset.
97
     */
98
    public Vec3i getTargetOffset();
99

100
    /**
101
     * @param offset The target position offset.
102
     */
103
    public void setTargetOffset(Vec3i offset);
104

105
    /**
106
     * Indicate that the given part should interact with the given side of the target.
107
     * @param side The side of the target block to interact with.
108
     *             Null removes the side override.
109
     */
110
    public void setTargetSideOverride(@Nullable Direction side);
111

112
    /**
113
     * @return The side of the target block to interact with. Can be null.
114
     */
115
    @Nullable
116
    public Direction getTargetSideOverride();
117

118
    /**
119
     * Indicate that this state has changes that must be saved to the world.
120
     */
121
    public void markDirty();
122

123
    /**
124
     * Check if dirty and reset the dirty state.
125
     * @return If this state has changed since the last time and needs to be persisted to NBT eventually.
126
     */
127
    public boolean isDirtyAndReset();
128

129
    /**
130
     * Check if this part state should update and reset the flag.
131
     * @return If this state has changed since the last time and needs to be updated to the client.
132
     */
133
    public boolean isUpdateAndReset();
134

135
    /**
136
     * Set a flag indicating that the next time that
137
     * {@link IPartType#shouldTriggerBlockRenderUpdate(IPartState, IPartState)}
138
     * is queried, it should return true.
139
     *
140
     * This is useful in cases where the player makes changes inside a part,
141
     * the state difference checking can not be relied upon,
142
     * and a state update should be forced in any case.
143
     *
144
     * This should only be called client-side.
145
     */
146
    public void forceBlockRenderUpdate();
147

148
    /**
149
     * @return If a block render update is forced.
150
     * This flagged will be set to false after this method is called.
151
     *
152
     * This should only be called client-side.
153
     */
154
    public boolean isForceBlockRenderUpdateAndReset();
155

156
    /**
157
     * Get the properties for the given aspect.
158
     * This will only retrieve the already saved properties, so this could be null if not set before.
159
     * It is better to call the {@link IAspect#getProperties(IPartType, PartTarget, IPartState)} method instead.
160
     * @param aspect The aspect to get the properties from.
161
     * @return The properties, this can be null if still the default.
162
     */
163
    public IAspectProperties getAspectProperties(IAspect aspect);
164

165
    /**
166
     * Set the properties for the given aspect.
167
     * @param aspect The aspect to get the properties from.
168
     * @param properties The properties, this can be null if still the default.
169
     */
170
    public void setAspectProperties(IAspect aspect, IAspectProperties properties);
171

172
    /**
173
     * Enable the part from working.
174
     * @param enabled If it should work.
175
     */
176
    public void setEnabled(boolean enabled);
177

178
    /**
179
     * @return If the part should work.
180
     */
181
    public boolean isEnabled();
182

183
    /**
184
     * Gathers the capabilities of this part state.
185
     * Don't call this unless you know what you're doing!
186
     * @param partType The part type this state is associated with.
187
     */
188
    public void gatherCapabilities(P partType);
189

190
    /**
191
     * Get the given capability.
192
     * @param <T> The capability type.
193
     * @param partType The part type.
194
     * @param capability The capability to get.
195
     * @param network The network the part belongs to.
196
     * @param partNetwork The part network the part belongs to.
197
     * @param target The target.
198
     * @return The optional capability instance.
199
     */
200
    public <T> Optional<T> getCapability(P partType, PartCapability<T> capability, INetwork network, IPartNetwork partNetwork, PartTarget target);
201

202
    /**
203
     * Add a capability to this state that will not be automatically persisted to NBT.
204
     * @param <T> The capability type.
205
     * @param capability The optional capability.
206
     * @param value The capability instance.
207
     */
208
    public <T> void addVolatileCapability(PartCapability<T> capability, Optional<T> value);
209

210
    /**
211
     * Remove a non-persisted capability.
212
     * @param capability The capability.
213
     */
214
    public void removeVolatileCapability(PartCapability<?> capability);
215

216
    /**
217
     * Load the inventory of the given name from the part state.
218
     * @param name The inventory name.
219
     * @param inventory The inventory object to load into.
220
     */
221
    public default void loadInventoryNamed(String name, Container inventory) {
222
        NonNullList<ItemStack> tabItems = this.getInventoryNamed(name);
×
223
        if (tabItems != null) {
×
224
            for (int i = 0; i < tabItems.size(); i++) {
×
225
                inventory.setItem(i, tabItems.get(i));
×
226
            }
227
        }
228
    }
×
229

230
    /**
231
     * Save the inventory of the given name into the part state.
232
     * @param name The inventory name.
233
     * @param inventory The inventory object to save.
234
     */
235
    public default void saveInventoryNamed(String name, Container inventory) {
236
        NonNullList<ItemStack> latestItems = NonNullList.create();
×
237
        for (int i = 0; i < inventory.getContainerSize(); i++) {
×
238
            latestItems.add(inventory.getItem(i));
×
239
        }
240
        this.setInventoryNamed(name, latestItems);
×
241
    }
×
242

243
    /**
244
     * @param name The inventory name.
245
     * @return Get the inventory contents of the given name.
246
     */
247
    @Nullable
248
    public NonNullList<ItemStack> getInventoryNamed(String name);
249

250
    /**
251
     * Set the inventory of the given name.
252
     * @param name The inventory name.
253
     * @param inventory Inventory contents.
254
     */
255
    public void setInventoryNamed(String name, NonNullList<ItemStack> inventory);
256

257
    /**
258
     * @return All named inventories.
259
     */
260
    public Map<String, NonNullList<ItemStack>> getInventoriesNamed();
261

262
    /**
263
     * Clear all named inventories.
264
     */
265
    public void clearInventoriesNamed();
266

267
    /**
268
     * Run the initialization logic for offset handling.
269
     */
270
    public void initializeOffsets(PartTarget target);
271

272
    /**
273
     * Tick any internal offset variables.
274
     * @param partType The part type.
275
     * @param network The network.
276
     * @param partNetwork The part network.
277
     * @param target The part target.
278
     */
279
    public void updateOffsetVariables(P partType, INetwork network, IPartNetwork partNetwork, PartTarget target);
280

281
    /**
282
     * Indicate that the contents of the offset variables inventory have changed.
283
     */
284
    public void markOffsetVariablesChanged();
285

286
    /**
287
     * @param slot The offset variable slot.
288
     * @return The current error, or null if no error.
289
     */
290
    @Nullable
291
    public MutableComponent getOffsetVariableError(int slot);
292

293
    /**
294
     * @return If the part contains variable-driven offsets that require updating.
295
     */
296
    public boolean requiresOffsetUpdates();
297

298
    /**
299
     * @return The max offset allowed in this part.
300
     */
301
    public int getMaxOffset();
302

303
    /**
304
     * Update the max offset for this part.
305
     * @param offset The new offset.
306
     */
307
    public void setMaxOffset(int offset);
308
}
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