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

CyclopsMC / IntegratedDynamics / 22186773560

19 Feb 2026 02:52PM UTC coverage: 52.603% (+0.2%) from 52.363%
22186773560

push

github

web-flow
Remove Lombok dependency (#1604)

2911 of 8664 branches covered (33.6%)

Branch coverage included in aggregate %.

17683 of 30486 relevant lines covered (58.0%)

3.01 hits per line

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

65.19
/src/main/java/org/cyclops/integrateddynamics/blockentity/BlockEntityDelay.java
1
package org.cyclops.integrateddynamics.blockentity;
2

3
import com.google.common.collect.Lists;
4
import com.google.common.collect.Queues;
5
import net.minecraft.core.BlockPos;
6
import net.minecraft.network.chat.Component;
7
import net.minecraft.world.MenuProvider;
8
import net.minecraft.world.entity.player.Inventory;
9
import net.minecraft.world.entity.player.Player;
10
import net.minecraft.world.inventory.AbstractContainerMenu;
11
import net.minecraft.world.item.ItemStack;
12
import net.minecraft.world.level.Level;
13
import net.minecraft.world.level.block.entity.BlockEntityType;
14
import net.minecraft.world.level.block.state.BlockState;
15
import net.minecraft.world.level.storage.ValueInput;
16
import net.minecraft.world.level.storage.ValueOutput;
17
import net.neoforged.neoforge.transfer.item.VanillaContainerWrapper;
18
import org.cyclops.cyclopscore.datastructure.DimPos;
19
import org.cyclops.cyclopscore.inventory.InventorySlotMasked;
20
import org.cyclops.cyclopscore.persist.nbt.NBTPersist;
21
import org.cyclops.integrateddynamics.Capabilities;
22
import org.cyclops.integrateddynamics.IntegratedDynamics;
23
import org.cyclops.integrateddynamics.RegistryEntries;
24
import org.cyclops.integrateddynamics.api.evaluate.EvaluationException;
25
import org.cyclops.integrateddynamics.api.evaluate.expression.VariableAdapter;
26
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
27
import org.cyclops.integrateddynamics.api.evaluate.variable.IVariable;
28
import org.cyclops.integrateddynamics.api.item.IDelayVariableFacade;
29
import org.cyclops.integrateddynamics.api.item.IVariableFacadeHandlerRegistry;
30
import org.cyclops.integrateddynamics.api.network.INetworkElement;
31
import org.cyclops.integrateddynamics.api.network.INetworkElementProvider;
32
import org.cyclops.integrateddynamics.api.network.IPartNetwork;
33
import org.cyclops.integrateddynamics.capability.networkelementprovider.NetworkElementProviderSingleton;
34
import org.cyclops.integrateddynamics.core.blockentity.BlockEntityActiveVariableBase;
35
import org.cyclops.integrateddynamics.core.evaluate.DelayVariableFacadeHandler;
36
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueHelpers;
37
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypeList;
38
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypes;
39
import org.cyclops.integrateddynamics.core.helper.NetworkHelpers;
40
import org.cyclops.integrateddynamics.core.item.DelayVariableFacade;
41
import org.cyclops.integrateddynamics.inventory.container.ContainerDelay;
42
import org.cyclops.integrateddynamics.network.DelayNetworkElement;
43

44
import javax.annotation.Nullable;
45
import java.util.Optional;
46
import java.util.Queue;
47
import java.util.function.Supplier;
48

49
/**
50
 * A part entity for the variable delay.
51
 *
52
 * @author rubensworks
53
 */
54
public class BlockEntityDelay extends BlockEntityProxy implements MenuProvider {
55

56
    public static final int INVENTORY_SIZE = 3;
57

58
    protected Queue<IValue> values = null;
3✔
59
    @NBTPersist
3✔
60
    private int capacity = 5;
61
    @NBTPersist
3✔
62
    private int updateInterval = 1;
63
    private ValueTypeList.ValueList list = ValueTypes.LIST.getDefault();
4✔
64
    private final IVariable<?> variable;
65

66
    private Player lastPlayer = null;
3✔
67
    private EvaluationException lastError = null;
3✔
68

69
    public int getCapacity() {
70
        return capacity;
×
71
    }
72

73
    public int getUpdateInterval() {
74
        return updateInterval;
×
75
    }
76

77
    public void setUpdateInterval(int updateInterval) {
78
        this.updateInterval = updateInterval;
×
79
    }
×
80

81
    public void setLastPlayer(Player lastPlayer) {
82
        this.lastPlayer = lastPlayer;
×
83
    }
×
84

85
    public BlockEntityDelay(BlockPos blockPos, BlockState blockState) {
86
        super(RegistryEntries.BLOCK_ENTITY_DELAY.get(), blockPos, blockState, BlockEntityDelay.INVENTORY_SIZE);
8✔
87
        this.variable = new VariableAdapter<ValueTypeList.ValueList>() {
12✔
88

89
            @Override
90
            public ValueTypeList getType() {
91
                return ValueTypes.LIST;
2✔
92
            }
93

94
            @Override
95
            public ValueTypeList.ValueList getValue() throws EvaluationException {
96
                if (lastError != null) {
4!
97
                    throw lastError;
×
98
                }
99
                return list;
4✔
100
            }
101
        };
102
    }
1✔
103

104
    public static class CapabilityRegistrar extends BlockEntityActiveVariableBase.CapabilityRegistrar<BlockEntityDelay> {
105
        public CapabilityRegistrar(Supplier<BlockEntityType<? extends BlockEntityDelay>> blockEntityType) {
106
            super(blockEntityType);
3✔
107
        }
1✔
108

109
        @Override
110
        public void populate() {
111
            super.populate();
2✔
112

113
            add(
4✔
114
                    net.neoforged.neoforge.capabilities.Capabilities.Item.BLOCK,
115
                    (blockEntity, direction) -> {
116
                        int slot = -1;
×
117
                        if (direction != null) {
×
118
                            switch (direction) {
×
119
                                case DOWN -> slot = SLOT_WRITE_OUT;
×
120
                                case UP -> slot = SLOT_WRITE_IN;
×
121
                                case NORTH -> slot = SLOT_READ;
×
122
                                case SOUTH -> slot = SLOT_READ;
×
123
                                case WEST -> slot = SLOT_READ;
×
124
                                case EAST -> slot = SLOT_READ;
×
125
                            }
126
                        } else {
127
                            slot = SLOT_READ;
×
128
                        }
129
                        return VanillaContainerWrapper.of(new InventorySlotMasked(blockEntity.getInventory(), slot));
×
130
                    }
131
            );
132
            add(
4✔
133
                    Capabilities.NetworkElementProvider.BLOCK,
134
                    (blockEntity, direction) -> blockEntity.getNetworkElementProvider()
3✔
135
            );
136
        }
1✔
137
    }
138

139
    @Override
140
    public INetworkElementProvider getNetworkElementProvider() {
141
        return new NetworkElementProviderSingleton() {
8✔
142
            @Override
143
            public INetworkElement createNetworkElement(Level world, BlockPos blockPos) {
144
                return new DelayNetworkElement(DimPos.of(world, blockPos));
7✔
145
            }
146
        };
147
    }
148

149
    @Override
150
    public ItemStack writeProxyInfo(boolean generateId, ItemStack itemStack, final int proxyId) {
151
        IVariableFacadeHandlerRegistry registry = IntegratedDynamics._instance.getRegistryManager().getRegistry(IVariableFacadeHandlerRegistry.class);
6✔
152
        return registry.writeVariableFacadeItem(generateId, itemStack, DelayVariableFacadeHandler.getInstance(), new IVariableFacadeHandlerRegistry.IVariableFacadeFactory<IDelayVariableFacade>() {
18✔
153
            @Override
154
            public IDelayVariableFacade create(boolean generateId) {
155
                return new DelayVariableFacade(generateId, proxyId);
7✔
156
            }
157

158
            @Override
159
            public IDelayVariableFacade create(int id) {
160
                return new DelayVariableFacade(id, proxyId);
×
161
            }
162
        }, getLevel(), lastPlayer, getBlockState());
5✔
163
    }
164

165
    @Override
166
    public IVariable<?> getVariable(IPartNetwork network) {
167
        return variable;
3✔
168
    }
169

170
    public IVariable<?> getVariableSuper(IPartNetwork network) {
171
        return super.getVariable(network);
4✔
172
    }
173

174
    public void setCapacity(int capacity) {
175
        this.capacity = Math.max(1, capacity);
×
176
        this.values = Queues.newArrayBlockingQueue(this.capacity);
×
177
    }
×
178

179
    public Queue<IValue> getValues() {
180
        if (values == null) {
3✔
181
            values = Queues.newArrayBlockingQueue(this.capacity);
5✔
182
        }
183
        return values;
3✔
184
    }
185

186
    @Override
187
    public void saveAdditional(ValueOutput output) {
188
        super.saveAdditional(output);
3✔
189
        ValueOutput.ValueOutputList valueList = output.childrenList("values");
4✔
190
        for (IValue value : getValues()) {
11✔
191
            ValueHelpers.serialize(valueList.addChild(), value);
4✔
192
        }
1✔
193
    }
1✔
194

195
    @Override
196
    public void read(ValueInput input) {
197
        super.read(input);
3✔
198
        if (this.capacity <= 0) this.capacity = 1;
3!
199
        values = Queues.newArrayBlockingQueue(this.capacity);
5✔
200

201
        for (ValueInput valueInput : input.childrenList("values").orElseThrow()) {
14✔
202
            IValue value = ValueHelpers.deserialize(valueInput);
3✔
203
            if (value != null) {
2!
204
                this.values.add(value);
5✔
205
            }
206
        }
1✔
207
    }
1✔
208

209
    @Nullable
210
    @Override
211
    public AbstractContainerMenu createMenu(int id, Inventory playerInventory, Player playerEntity) {
212
        return new ContainerDelay(id, playerInventory, this.getInventory(), Optional.of(this));
×
213
    }
214

215
    @Override
216
    public Component getDisplayName() {
217
        return Component.translatable("block.integrateddynamics.delay");
×
218
    }
219

220
    public static class Ticker extends BlockEntityProxy.Ticker<BlockEntityDelay> {
3✔
221
        @Override
222
        protected void update(Level level, BlockPos pos, BlockState blockState, BlockEntityDelay blockEntity) {
223
            super.update(level, pos, blockState, blockEntity);
6✔
224

225
            if (!level.isClientSide() && blockEntity.updateInterval > 0 && level.getGameTime() % blockEntity.updateInterval == 0) {
15!
226
                // Remove oldest elements from the queue until we have room for a new one.
227
                while (blockEntity.getValues().size() >= blockEntity.capacity) {
6✔
228
                    blockEntity.getValues().poll();
5✔
229
                }
230

231
                IPartNetwork partNetwork = NetworkHelpers.getPartNetwork(blockEntity.getNetwork()).orElse(null);
7✔
232
                if (partNetwork == null) {
2!
233
                    return;
×
234
                }
235

236
                // Add new value to the queue
237
                IVariable<?> variable = blockEntity.getVariableSuper(partNetwork);
4✔
238
                IValue value = null;
2✔
239
                if (variable != null) {
2✔
240
                    try {
241
                        value = variable.getValue();
3✔
242
                        blockEntity.lastError = null;
3✔
243
                    } catch (EvaluationException e) {
×
244
                        blockEntity.getEvaluator().addError(e.getErrorMessage());
×
245
                        blockEntity.lastError = e;
×
246
                    }
1✔
247
                    if (value != null) {
2!
248
                        try {
249
                            if (blockEntity.list.getRawValue().getLength() > 0 && blockEntity.list.getRawValue().getValueType() != value.getType()) {
12!
250
                                blockEntity.getValues().clear();
×
251
                            }
252
                        } catch (EvaluationException e) {}
1✔
253
                        blockEntity.getValues().add(value);
5✔
254

255
                        // Update variable with as value the materialized queue list
256
                        blockEntity.list = ValueTypeList.ValueList.ofList(value.getType(), Lists.newArrayList(blockEntity.values));
9✔
257
                    }
258
                } else {
259
                    blockEntity.getValues().clear();
3✔
260
                    blockEntity.list = ValueTypes.LIST.getDefault();
4✔
261
                }
262
                blockEntity.variable.invalidate();
3✔
263
            }
264
        }
1✔
265
    }
266
}
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