Allow json states to be plain strings, fix up error handling and gog build

This commit is contained in:
Vincent Lee committed 2020-03-28 20:42:19 -05:00
1 parent e0f272a358
commit 09b18e8ab9
5 files changed
+27 -7

No files matched your search

@@ -30,9 +30,11 @@ import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.ForgeRegistryEntry;
import net.minecraftforge.registries.ObjectHolder;
import vazkii.botania.common.Botania;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.crafting.ModRecipeTypes;
@@ -155,7 +157,19 @@ public class RecipeManaInfusion implements IRecipe<IInventory> {
String group = JSONUtils.getString(json, "group", "");
BlockState catalystState = null;
if (json.has("catalyst")) {
catalystState = StateIngredient.readBlockState(json.getAsJsonObject("catalyst"));
if (json.get("catalyst").isJsonPrimitive()) {
String s = JSONUtils.getString(json, "catalyst");
ResourceLocation catalystId = ResourceLocation.tryCreate(s);
if (catalystId == null) {
throw new IllegalArgumentException("Invalid catalyst ID: " + s);
}
if (!ForgeRegistries.BLOCKS.containsKey(catalystId)) {
throw new IllegalArgumentException("Unknown catalyst: " + s);
}
catalystState = ForgeRegistries.BLOCKS.getValue(catalystId).getDefaultState();
} else {
catalystState = StateIngredient.readBlockState(JSONUtils.getJsonObject(json, "catalyst"));
}
}
RecipeManaInfusion ret = new RecipeManaInfusion(id, output, ing, mana, group);
@@ -91,6 +91,7 @@ public class RecipePureDaisy implements IRecipe<IInventory> {
return time;
}
@Override
public ResourceLocation getId() {
return id;
}
@@ -130,8 +131,8 @@ public class RecipePureDaisy implements IRecipe<IInventory> {
@Nonnull
@Override
public RecipePureDaisy read(@Nonnull ResourceLocation id, JsonObject object) {
StateIngredient input = StateIngredient.deserialize(object.getAsJsonObject("input"));
BlockState output = StateIngredient.readBlockState(object.getAsJsonObject("output"));
StateIngredient input = StateIngredient.deserialize(JSONUtils.getJsonObject(object, "input"));
BlockState output = StateIngredient.readBlockState(JSONUtils.getJsonObject(object, "output"));
int time = JSONUtils.getInt(object, "time", DEFAULT_TIME);
return new RecipePureDaisy(id, input, output, time);
}
@@ -93,6 +93,11 @@ public abstract class StateIngredient implements Predicate<BlockState> {
CompoundNBT nbt = (CompoundNBT) new Dynamic<>(JsonOps.INSTANCE, object).convert(NBTDynamicOps.INSTANCE).getValue();
renameTag(nbt, "name", "Name");
renameTag(nbt, "properties", "Properties");
String name = nbt.getString("Name");
ResourceLocation id = ResourceLocation.tryCreate(name);
if (id == null || !ForgeRegistries.BLOCKS.containsKey(id)) {
throw new IllegalArgumentException("Invalid or unknown block ID: " + name);
}
return NBTUtil.readBlockState(nbt);
}