File tree 5 files changed +15
-8
lines changed
src/main/java/de/dafuqs/spectrum/api/energy
5 files changed +15
-8
lines changed Original file line number Diff line number Diff line change 1
1
package de .dafuqs .spectrum .api .energy ;
2
2
3
3
import de .dafuqs .spectrum .api .energy .color .*;
4
- import de .dafuqs .spectrum .registries .*;
5
4
import net .minecraft .nbt .*;
6
5
import net .minecraft .text .*;
7
6
import net .minecraft .util .*;
@@ -165,9 +164,11 @@ default float getTotalFillPercent() {
165
164
Map <InkColor , Long > energy = new HashMap <>();
166
165
if (compound != null ) {
167
166
for (String key : compound .getKeys ()) {
168
- InkColor inkColor = SpectrumRegistries .INK_COLORS .get (new Identifier (key ));
169
- long amount = compound .getLong (key );
170
- energy .put (inkColor , amount );
167
+ Optional <InkColor > color = InkColor .ofIdString (key );
168
+ if (color .isPresent ()) {
169
+ long amount = compound .getLong (key );
170
+ energy .put (color .get (), amount );
171
+ }
171
172
}
172
173
}
173
174
return energy ;
Original file line number Diff line number Diff line change 1
1
package de .dafuqs .spectrum .api .energy .color ;
2
2
3
+ import de .dafuqs .spectrum .*;
3
4
import de .dafuqs .spectrum .helpers .*;
4
5
import de .dafuqs .spectrum .registries .*;
5
6
import net .minecraft .registry .tag .*;
@@ -46,7 +47,12 @@ public static Optional<InkColor> ofId(Identifier id) {
46
47
}
47
48
48
49
public static Optional <InkColor > ofIdString (String idString ) {
49
- return SpectrumRegistries .INK_COLORS .getOrEmpty (new Identifier (idString ));
50
+ try {
51
+ Identifier id = new Identifier (idString );
52
+ return SpectrumRegistries .INK_COLORS .getOrEmpty (id ).or (() -> SpectrumRegistries .INK_COLORS .getOrEmpty (SpectrumCommon .locate (idString )));
53
+ } catch (InvalidIdentifierException ignored ) {
54
+ return Optional .empty ();
55
+ }
50
56
}
51
57
52
58
public DyeColor getDyeColor () {
Original file line number Diff line number Diff line change @@ -130,7 +130,7 @@ public boolean isFull() {
130
130
131
131
public static IndividualCappedInkStorage fromNbt (@ NotNull NbtCompound compound ) {
132
132
long maxEnergyPerColor = compound .getLong ("MaxEnergyPerColor" );
133
- Map <InkColor , Long > colors = InkStorage .readEnergy (compound .getCompound ("Energy" ));
133
+ Map <InkColor , Long > colors = InkStorage .readEnergy (compound .contains ( "Energy" ) ? compound . getCompound ("Energy" ) : compound );
134
134
return new IndividualCappedInkStorage (maxEnergyPerColor , colors );
135
135
}
136
136
Original file line number Diff line number Diff line change @@ -132,7 +132,7 @@ public NbtCompound toNbt() {
132
132
133
133
public static TotalCappedElementalMixingInkStorage fromNbt (@ NotNull NbtCompound compound ) {
134
134
long maxEnergyTotal = compound .getLong ("MaxEnergyTotal" );
135
- Map <InkColor , Long > energy = InkStorage .readEnergy (compound .getCompound ("Energy" ));
135
+ Map <InkColor , Long > energy = InkStorage .readEnergy (compound .contains ( "Energy" ) ? compound . getCompound ("Energy" ) : compound );
136
136
return new TotalCappedElementalMixingInkStorage (maxEnergyTotal , energy );
137
137
}
138
138
Original file line number Diff line number Diff line change @@ -116,7 +116,7 @@ public NbtCompound toNbt() {
116
116
117
117
public static TotalCappedInkStorage fromNbt (@ NotNull NbtCompound compound ) {
118
118
long maxEnergyTotal = compound .getLong ("MaxEnergyTotal" );
119
- Map <InkColor , Long > colors = InkStorage .readEnergy (compound .getCompound ("Energy" ));
119
+ Map <InkColor , Long > colors = InkStorage .readEnergy (compound .contains ( "Energy" ) ? compound . getCompound ("Energy" ) : compound );
120
120
return new TotalCappedInkStorage (maxEnergyTotal , colors );
121
121
}
122
122
You can’t perform that action at this time.
0 commit comments