• 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

6.98
/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 net.neoforged.neoforge.transfer.item.VanillaContainerWrapper;
15
import org.cyclops.cyclopscore.datastructure.DimPos;
16
import org.cyclops.cyclopscore.inventory.InventorySlotMasked;
17
import org.cyclops.cyclopscore.inventory.SimpleInventory;
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.EvaluationException;
22
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
23
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueType;
24
import org.cyclops.integrateddynamics.api.evaluate.variable.IVariable;
25
import org.cyclops.integrateddynamics.api.item.IValueTypeVariableFacade;
26
import org.cyclops.integrateddynamics.api.item.IVariableFacadeHandlerRegistry;
27
import org.cyclops.integrateddynamics.api.network.INetworkElement;
28
import org.cyclops.integrateddynamics.api.network.INetworkElementProvider;
29
import org.cyclops.integrateddynamics.capability.networkelementprovider.NetworkElementProviderSingleton;
30
import org.cyclops.integrateddynamics.core.blockentity.BlockEntityActiveVariableBase;
31
import org.cyclops.integrateddynamics.core.blockentity.BlockEntityCableConnectableInventory;
32
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypes;
33
import org.cyclops.integrateddynamics.core.helper.NetworkHelpers;
34
import org.cyclops.integrateddynamics.core.item.ValueTypeVariableFacade;
35
import org.cyclops.integrateddynamics.inventory.container.ContainerMaterializer;
36
import org.cyclops.integrateddynamics.network.MaterializerNetworkElement;
37

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

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

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

53
    @Setter
×
54
    private Player lastPlayer = null;
55
    private boolean writeVariable;
56

57
    public BlockEntityMaterializer(BlockPos blockPos, BlockState blockState) {
58
        super(RegistryEntries.BLOCK_ENTITY_MATERIALIZER.get(), blockPos, blockState, BlockEntityMaterializer.INVENTORY_SIZE);
×
59
    }
×
60

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

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

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

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

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

116
    @Override
117
    public int getSlotRead() {
118
        return SLOT_READ;
×
119
    }
120

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

127
    @Override
128
    public void onDirty() {
129
        super.onDirty();
×
130
        if (!level.isClientSide()) {
×
131
            this.writeVariable = true;
×
132
        }
133
    }
×
134

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

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

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

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

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

174
            if (blockEntity.writeVariable && !blockEntity.getInventory().getItem(SLOT_WRITE_IN).isEmpty() && blockEntity.canWrite() && blockEntity.getInventory().getItem(SLOT_WRITE_OUT).isEmpty()) {
×
175
                blockEntity.writeVariable = false;
×
176

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