• 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

4.08
/src/main/java/org/cyclops/integrateddynamics/core/evaluate/variable/ValueObjectTypeBlock.java
1
package org.cyclops.integrateddynamics.core.evaluate.variable;
2

3
import lombok.ToString;
4
import net.minecraft.core.registries.BuiltInRegistries;
5
import net.minecraft.network.chat.Component;
6
import net.minecraft.network.chat.MutableComponent;
7
import net.minecraft.world.item.BlockItem;
8
import net.minecraft.world.item.ItemStack;
9
import net.minecraft.world.level.block.Blocks;
10
import net.minecraft.world.level.block.state.BlockState;
11
import net.minecraft.world.level.storage.ValueInput;
12
import net.minecraft.world.level.storage.ValueOutput;
13
import org.cyclops.cyclopscore.helper.IModHelpers;
14
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueTypeNamed;
15
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueTypeNullable;
16
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueTypeUniquelyNamed;
17
import org.cyclops.integrateddynamics.core.helper.L10NValues;
18
import org.cyclops.integrateddynamics.core.logicprogrammer.ValueTypeItemStackLPElement;
19
import org.cyclops.integrateddynamics.core.logicprogrammer.ValueTypeLPElementBase;
20

21
/**
22
 * Value type with values that are blocks (these are internally stored as blockstates).
23
 * @author rubensworks
24
 */
25
public class ValueObjectTypeBlock extends ValueObjectTypeBase<ValueObjectTypeBlock.ValueBlock> implements
26
        IValueTypeNamed<ValueObjectTypeBlock.ValueBlock>, IValueTypeUniquelyNamed<ValueObjectTypeBlock.ValueBlock>,
27
        IValueTypeNullable<ValueObjectTypeBlock.ValueBlock> {
28

29
    public ValueObjectTypeBlock() {
30
        super("block", ValueObjectTypeBlock.ValueBlock.class);
4✔
31
    }
1✔
32

33
    public static MutableComponent getBlockkDisplayNameSafe(BlockState blockState) {
34
        return Component.translatable(blockState.getBlock().getDescriptionId());
×
35
    }
36

37
    @Override
38
    public ValueBlock getDefault() {
39
        return ValueBlock.of(Blocks.AIR.defaultBlockState());
×
40
    }
41

42
    @Override
43
    public MutableComponent toCompactString(ValueBlock value) {
44
        if (value.getRawValue().isPresent()) {
×
45
            BlockState blockState = value.getRawValue().get();
×
46
            ItemStack itemStack = IModHelpers.get().getBlockHelpers().getItemStackFromBlockState(blockState);
×
47
            if (!itemStack.isEmpty()) {
×
48
                return ValueObjectTypeItemStack.getItemStackDisplayNameSafe(itemStack);
×
49
            }
50
            return ValueObjectTypeBlock.getBlockkDisplayNameSafe(blockState);
×
51
        }
52
        return Component.literal("");
×
53
    }
54

55
    @Override
56
    public void serialize(ValueOutput valueOutput, ValueBlock value) {
57
        value.getRawValue().ifPresent(v -> valueOutput.store("v", BlockState.CODEC, v));
×
58
    }
×
59

60
    @Override
61
    public ValueBlock deserialize(ValueInput valueInput) {
62
        return ValueBlock.of(valueInput.read("v", BlockState.CODEC).orElseGet(Blocks.AIR::defaultBlockState));
×
63
    }
64

65
    @Override
66
    public String getName(ValueBlock a) {
67
        return toCompactString(a).getString();
×
68
    }
69

70
    @Override
71
    public boolean isNull(ValueBlock a) {
72
        return !a.getRawValue().isPresent();
×
73
    }
74

75
    @Override
76
    public ValueTypeLPElementBase createLogicProgrammerElement() {
77
        return new ValueTypeItemStackLPElement<>(this, new ValueTypeItemStackLPElement.IItemStackToValue<ValueObjectTypeBlock.ValueBlock>() {
×
78
            @Override
79
            public boolean isNullable() {
80
                return true;
×
81
            }
82

83
            @Override
84
            public Component validate(ItemStack itemStack) {
85
                if(!itemStack.isEmpty() && !(itemStack.getItem() instanceof BlockItem)) {
×
86
                    return Component.translatable(L10NValues.VALUETYPE_OBJECT_BLOCK_ERROR_NOBLOCK);
×
87
                }
88
                return null;
×
89
            }
90

91
            @Override
92
            public ValueObjectTypeBlock.ValueBlock getValue(ItemStack itemStack) {
93
                return ValueObjectTypeBlock.ValueBlock.of(
×
94
                        itemStack.isEmpty() ? Blocks.AIR.defaultBlockState() : IModHelpers.get().getBlockHelpers().getBlockStateFromItemStack(itemStack));
×
95
            }
96

97
            @Override
98
            public ItemStack getValueAsItemStack(ValueBlock value) {
99
                return value.getRawValue()
×
100
                        .map(IModHelpers.get().getBlockHelpers()::getItemStackFromBlockState)
×
101
                        .orElse(ItemStack.EMPTY);
×
102
            }
103
        });
104
    }
105

106
    @Override
107
    public String getUniqueName(ValueBlock value) {
108
        if (value.getRawValue().isPresent()) {
×
109
            BlockState blockState = value.getRawValue().get();
×
110
            return BuiltInRegistries.BLOCK.getKey(blockState.getBlock()).toString();
×
111
        }
112
        return "";
×
113
    }
114

115
    @ToString
×
116
    public static class ValueBlock extends ValueOptionalBase<BlockState> {
117

118
        private ValueBlock(BlockState blockState) {
119
            super(ValueTypes.OBJECT_BLOCK, blockState);
×
120
        }
×
121

122
        public static ValueBlock of(BlockState blockState) {
123
            return new ValueBlock(blockState);
×
124
        }
125

126
        @Override
127
        protected boolean isEqual(BlockState a, BlockState b) {
128
            return a.equals(b);
×
129
        }
130
    }
131

132
}
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