Skip to content

Commit

Permalink
Don't hard-crash on unsupported conversions to NBT
Browse files Browse the repository at this point in the history
Closes #8
  • Loading branch information
rubensworks committed Apr 8, 2024
1 parent 6a46172 commit a1ec7fb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import lombok.SneakyThrows;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import org.cyclops.integrateddynamics.api.evaluate.EvaluationException;
import org.cyclops.integrateddynamics.api.evaluate.operator.IOperator;
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
import org.cyclops.integrateddynamics.core.evaluate.operator.CurriedOperator;
Expand Down Expand Up @@ -84,6 +86,6 @@ public boolean hasMember(String key) {
@SneakyThrows
@Override
public void putMember(String key, Value value) {
throw new UnsupportedOperationException("Can not put members in static values of " + valueType.getTypeName());
throw new EvaluationException(Component.translatable("valuetype.integratedscripting.error.translation.proxyobject_putMember", key, valueType.getTypeName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import org.cyclops.integrateddynamics.api.evaluate.EvaluationException;
import org.cyclops.integrateddynamics.api.evaluate.operator.IOperator;
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
Expand Down Expand Up @@ -117,6 +118,6 @@ public V translateFromGraal(Context context, Value value, IEvaluationExceptionFa

@Override
public Tag translateToNbt(Context context, V value, IEvaluationExceptionFactory exceptionFactory) throws EvaluationException {
throw new UnsupportedOperationException("translateToNbt is not supported");
throw new EvaluationException(Component.translatable("valuetype.integratedscripting.error.translation.unsupported_translateToNbt", Component.translatable(value.getType().getTranslationKey()), value.getType().toCompactString(value)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public ValueTypeOperator.ValueOperator translateFromGraal(Context context, Value

@Override
public Tag translateToNbt(Context context, ValueTypeOperator.ValueOperator value, IEvaluationExceptionFactory exceptionFactory) throws EvaluationException {
throw new UnsupportedOperationException("translateToNbt is not supported");
throw new EvaluationException(Component.translatable("valuetype.integratedscripting.error.translation.unsupported_translateToNbt", Component.translatable(value.getType().getTranslationKey()), value.getType().toCompactString(value)));
}

public static class GraalOperator extends OperatorBase {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/integratedscripting/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"valuetype.integratedscripting.error.translation.list_infinite": "Can not translate an infinite list into a scripting language.",
"valuetype.integratedscripting.error.translation.nbt_unknown": "Can not translate NBT members of type %s.",
"valuetype.integratedscripting.error.translation.nbt_unmatched": "Could not interpret the field %s as NBT.",
"valuetype.integratedscripting.error.translation.unsupported_translateToNbt": "Illegal conversion of %s \"%s\" to NBT.",
"valuetype.integratedscripting.error.translation.proxyobject_putMember": "Illegal adding of key \"%s\" to read-only %s",

"_comment": "Operators",
"operator.integratedscripting.integratedscript.basename": "Integrated Script %s",
Expand Down

0 comments on commit a1ec7fb

Please sign in to comment.