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

CyclopsMC / IntegratedDynamics / 19594291637

22 Nov 2025 10:30AM UTC coverage: 53.061% (+0.006%) from 53.055%
19594291637

push

github

rubensworks
Merge remote-tracking branch 'origin/master-1.21-lts' into master-1.21

2886 of 8780 branches covered (32.87%)

Branch coverage included in aggregate %.

17360 of 29376 relevant lines covered (59.1%)

3.07 hits per line

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

55.81
/src/main/java/org/cyclops/integrateddynamics/blockentity/BlockEntityMaterializer.java
1
package org.cyclops.integrateddynamics.blockentity;
2

3
import lombok.Setter;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.network.chat.Component;
6
import net.minecraft.world.MenuProvider;
7
import net.minecraft.world.entity.player.Inventory;
8
import net.minecraft.world.entity.player.Player;
9
import net.minecraft.world.inventory.AbstractContainerMenu;
10
import net.minecraft.world.item.ItemStack;
11
import net.minecraft.world.level.Level;
12
import net.minecraft.world.level.block.entity.BlockEntityType;
13
import net.minecraft.world.level.block.state.BlockState;
14
import org.cyclops.cyclopscore.capability.item.ItemHandlerSlotMasked;
15
import org.cyclops.cyclopscore.datastructure.DimPos;
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
    @Setter
3✔
53
    private Player lastPlayer = null;
54
    private boolean writeVariable;
55

56
    public BlockEntityMaterializer(BlockPos blockPos, BlockState blockState) {
57
        super(RegistryEntries.BLOCK_ENTITY_MATERIALIZER.get(), blockPos, blockState, BlockEntityMaterializer.INVENTORY_SIZE);
8✔
58
    }
1✔
59

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

65
        @Override
66
        public void populate() {
67
            super.populate();
2✔
68

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

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

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

115
    @Override
116
    public int getSlotRead() {
117
        return SLOT_READ;
2✔
118
    }
119

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

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

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

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

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

163
    @Override
164
    public Component getDisplayName() {
165
        return Component.translatable("block.integrateddynamics.materializer");
×
166
    }
167

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

173
            if (blockEntity.writeVariable && !blockEntity.getInventory().getItem(SLOT_WRITE_IN).isEmpty() && blockEntity.canWrite() && blockEntity.getInventory().getItem(SLOT_WRITE_OUT).isEmpty()) {
18!
174
                blockEntity.writeVariable = false;
3✔
175

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