• 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

54.55
/src/main/java/org/cyclops/integrateddynamics/blockentity/BlockEntityMaterializer.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.integrateddynamics.Capabilities;
18
import org.cyclops.integrateddynamics.IntegratedDynamics;
19
import org.cyclops.integrateddynamics.RegistryEntries;
20
import org.cyclops.integrateddynamics.api.evaluate.EvaluationException;
21
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
22
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueType;
23
import org.cyclops.integrateddynamics.api.evaluate.variable.IVariable;
24
import org.cyclops.integrateddynamics.api.item.IValueTypeVariableFacade;
25
import org.cyclops.integrateddynamics.api.item.IVariableFacadeHandlerRegistry;
26
import org.cyclops.integrateddynamics.api.network.INetworkElement;
27
import org.cyclops.integrateddynamics.api.network.INetworkElementProvider;
28
import org.cyclops.integrateddynamics.capability.networkelementprovider.NetworkElementProviderSingleton;
29
import org.cyclops.integrateddynamics.core.blockentity.BlockEntityActiveVariableBase;
30
import org.cyclops.integrateddynamics.core.blockentity.BlockEntityCableConnectableInventory;
31
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypes;
32
import org.cyclops.integrateddynamics.core.helper.NetworkHelpers;
33
import org.cyclops.integrateddynamics.core.item.ValueTypeVariableFacade;
34
import org.cyclops.integrateddynamics.inventory.container.ContainerMaterializer;
35
import org.cyclops.integrateddynamics.network.MaterializerNetworkElement;
36

37
import javax.annotation.Nullable;
38
import java.util.Optional;
39
import java.util.function.Supplier;
40

41
/**
42
 * A part entity for the variable materializer.
43
 * @author rubensworks
44
 */
45
public class BlockEntityMaterializer extends BlockEntityActiveVariableBase<MaterializerNetworkElement> implements MenuProvider {
46

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

52
    private Player lastPlayer = null;
3✔
53
    private boolean writeVariable;
54

55
    public void setLastPlayer(Player lastPlayer) {
56
        this.lastPlayer = lastPlayer;
×
57
    }
×
58

59
    public BlockEntityMaterializer(BlockPos blockPos, BlockState blockState) {
60
        super(RegistryEntries.BLOCK_ENTITY_MATERIALIZER.get(), blockPos, blockState, BlockEntityMaterializer.INVENTORY_SIZE);
8✔
61
    }
1✔
62

63
    public static class CapabilityRegistrar extends BlockEntityCableConnectableInventory.CapabilityRegistrar<BlockEntityMaterializer> {
64
        public CapabilityRegistrar(Supplier<BlockEntityType<? extends BlockEntityMaterializer>> blockEntityType) {
65
            super(blockEntityType);
3✔
66
        }
1✔
67

68
        @Override
69
        public void populate() {
70
            super.populate();
2✔
71

72
            add(
4✔
73
                    net.neoforged.neoforge.capabilities.Capabilities.Item.BLOCK,
74
                    (blockEntity, direction) -> {
75
                        int slot = -1;
×
76
                        if (direction != null) {
×
77
                            switch (direction) {
×
78
                                case DOWN -> slot = SLOT_WRITE_OUT;
×
79
                                case UP -> slot = SLOT_WRITE_IN;
×
80
                                case NORTH -> slot = SLOT_READ;
×
81
                                case SOUTH -> slot = SLOT_READ;
×
82
                                case WEST -> slot = SLOT_READ;
×
83
                                case EAST -> slot = SLOT_READ;
×
84
                            }
85
                        } else {
86
                            slot = SLOT_READ;
×
87
                        }
88
                        return VanillaContainerWrapper.of(new InventorySlotMasked(blockEntity.getInventory(), slot));
×
89
                    }
90
            );
91
            add(
4✔
92
                    Capabilities.NetworkElementProvider.BLOCK,
93
                    (blockEntity, direction) -> blockEntity.getNetworkElementProvider()
3✔
94
            );
95
        }
1✔
96
    }
97

98
    @Override
99
    public INetworkElementProvider getNetworkElementProvider() {
100
        return new NetworkElementProviderSingleton() {
8✔
101
            @Override
102
            public INetworkElement createNetworkElement(Level world, BlockPos blockPos) {
103
                return new MaterializerNetworkElement(DimPos.of(world, blockPos));
7✔
104
            }
105
        };
106
    }
107

108
    @Override
109
    protected SimpleInventory createInventory(int inventorySize, int stackSize) {
110
        return new SimpleInventory(inventorySize, stackSize) {
12✔
111
            @Override
112
            public boolean canPlaceItem(int slot, ItemStack itemStack) {
113
                return slot != SLOT_WRITE_OUT && super.canPlaceItem(slot, itemStack);
×
114
            }
115
        };
116
    }
117

118
    @Override
119
    public int getSlotRead() {
120
        return SLOT_READ;
2✔
121
    }
122

123
    protected boolean canWrite() {
124
        return NetworkHelpers.getPartNetwork(getNetwork())
6✔
125
                .map(partNetwork -> getVariable(partNetwork) != null && getEvaluator().getErrors().isEmpty())
15!
126
                .orElse(false);
4✔
127
    }
128

129
    @Override
130
    public void onDirty() {
131
        super.onDirty();
2✔
132
        if (!level.isClientSide()) {
4!
133
            this.writeVariable = true;
3✔
134
        }
135
    }
1✔
136

137
    public ItemStack writeMaterialized(boolean generateId, ItemStack itemStack) {
138
        IVariableFacadeHandlerRegistry registry = IntegratedDynamics._instance.getRegistryManager().getRegistry(IVariableFacadeHandlerRegistry.class);
6✔
139
        IVariable variable = getVariable(NetworkHelpers.getPartNetworkChecked(getNetwork()));
6✔
140
        try {
141
            final IValue value = variable.getType().materialize(variable.getValue());
6✔
142
            final IValueType valueType = value.getType();
3✔
143
            return registry.writeVariableFacadeItem(generateId, itemStack, ValueTypes.REGISTRY, new IVariableFacadeHandlerRegistry.IVariableFacadeFactory<IValueTypeVariableFacade>() {
22✔
144
                @Override
145
                public IValueTypeVariableFacade create(boolean generateId) {
146
                    return new ValueTypeVariableFacade(generateId, valueType, value);
9✔
147
                }
148

149
                @Override
150
                public IValueTypeVariableFacade create(int id) {
151
                    return new ValueTypeVariableFacade(id, valueType, value);
×
152
                }
153
            }, getLevel(), lastPlayer, getBlockState());
5✔
154
        } catch (EvaluationException e) {
×
155
            getEvaluator().addError(Component.translatable(e.getMessage()));
×
156
        }
157
        return ItemStack.EMPTY;
×
158
    }
159

160
    @Nullable
161
    @Override
162
    public AbstractContainerMenu createMenu(int id, Inventory playerInventory, Player playerEntity) {
163
        return new ContainerMaterializer(id, playerInventory, this.getInventory(), Optional.of(this));
×
164
    }
165

166
    @Override
167
    public Component getDisplayName() {
168
        return Component.translatable("block.integrateddynamics.materializer");
×
169
    }
170

171
    public static class Ticker extends BlockEntityCableConnectableInventory.Ticker<BlockEntityMaterializer> {
3✔
172
        @Override
173
        protected void update(Level level, BlockPos pos, BlockState blockState, BlockEntityMaterializer blockEntity) {
174
            super.update(level, pos, blockState, blockEntity);
6✔
175

176
            if (blockEntity.writeVariable && !blockEntity.getInventory().getItem(SLOT_WRITE_IN).isEmpty() && blockEntity.canWrite() && blockEntity.getInventory().getItem(SLOT_WRITE_OUT).isEmpty()) {
18!
177
                blockEntity.writeVariable = false;
3✔
178

179
                // Write proxy reference
180
                ItemStack outputStack = blockEntity.writeMaterialized(!blockEntity.getLevel().isClientSide(), blockEntity.getInventory().getItem(SLOT_WRITE_IN));
13!
181
                if(!outputStack.isEmpty()) {
3!
182
                    blockEntity.getInventory().setItem(SLOT_WRITE_OUT, outputStack);
5✔
183
                    blockEntity.getInventory().removeItemNoUpdate(SLOT_WRITE_IN);
5✔
184
                }
185
            }
186
        }
1✔
187
    }
188
}
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