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

CyclopsMC / IntegratedDynamics / 15234441513

25 May 2025 05:02AM UTC coverage: 45.524% (-0.02%) from 45.542%
15234441513

push

github

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

2556 of 8407 branches covered (30.4%)

Branch coverage included in aggregate %.

11877 of 23297 relevant lines covered (50.98%)

2.42 hits per line

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

51.06
/src/main/java/org/cyclops/integrateddynamics/part/aspect/AspectBase.java
1
package org.cyclops.integrateddynamics.part.aspect;
2

3
import net.minecraft.network.chat.Component;
4
import net.minecraft.resources.ResourceLocation;
5
import net.minecraft.world.MenuProvider;
6
import net.minecraft.world.SimpleContainer;
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 org.apache.commons.lang3.tuple.Triple;
11
import org.cyclops.cyclopscore.helper.IModHelpers;
12
import org.cyclops.cyclopscore.init.ModBaseNeoForge;
13
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
14
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueType;
15
import org.cyclops.integrateddynamics.api.part.IPartContainer;
16
import org.cyclops.integrateddynamics.api.part.IPartState;
17
import org.cyclops.integrateddynamics.api.part.IPartType;
18
import org.cyclops.integrateddynamics.api.part.PartPos;
19
import org.cyclops.integrateddynamics.api.part.PartTarget;
20
import org.cyclops.integrateddynamics.api.part.aspect.IAspect;
21
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
22
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectPropertyTypeInstance;
23
import org.cyclops.integrateddynamics.core.helper.L10NValues;
24
import org.cyclops.integrateddynamics.core.helper.PartHelpers;
25
import org.cyclops.integrateddynamics.core.inventory.container.ContainerAspectSettings;
26
import org.cyclops.integrateddynamics.core.part.PartTypeBase;
27

28
import javax.annotation.Nullable;
29
import java.util.Collection;
30
import java.util.Collections;
31
import java.util.List;
32
import java.util.Optional;
33

34
/**
35
 * Base class for aspects.
36
 * @author rubensworks
37
 */
38
public abstract class AspectBase<V extends IValue, T extends IValueType<V>> implements IAspect<V, T> {
39

40
    private final IAspectProperties defaultProperties;
41

42
    private final ModBaseNeoForge mod;
43
    private String translationKey = null;
3✔
44

45
    public AspectBase(ModBaseNeoForge mod, IAspectProperties defaultProperties) {
2✔
46
        this.mod = mod;
3✔
47
        this.defaultProperties = defaultProperties == null ? createDefaultProperties() : defaultProperties;
8✔
48
    }
1✔
49

50
    @Override
51
    public ResourceLocation getUniqueName() {
52
        return ResourceLocation.fromNamespaceAndPath(getModId(), getUnlocalizedType().replaceAll("\\.", "_"));
9✔
53
    }
54

55
    @Override
56
    public String getTranslationKey() {
57
        return translationKey != null ? translationKey : (translationKey = getUnlocalizedPrefix());
×
58
    }
59

60
    protected String getUnlocalizedPrefix() {
61
        return "aspect." + getModId() + "." + getUnlocalizedType();
×
62
    }
63

64
    protected abstract String getUnlocalizedType();
65

66
    @Override
67
    public void loadTooltip(List<Component> lines, boolean appendOptionalInfo) {
68
        Component aspectName = Component.translatable(getTranslationKey());
×
69
        Component valueTypeName = Component.translatable(getValueType().getTranslationKey());
×
70
        lines.add(Component.translatable(L10NValues.ASPECT_TOOLTIP_ASPECTNAME, aspectName));
×
71
        lines.add(Component.translatable(L10NValues.ASPECT_TOOLTIP_VALUETYPENAME, valueTypeName)
×
72
                .withStyle(getValueType().getDisplayColorFormat()));
×
73
        if(appendOptionalInfo) {
×
74
            IModHelpers.get().getL10NHelpers().addOptionalInfo(lines, getUnlocalizedPrefix());
×
75
        }
76
    }
×
77

78
    @Override
79
    public <P extends IPartType<P, S>, S extends IPartState<P>> boolean hasProperties() {
80
        return getDefaultProperties() != null;
7✔
81
    }
82

83
    @Override
84
    public <P extends IPartType<P, S>, S extends IPartState<P>> IAspectProperties getProperties(P partType, PartTarget target, S state) {
85
        IAspectProperties properties = state.getAspectProperties(this);
4✔
86
        if(properties == null) {
2✔
87
            properties = getDefaultProperties().clone();
4✔
88
            setProperties(partType, target, state, properties);
6✔
89
        }
90
        return properties;
2✔
91
    }
92

93
    @Override
94
    public <P extends IPartType<P, S>, S extends IPartState<P>> void setProperties(P partType, PartTarget target, S state, IAspectProperties properties) {
95
        state.setAspectProperties(this, properties);
4✔
96
    }
1✔
97

98
    @Override
99
    public final IAspectProperties getDefaultProperties() {
100
        return defaultProperties;
3✔
101
    }
102

103
    @SuppressWarnings("deprecation")
104
    @Override
105
    public Collection<IAspectPropertyTypeInstance> getPropertyTypes() {
106
        return hasProperties() ? getDefaultProperties().getTypes() : Collections.emptyList();
×
107
    }
108

109
    @Override
110
    public MenuProvider getPropertiesContainerProvider(PartPos pos) {
111
        return new MenuProvider() {
×
112
            @Override
113
            public Component getDisplayName() {
114
                return Component.translatable("gui.integrateddynamics.aspect_settings");
×
115
            }
116

117
            @Nullable
118
            @Override
119
            public AbstractContainerMenu createMenu(int id, Inventory playerInventory, Player playerEntity) {
120
                Triple<IPartContainer, PartTypeBase, PartTarget> data = PartHelpers.getContainerPartConstructionData(pos);
×
121
                return new ContainerAspectSettings(id, playerInventory, new SimpleContainer(0),
×
122
                        Optional.of(data.getRight()), Optional.of(data.getLeft()), Optional.of(data.getMiddle()), AspectBase.this);
×
123
            }
124

125
            @Override
126
            public boolean shouldTriggerClientSideContainerClosingOnOpen() {
127
                return false;
×
128
            }
129
        };
130
    }
131

132
    /**
133
     * Creates the default properties for this aspect, only called once.
134
     * @return The default properties.
135
     */
136
    @Deprecated
137
    protected IAspectProperties createDefaultProperties() {
138
        return null;
2✔
139
    }
140

141
    protected ModBaseNeoForge getMod() {
142
        return mod;
3✔
143
    }
144

145
    protected String getModId() {
146
        return getMod().getModId();
4✔
147
    }
148

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