forked from WayofTime/BloodMagic
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac50cfc
commit bd584c6
Showing
6 changed files
with
56 additions
and
6 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/main/java/WayofTime/alchemicalWizardry/common/summoning/meteor/ItemStackAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ItemStack> { | ||
|
||
@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. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-60 Bytes
(99%)
src/main/resources/assets/alchemicalwizardry/meteors/meteors.zip
Binary file not shown.
Binary file modified
BIN
-23 Bytes
(99%)
src/main/resources/assets/alchemicalwizardry/meteors/reagents.zip
Binary file not shown.