• 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

1.98
/src/main/java/org/cyclops/integrateddynamics/core/evaluate/variable/ValueObjectTypeEntity.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.server.level.ServerLevel;
8
import net.minecraft.world.entity.Entity;
9
import net.minecraft.world.entity.EntityType;
10
import net.minecraft.world.entity.item.ItemEntity;
11
import net.minecraft.world.level.storage.ValueInput;
12
import net.minecraft.world.level.storage.ValueOutput;
13
import net.neoforged.neoforge.server.ServerLifecycleHooks;
14
import org.cyclops.cyclopscore.helper.IModHelpers;
15
import org.cyclops.integrateddynamics.api.advancement.criterion.ValuePredicate;
16
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueTypeNamed;
17
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueTypeNullable;
18
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueTypeUniquelyNamed;
19
import org.cyclops.integrateddynamics.core.logicprogrammer.ValueTypeLPElementBase;
20

21
import javax.annotation.Nullable;
22
import java.util.Optional;
23
import java.util.UUID;
24

25
/**
26
 * Value type with values that are itemstacks.
27
 * @author rubensworks
28
 */
29
public class ValueObjectTypeEntity extends ValueObjectTypeBase<ValueObjectTypeEntity.ValueEntity> implements
30
        IValueTypeNamed<ValueObjectTypeEntity.ValueEntity>, IValueTypeUniquelyNamed<ValueObjectTypeEntity.ValueEntity>,
31
        IValueTypeNullable<ValueObjectTypeEntity.ValueEntity> {
32

33
    public ValueObjectTypeEntity() {
34
        super("entity", ValueObjectTypeEntity.ValueEntity.class);
4✔
35
    }
1✔
36

37
    @Override
38
    public ValueEntity getDefault() {
39
        return ValueEntity.of((UUID) null);
×
40
    }
41

42
    @Override
43
    public MutableComponent toCompactString(ValueEntity value) {
44
        Optional<UUID> uuid = value.getUuid();
×
45
        if (uuid.isPresent()) {
×
46
            Optional<Entity> entity = value.getRawValue();
×
47
            if(entity.isPresent()) {
×
48
                Entity e = entity.get();
×
49
                if(e instanceof ItemEntity) {
×
50
                    return (MutableComponent) ((ItemEntity) e).getItem().getHoverName();
×
51
                } else {
52
                    return (MutableComponent) e.getName();
×
53
                }
54
            }
55
            return Component.literal("unknown");
×
56
        }
57
        return Component.literal("");
×
58
    }
59

60
    @Override
61
    public void serialize(ValueOutput valueOutput, ValueEntity value) {
62
        value.getUuid().ifPresent(v -> valueOutput.putString("v", v.toString()));
×
63
    }
×
64

65
    @Override
66
    public ValueEntity deserialize(ValueInput valueInput) {
67
        return ValueEntity.of(valueInput.getString("v").map(UUID::fromString).orElse(null));
×
68
    }
69

70
    @Override
71
    public String getName(ValueEntity a) {
72
        return toCompactString(a).getString();
×
73
    }
74

75
    @Override
76
    public boolean isNull(ValueEntity a) {
77
        return !a.getRawValue().isPresent();
×
78
    }
79

80
    @Override
81
    public ValueTypeLPElementBase createLogicProgrammerElement() {
82
        return null;
×
83
    }
84

85
    @Override
86
    public String getUniqueName(ValueEntity value) {
87
        Optional<UUID> uuid = value.getUuid();
×
88
        if (uuid.isPresent()) {
×
89
            UUID id = uuid.get();
×
90
            String entityName = value.getRawValue()
×
91
                    .map(entity -> BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType()).toString())
×
92
                    .orElse("unknown");
×
93
            return id.toString() + " (" + entityName + ")";
×
94
        }
95
        return "";
×
96
    }
97

98
    @ToString
×
99
    public static class ValueEntity extends ValueBase {
100

101
        private final Optional<UUID> value;
102

103
        protected ValueEntity(@Nullable Entity value) {
104
            super(ValueTypes.OBJECT_ENTITY);
×
105
            this.value = value == null ? Optional.<UUID>empty() : Optional.of(value.getUUID());
×
106
        }
×
107

108
        private ValueEntity(@Nullable UUID entityUuid) {
109
            super(ValueTypes.OBJECT_ENTITY);
×
110
            this.value = Optional.ofNullable(entityUuid);
×
111
        }
×
112

113
        /**
114
         * @return The raw value in an optional holder.
115
         */
116
        public Optional<Entity> getRawValue() {
117
            Optional<UUID> uuid = getUuid();
×
118
            if (uuid.isPresent()) {
×
119
                if (IModHelpers.get().getMinecraftHelpers().isClientSideThread()) {
×
120
                    return ValueObjectTypeEntityClient.getEntity(uuid.get());
×
121
                }
122
                for (ServerLevel world : ServerLifecycleHooks.getCurrentServer().getAllLevels()) {
×
123
                    Entity entity = world.getEntity(uuid.get());
×
124
                    if (entity != null) {
×
125
                        return Optional.of(entity);
×
126
                    }
127
                }
×
128
            }
129
            return Optional.empty();
×
130
        }
131

132
        public Optional<UUID> getUuid() {
133
            return value;
×
134
        }
135

136
        @Override
137
        public boolean equals(Object o) {
138
            if(o instanceof ValueEntity) {
×
139
                if (((ValueEntity) o).value.isPresent() && value.isPresent()) {
×
140
                    return ((ValueEntity) o).value.get().equals(value.get());
×
141
                } else if (!((ValueEntity) o).value.isPresent() && !value.isPresent()) {
×
142
                    return true;
×
143
                }
144
            }
145
            return false;
×
146
        }
147

148
        @Override
149
        public int hashCode() {
150
            return getType().hashCode() + (getRawValue().isPresent() ? getRawValue().get().hashCode() : 0);
×
151
        }
152

153
        public static ValueEntity of(@Nullable Entity entity) {
154
            return new ValueEntity(entity);
×
155
        }
156

157
        public static ValueEntity of(@Nullable UUID entityUuid) {
158
            return new ValueEntity(entityUuid);
×
159
        }
160

161
    }
162

163
    public static class ValueEntityPredicate extends ValuePredicate<ValueEntity> {
164

165
        private final Optional<EntityType<? extends Entity>> entityType;
166

167
        public ValueEntityPredicate(Optional<EntityType<? extends Entity>> entityType) {
168
            super(Optional.of(ValueTypes.OBJECT_ENTITY), Optional.empty(), Optional.empty());
×
169
            this.entityType = entityType;
×
170
        }
×
171

172
        public Optional<EntityType<? extends Entity>> getEntityType() {
173
            return entityType;
×
174
        }
175

176
        @Override
177
        protected boolean testTyped(ValueEntity value) {
178
            return super.testTyped(value)
×
179
                    && (entityType.isEmpty()
×
180
                        || (value.getRawValue().isPresent() && value.getRawValue().get().getType() == entityType.get()));
×
181
        }
182
    }
183

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