Add exception hierarchy
This commit is contained in:
13 files changed
+216
-74
No files matched your search
@@ -20,6 +20,7 @@ import carpet.script.argument.Vector3Argument;
|
||||
import carpet.script.exception.ExitStatement;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import carpet.script.exception.ThrowStatement;
|
||||
import carpet.script.exception.Throwables;
|
||||
import carpet.script.utils.FixedCommandSource;
|
||||
import carpet.script.utils.ScarpetJsonDeserializer;
|
||||
import carpet.script.utils.ShapeDispatcher;
|
||||
@@ -132,7 +133,7 @@ public class Auxiliary {
|
||||
Identifier soundName = new Identifier(lv.get(0).evalValue(c).getString());
|
||||
Vector3Argument locator = Vector3Argument.findIn(cc, lv, 1);
|
||||
if (Registry.SOUND_EVENT.get(soundName) == null)
|
||||
throw new ThrowStatement("No such sound: "+soundName.getPath(), ThrowStatement.UNKNOWN_SOUND);
|
||||
throw new ThrowStatement("No such sound: "+soundName.getPath(), Throwables.UNKNOWN_SOUND);
|
||||
float volume = 1.0F;
|
||||
float pitch = 1.0F;
|
||||
SoundCategory mixer = SoundCategory.MASTER;
|
||||
@@ -828,7 +829,7 @@ public class Auxiliary {
|
||||
state = ((CarpetScriptHost) c.host).readFileTag(fdesc.getLeft(), fdesc.getRight());
|
||||
} catch (CrashException e)
|
||||
{
|
||||
throw new ThrowStatement("Couldn't read NBT data", ThrowStatement.NBT_READ_EXCEPTION);
|
||||
throw new ThrowStatement("Couldn't read NBT data", Throwables.NBT_READ);
|
||||
}
|
||||
|
||||
if (state == null) return LazyValue.NULL;
|
||||
@@ -846,7 +847,7 @@ public class Auxiliary {
|
||||
Throwable exc = e;
|
||||
if(e.getCause() != null)
|
||||
exc = e.getCause();
|
||||
throw new ThrowStatement("Failed to read JSON file: "+exc.getMessage(), ThrowStatement.JSON_READ_EXCEPTION);
|
||||
throw new ThrowStatement("Failed to read JSON file: "+exc.getMessage(), Throwables.JSON_READ);
|
||||
}
|
||||
Value parsedJson = gson.fromJson(json, Value.class);
|
||||
if (parsedJson == null)
|
||||
@@ -940,7 +941,7 @@ public class Auxiliary {
|
||||
state = ((CarpetScriptHost)((CarpetContext)c).host).readFileTag(file, shared);
|
||||
} catch (CrashException e)
|
||||
{
|
||||
throw new ThrowStatement("Failed to read App data", ThrowStatement.NBT_READ_EXCEPTION);
|
||||
throw new ThrowStatement("Failed to read App data", Throwables.NBT_READ);
|
||||
}
|
||||
if (state == null)
|
||||
return (cc, tt) -> Value.NULL;
|
||||
|
||||
@@ -7,6 +7,7 @@ import carpet.script.Expression;
|
||||
import carpet.script.LazyValue;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import carpet.script.exception.ThrowStatement;
|
||||
import carpet.script.exception.Throwables;
|
||||
import carpet.script.value.ListValue;
|
||||
import carpet.script.value.NBTSerializableValue;
|
||||
import carpet.script.value.NullValue;
|
||||
@@ -192,7 +193,7 @@ public class Inventories {
|
||||
String itemStr = lv.get(0).evalValue(c).getString();
|
||||
Item item;
|
||||
Identifier id = new Identifier(itemStr);
|
||||
item = Registry.ITEM.getOrEmpty(id).orElseThrow(() -> new ThrowStatement("Incorrect item: "+itemStr, ThrowStatement.UNKNOWN_ITEM));
|
||||
item = Registry.ITEM.getOrEmpty(id).orElseThrow(() -> new ThrowStatement("Incorrect item: "+itemStr, Throwables.UNKNOWN_ITEM));
|
||||
|
||||
if (!item.hasRecipeRemainder()) return LazyValue.NULL;
|
||||
Value ret = new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.ITEM.getId(item.getRecipeRemainder())));
|
||||
|
||||
@@ -7,6 +7,7 @@ import carpet.script.Expression;
|
||||
import carpet.script.LazyValue;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import carpet.script.exception.ThrowStatement;
|
||||
import carpet.script.exception.Throwables;
|
||||
import carpet.script.value.EntityValue;
|
||||
import carpet.script.value.ListValue;
|
||||
import carpet.script.value.NullValue;
|
||||
@@ -132,7 +133,7 @@ public class Scoreboards {
|
||||
criterion = ScoreboardCriterion.createStatCriterion(critetionName).orElse(null);
|
||||
if (criterion==null)
|
||||
{
|
||||
throw new ThrowStatement("Unknown scoreboard criterion: "+critetionName, ThrowStatement.UNKNOWN_CRITERION);
|
||||
throw new ThrowStatement("Unknown scoreboard criterion: "+critetionName, Throwables.UNKNOWN_CRITERION);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import carpet.script.argument.BlockArgument;
|
||||
import carpet.script.argument.Vector3Argument;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import carpet.script.exception.ThrowStatement;
|
||||
import carpet.script.exception.Throwables;
|
||||
import carpet.script.utils.BiomeInfo;
|
||||
import carpet.script.utils.WorldTools;
|
||||
import carpet.script.value.BlockValue;
|
||||
@@ -338,7 +339,7 @@ public class WorldAccess {
|
||||
if (!"any".equals(poiType))
|
||||
{
|
||||
PointOfInterestType type = Registry.POINT_OF_INTEREST_TYPE.getOrEmpty(new Identifier(poiType))
|
||||
.orElseThrow(() -> new ThrowStatement("Unknown POI type", ThrowStatement.UNKNOWN_POI_TYPE));
|
||||
.orElseThrow(() -> new ThrowStatement("Unknown POI type", Throwables.UNKNOWN_POI_TYPE));
|
||||
condition = (tt) -> tt == type;
|
||||
}
|
||||
if (locator.offset + 2 < lv.size())
|
||||
@@ -393,7 +394,7 @@ public class WorldAccess {
|
||||
}
|
||||
String poiTypeString = poi.getString().toLowerCase(Locale.ROOT);
|
||||
PointOfInterestType type = Registry.POINT_OF_INTEREST_TYPE.getOrEmpty(new Identifier(poiTypeString))
|
||||
.orElseThrow(() -> new ThrowStatement("Unknown POI type: "+poiTypeString, ThrowStatement.UNKNOWN_POI_TYPE));
|
||||
.orElseThrow(() -> new ThrowStatement("Unknown POI type: "+poiTypeString, Throwables.UNKNOWN_POI_TYPE));
|
||||
int occupancy = 0;
|
||||
if (locator.offset + 1 < lv.size())
|
||||
{
|
||||
@@ -873,7 +874,7 @@ public class WorldAccess {
|
||||
playerBreak = true;
|
||||
String itemString = val.getString();
|
||||
item = Registry.ITEM.getOrEmpty(new Identifier(itemString))
|
||||
.orElseThrow(() -> new ThrowStatement("Incorrect item: " + itemString, ThrowStatement.UNKNOWN_ITEM));
|
||||
.orElseThrow(() -> new ThrowStatement("Incorrect item: " + itemString, Throwables.UNKNOWN_ITEM));
|
||||
}
|
||||
}
|
||||
CompoundTag tag = null;
|
||||
@@ -1180,7 +1181,7 @@ public class WorldAccess {
|
||||
String biomeName = lv.get(locator.offset+0).evalValue(c).getString();
|
||||
// from locatebiome command code
|
||||
Biome biome = cc.s.getMinecraftServer().getRegistryManager().get(Registry.BIOME_KEY).getOrEmpty(new Identifier(biomeName))
|
||||
.orElseThrow(() -> new ThrowStatement("Unknown biome: "+biomeName, ThrowStatement.UNKNOWN_BIOME));
|
||||
.orElseThrow(() -> new ThrowStatement("Unknown biome: "+biomeName, Throwables.UNKNOWN_BIOME));
|
||||
boolean doImmediateUpdate = true;
|
||||
if (lv.size() > locator.offset+1)
|
||||
{
|
||||
@@ -1250,7 +1251,7 @@ public class WorldAccess {
|
||||
{
|
||||
String reqString = requested.getString();
|
||||
structure = Registry.STRUCTURE_FEATURE.getOrEmpty(new Identifier(reqString))
|
||||
.orElseThrow(() -> new ThrowStatement("Unknown structure: " + reqString, ThrowStatement.UNKNOWN_STRUCTURE));
|
||||
.orElseThrow(() -> new ThrowStatement("Unknown structure: " + reqString, Throwables.UNKNOWN_STRUCTURE));
|
||||
}
|
||||
if (lv.size() > locator.offset+1)
|
||||
{
|
||||
@@ -1330,7 +1331,7 @@ public class WorldAccess {
|
||||
throw new InternalExpressionException("'set_structure requires at least position and a structure name");
|
||||
String structureName = lv.get(locator.offset).evalValue(c).getString().toLowerCase(Locale.ROOT);
|
||||
ConfiguredStructureFeature<?, ?> configuredStructure = FeatureGenerator.resolveConfiguredStructure(structureName, world, pos);
|
||||
if (configuredStructure == null) throw new ThrowStatement("Unknown structure: "+structureName, ThrowStatement.UNKNOWN_STRUCTURE);
|
||||
if (configuredStructure == null) throw new ThrowStatement("Unknown structure: "+structureName, Throwables.UNKNOWN_STRUCTURE);
|
||||
// good 'ol pointer
|
||||
Value[] result = new Value[]{Value.NULL};
|
||||
// technically a world modification. Even if we could let it slide, we will still park it
|
||||
|
||||
Reference in new issue
Block a user