• 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

58.33
/src/main/java/org/cyclops/integrateddynamics/blockentity/BlockEntityProxy.java
1
package org.cyclops.integrateddynamics.blockentity;
2

3
import net.minecraft.core.BlockPos;
4
import net.minecraft.network.chat.Component;
5
import net.minecraft.world.MenuProvider;
6
import net.minecraft.world.entity.player.Inventory;
7
import net.minecraft.world.entity.player.Player;
8
import net.minecraft.world.inventory.AbstractContainerMenu;
9
import net.minecraft.world.item.ItemStack;
10
import net.minecraft.world.level.Level;
11
import net.minecraft.world.level.block.entity.BlockEntityType;
12
import net.minecraft.world.level.block.state.BlockState;
13
import net.neoforged.neoforge.transfer.item.VanillaContainerWrapper;
14
import org.cyclops.cyclopscore.datastructure.DimPos;
15
import org.cyclops.cyclopscore.inventory.InventorySlotMasked;
16
import org.cyclops.cyclopscore.inventory.SimpleInventory;
17
import org.cyclops.cyclopscore.persist.nbt.NBTPersist;
18
import org.cyclops.integrateddynamics.Capabilities;
19
import org.cyclops.integrateddynamics.IntegratedDynamics;
20
import org.cyclops.integrateddynamics.RegistryEntries;
21
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
22
import org.cyclops.integrateddynamics.api.evaluate.variable.ValueDeseralizationContext;
23
import org.cyclops.integrateddynamics.api.item.IProxyVariableFacade;
24
import org.cyclops.integrateddynamics.api.item.IVariableFacadeHandlerRegistry;
25
import org.cyclops.integrateddynamics.api.network.INetworkElement;
26
import org.cyclops.integrateddynamics.api.network.INetworkElementProvider;
27
import org.cyclops.integrateddynamics.capability.networkelementprovider.NetworkElementProviderSingleton;
28
import org.cyclops.integrateddynamics.core.blockentity.BlockEntityActiveVariableBase;
29
import org.cyclops.integrateddynamics.core.blockentity.BlockEntityCableConnectableInventory;
30
import org.cyclops.integrateddynamics.core.evaluate.InventoryVariableEvaluator;
31
import org.cyclops.integrateddynamics.core.evaluate.ProxyVariableFacadeHandler;
32
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypes;
33
import org.cyclops.integrateddynamics.core.helper.L10NValues;
34
import org.cyclops.integrateddynamics.core.helper.NetworkHelpers;
35
import org.cyclops.integrateddynamics.core.item.ProxyVariableFacade;
36
import org.cyclops.integrateddynamics.inventory.container.ContainerProxy;
37
import org.cyclops.integrateddynamics.network.ProxyNetworkElement;
38

39
import javax.annotation.Nullable;
40
import java.util.Optional;
41
import java.util.function.Supplier;
42

43
/**
44
 * A part entity for the variable proxy.
45
 * @author rubensworks
46
 */
47
public class BlockEntityProxy extends BlockEntityActiveVariableBase<ProxyNetworkElement> implements MenuProvider {
48

49
    public static final int INVENTORY_SIZE = 3;
50
    public static final int SLOT_READ = 0;
51
    public static final int SLOT_WRITE_IN = 1;
52
    public static final int SLOT_WRITE_OUT = 2;
53

54
    public static final String GLOBALCOUNTER_KEY = "proxy";
55

56
    @NBTPersist
3✔
57
    private int proxyId = -1;
58

59
    private Player lastPlayer = null;
3✔
60
    private boolean writeVariable;
61

62
    public int getProxyId() {
63
        return proxyId;
3✔
64
    }
65

66
    public void setProxyId(int proxyId) {
67
        this.proxyId = proxyId;
×
68
    }
×
69

70
    public void setLastPlayer(Player lastPlayer) {
71
        this.lastPlayer = lastPlayer;
×
72
    }
×
73

74
    public BlockEntityProxy(BlockPos blockPos, BlockState blockState) {
75
        this(RegistryEntries.BLOCK_ENTITY_PROXY.get(), blockPos, blockState, BlockEntityProxy.INVENTORY_SIZE);
8✔
76
    }
1✔
77

78
    public BlockEntityProxy(BlockEntityType<?> type, BlockPos blockPos, BlockState blockState, int inventorySize) {
79
        super(type, blockPos, blockState, inventorySize);
6✔
80
    }
1✔
81

82
    public static class CapabilityRegistrar extends BlockEntityActiveVariableBase.CapabilityRegistrar<BlockEntityProxy> {
83
        public CapabilityRegistrar(Supplier<BlockEntityType<? extends BlockEntityProxy>> blockEntityType) {
84
            super(blockEntityType);
3✔
85
        }
1✔
86

87
        @Override
88
        public void populate() {
89
            super.populate();
2✔
90

91
            add(
4✔
92
                    net.neoforged.neoforge.capabilities.Capabilities.Item.BLOCK,
93
                    (blockEntity, direction) -> {
94
                        int slot = -1;
×
95
                        if (direction != null) {
×
96
                            switch (direction) {
×
97
                                case DOWN -> slot = SLOT_WRITE_OUT;
×
98
                                case UP -> slot = SLOT_WRITE_IN;
×
99
                                case NORTH -> slot = SLOT_READ;
×
100
                                case SOUTH -> slot = SLOT_READ;
×
101
                                case WEST -> slot = SLOT_READ;
×
102
                                case EAST -> slot = SLOT_READ;
×
103
                            }
104
                        } else {
105
                            slot = SLOT_READ;
×
106
                        }
107
                        return VanillaContainerWrapper.of(new InventorySlotMasked(blockEntity.getInventory(), slot));
×
108
                    }
109
            );
110
            add(
4✔
111
                    Capabilities.NetworkElementProvider.BLOCK,
112
                    (blockEntity, direction) -> blockEntity.getNetworkElementProvider()
3✔
113
            );
114
        }
1✔
115
    }
116

117
    @Override
118
    public INetworkElementProvider getNetworkElementProvider() {
119
        return new NetworkElementProviderSingleton() {
8✔
120
            @Override
121
            public INetworkElement createNetworkElement(Level world, BlockPos blockPos) {
122
                return new ProxyNetworkElement(DimPos.of(world, blockPos));
7✔
123
            }
124
        };
125
    }
126

127
    public boolean isWriteVariable() {
128
        return writeVariable;
3✔
129
    }
130

131
    @Override
132
    protected SimpleInventory createInventory(int inventorySize, int stackSize) {
133
        return new SimpleInventory(inventorySize, stackSize) {
12✔
134
            @Override
135
            public boolean canPlaceItem(int slot, ItemStack itemStack) {
136
                return slot != SLOT_WRITE_OUT && super.canPlaceItem(slot, itemStack);
×
137
            }
138
        };
139
    }
140

141
    @Override
142
    protected InventoryVariableEvaluator<IValue> createEvaluator() {
143
        return new InventoryVariableEvaluator<IValue>(this.getInventory(), getSlotRead(), () -> ValueDeseralizationContext.of(getLevel()), ValueTypes.CATEGORY_ANY) {
26✔
144
            @Override
145
            protected void preValidate() {
146
                super.preValidate();
2✔
147
                // Hard check to make sure the variable is not directly referring to this proxy.
148
                if(getVariableFacade() instanceof IProxyVariableFacade) {
4!
149
                    if(((IProxyVariableFacade) getVariableFacade()).getProxyId() == getProxyId()) {
×
150
                        addError(Component.translatable(L10NValues.VARIABLE_ERROR_RECURSION, getVariableFacade().getId()));
×
151
                    }
152
                }
153
            }
1✔
154
        };
155
    }
156

157
    /**
158
     * This will generate a new proxy id.
159
     * Be careful when calling this!
160
     */
161
    public void generateNewProxyId() {
162
        this.proxyId = IntegratedDynamics.globalCounters.get().getNext(GLOBALCOUNTER_KEY);
7✔
163
        setChanged();
2✔
164
    }
1✔
165

166
    @Override
167
    public int getSlotRead() {
168
        return SLOT_READ;
2✔
169
    }
170

171
    protected int getSlotWriteIn() {
172
        return SLOT_WRITE_IN;
2✔
173
    }
174

175
    protected int getSlotWriteOut() {
176
        return SLOT_WRITE_OUT;
2✔
177
    }
178

179
    @Override
180
    public void onDirty() {
181
        super.onDirty();
2✔
182
        if (!level.isClientSide()) {
4!
183
            this.writeVariable = true;
3✔
184
        }
185
    }
1✔
186

187
    public ItemStack writeProxyInfo(boolean generateId, ItemStack itemStack, final int proxyId) {
188
        IVariableFacadeHandlerRegistry registry = IntegratedDynamics._instance.getRegistryManager().getRegistry(IVariableFacadeHandlerRegistry.class);
6✔
189
        return registry.writeVariableFacadeItem(generateId, itemStack, ProxyVariableFacadeHandler.getInstance(), new IVariableFacadeHandlerRegistry.IVariableFacadeFactory<IProxyVariableFacade>() {
18✔
190
            @Override
191
            public IProxyVariableFacade create(boolean generateId) {
192
                return new ProxyVariableFacade(generateId, proxyId);
7✔
193
            }
194

195
            @Override
196
            public IProxyVariableFacade create(int id) {
197
                return new ProxyVariableFacade(id, proxyId);
×
198
            }
199
        }, getLevel(), lastPlayer, getBlockState());
5✔
200
    }
201

202
    @Nullable
203
    @Override
204
    public AbstractContainerMenu createMenu(int id, Inventory playerInventory, Player playerEntity) {
205
        return new ContainerProxy(id, playerInventory, this.getInventory(), Optional.of(this));
×
206
    }
207

208
    @Override
209
    public Component getDisplayName() {
210
        return Component.translatable("block.integrateddynamics.proxy");
×
211
    }
212

213
    public static class Ticker<T extends BlockEntityProxy> extends BlockEntityCableConnectableInventory.Ticker<T> {
3✔
214
        @Override
215
        protected void update(Level level, BlockPos pos, BlockState blockState, T blockEntity) {
216
            super.update(level, pos, blockState, blockEntity);
6✔
217

218
            // If the block was placed by a non-player, this is needed.
219
            if (blockEntity.getProxyId() < 0) {
3✔
220
                blockEntity.generateNewProxyId();
2✔
221
                NetworkHelpers.initNetwork(level, pos, null);
5✔
222
            }
223

224
            if (blockEntity.isWriteVariable()) {
3✔
225
                if (!blockEntity.getInventory().getItem(blockEntity.getSlotWriteIn()).isEmpty() && blockEntity.getInventory().getItem(blockEntity.getSlotWriteOut()).isEmpty()) {
14!
226
                    // Write proxy reference
227
                    ItemStack outputStack = blockEntity.writeProxyInfo(!blockEntity.getLevel().isClientSide(), blockEntity.getInventory().removeItemNoUpdate(blockEntity.getSlotWriteIn()), blockEntity.getProxyId());
16!
228
                    blockEntity.getInventory().setItem(blockEntity.getSlotWriteOut(), outputStack);
6✔
229
                }
230
            }
231
        }
1✔
232
    }
233
}
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