Skip to content

Commit

Permalink
Use OPTIONAL_CODEC for FluidStackComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Jul 15, 2024
1 parent 4bffc13 commit 4262852
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions src/main/java/dev/latvian/mods/kubejs/recipe/KubeRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void deserialize(boolean merge) {
v.write();
}
} else if (!v.key.optional()) {
throw new MissingComponentException(v.key.name, v.key, valueMap.keySet());
throw new MissingComponentException(v.key.name, v.key, valueMap.keySet()).source(sourceLine);
}
}
}
Expand All @@ -89,7 +89,7 @@ public void serialize() {
for (var v : valueMap.holders) {
if (v.shouldWrite()) {
if (v.value == null) {
throw new KubeRuntimeException("Value not set for " + v.key + " in recipe " + this);
throw new KubeRuntimeException("Value not set for " + v.key + " in recipe " + this).source(sourceLine);
}

v.key.component.writeToJson(this, Cast.to(v), json);
Expand All @@ -101,7 +101,7 @@ public <T> T getValue(RecipeKey<T> key) {
var v = valueMap.getHolder(key);

if (v == null) {
throw new MissingComponentException(key.name, key, valueMap.keySet());
throw new MissingComponentException(key.name, key, valueMap.keySet()).source(sourceLine);
}

return Cast.to(v.value);
Expand All @@ -111,7 +111,7 @@ public <T> KubeRecipe setValue(RecipeKey<T> key, T value) {
RecipeComponentValue<T> v = Cast.to(valueMap.getHolder(key));

if (v == null) {
throw new MissingComponentException(key.name, key, valueMap.keySet());
throw new MissingComponentException(key.name, key, valueMap.keySet()).source(sourceLine);
}

v.value = value;
Expand All @@ -131,7 +131,7 @@ public Object get(String key) {
}
}

throw new MissingComponentException(key, null, valueMap.keySet());
throw new MissingComponentException(key, null, valueMap.keySet()).source(sourceLine);
}

// intended for use by scripts
Expand All @@ -147,7 +147,7 @@ public KubeRecipe set(Context cx, String key, Object value) {
}
}

throw new MissingComponentException(key, null, valueMap.keySet());
throw new MissingComponentException(key, null, valueMap.keySet()).source(sourceLine);
}

public void initValues(boolean created) {
Expand All @@ -162,7 +162,6 @@ public void initValues(boolean created) {
for (var v : valueMap.holders) {
if (v.key.alwaysWrite || !v.key.optional()) {
if (v.key.alwaysWrite) {
// FIXME? Not sure why read() was called here v.value = Cast.to(v.key.component.read(this, v.key.optional.getDefaultValue(type.schemaType)));
v.value = Cast.to(v.key.optional.getDefaultValue(type.schemaType));
}

Expand All @@ -189,7 +188,7 @@ public void afterLoaded() {
var e = v.checkEmpty();

if (!e.isEmpty()) {
throw new KubeRuntimeException(e);
throw new KubeRuntimeException(e).source(sourceLine);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class FluidStackComponent implements RecipeComponent<FluidStack> {

@Override
public Codec<FluidStack> codec() {
return FluidStack.CODEC;
return FluidStack.OPTIONAL_CODEC;
}

@Override
Expand Down

0 comments on commit 4262852

Please sign in to comment.