diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/ItemStackAdapter.java b/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/ItemStackAdapter.java new file mode 100644 index 00000000..b95f5d8b --- /dev/null +++ b/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/ItemStackAdapter.java @@ -0,0 +1,46 @@ +package WayofTime.alchemicalWizardry.common.summoning.meteor; + +import java.io.IOException; + +import net.minecraft.item.ItemStack; + +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; + +import WayofTime.alchemicalWizardry.AlchemicalWizardry; +import cpw.mods.fml.common.registry.GameRegistry; + +class ItemStackAdapter extends TypeAdapter { + + @Override + public ItemStack read(JsonReader reader) throws IOException { + String str = reader.nextString(); + String[] input = str.split(":"); + if (input.length < 2) { + AlchemicalWizardry.logger + .warn("Unable to read item stack \"{}\". Valid format is \"modid:name(:meta optional)\"", str); + return null; + } + ItemStack itemStack = GameRegistry.findItemStack(input[0], input[1], 1); + if (itemStack == null) { + AlchemicalWizardry.logger.warn("Unable to find item stack \"{}\".", str); + return null; + } + if (input.length < 3) { + return itemStack; + } + try { + itemStack.setItemDamage(Integer.parseInt(input[2])); + } catch (NumberFormatException e) { + AlchemicalWizardry.logger + .warn("Invalid metadata value {} for item stack {}:{}", input[2], input[0], input[1]); + } + return itemStack; + } + + @Override + public void write(JsonWriter writer, ItemStack mpc) throws IOException { + // Not implemented because it is not needed. + } +} diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/Meteor.java b/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/Meteor.java index 780f5924..dc0ed91d 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/Meteor.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/Meteor.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; -import net.minecraft.init.Items; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; @@ -27,7 +26,7 @@ public class Meteor { public int radius; public int cost; public float fillerChance; // Out of 100.0 - public transient ItemStack focusItem; + public ItemStack focusItem; private String focusModId; private String focusName; private int focusMeta; @@ -203,13 +202,17 @@ public class Meteor { } /** - * Construct the focus item for this meteor from its modid, name, and metadata + * Construct the focus item for this meteor from its modid, name, and metadata if using the old config format. */ private void buildFocusItem() { if (this.focusItem != null) return; this.focusItem = GameRegistry.findItemStack(this.focusModId, this.focusName, 1); if (this.focusItem == null) return; - Items.feather.setDamage(this.focusItem, this.focusMeta); + this.focusItem.setItemDamage(this.focusMeta); + AlchemicalWizardry.logger.warn( + "Setting focusModId, focusName, and focusMeta individually in meteor" + + "configs has been deprecated. Set \"focusItem\" with format \"modId:name(:meta optional)\"" + + " instead."); } /** diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/MeteorComponentAdapter.java b/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/MeteorComponentAdapter.java index d477cbe4..b8bdd1d9 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/MeteorComponentAdapter.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/MeteorComponentAdapter.java @@ -14,7 +14,7 @@ class MeteorComponentAdapter extends TypeAdapter { } @Override - public void write(JsonWriter writer, MeteorComponent mpc) throws IOException { + public void write(JsonWriter writer, MeteorComponent component) throws IOException { // Not implemented because it is not needed. } } diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/MeteorRegistry.java b/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/MeteorRegistry.java index f8d545b9..02660f17 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/MeteorRegistry.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/MeteorRegistry.java @@ -24,7 +24,8 @@ public class MeteorRegistry { public static void loadConfig() { Gson gson = new GsonBuilder().setPrettyPrinting() - .registerTypeAdapter(MeteorComponent.class, new MeteorComponentAdapter()).create(); + .registerTypeAdapter(MeteorComponent.class, new MeteorComponentAdapter()) + .registerTypeAdapter(ItemStack.class, new ItemStackAdapter()).create(); File file = new File("config/BloodMagic/meteors"); File[] files = file.listFiles(); if (files != null) { diff --git a/src/main/resources/assets/alchemicalwizardry/meteors/meteors.zip b/src/main/resources/assets/alchemicalwizardry/meteors/meteors.zip index c21c564c..3106a3ac 100644 Binary files a/src/main/resources/assets/alchemicalwizardry/meteors/meteors.zip and b/src/main/resources/assets/alchemicalwizardry/meteors/meteors.zip differ diff --git a/src/main/resources/assets/alchemicalwizardry/meteors/reagents.zip b/src/main/resources/assets/alchemicalwizardry/meteors/reagents.zip index 8d8b02f0..f3571170 100644 Binary files a/src/main/resources/assets/alchemicalwizardry/meteors/reagents.zip and b/src/main/resources/assets/alchemicalwizardry/meteors/reagents.zip differ