-
Notifications
You must be signed in to change notification settings - Fork 43
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
Showing
22 changed files
with
329 additions
and
375 deletions.
There are no files selected for viewing
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
39 changes: 39 additions & 0 deletions
39
src/main/java/net/id/paradiselost/recipe/RecipeHelper.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,39 @@ | ||
package net.id.paradiselost.recipe; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonSyntaxException; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.nbt.NbtHelper; | ||
import net.minecraft.recipe.ShapedRecipe; | ||
import net.minecraft.util.JsonHelper; | ||
|
||
public class RecipeHelper { | ||
// extracted from Incubus Core | ||
public static ItemStack getItemStackWithNbtFromJson(JsonObject json) { | ||
Item item = ShapedRecipe.getItem(json); | ||
|
||
int count = JsonHelper.getInt(json, "count", 1); | ||
if (count < 1) { | ||
throw new JsonSyntaxException("Invalid output count: " + count); | ||
} | ||
|
||
ItemStack stack = new ItemStack(item, count); | ||
String nbt = JsonHelper.getString(json, "nbt", ""); | ||
if(nbt.isEmpty()) { | ||
return stack; | ||
} | ||
|
||
try { | ||
NbtCompound compound = NbtHelper.fromNbtProviderString(nbt); | ||
compound.remove("palette"); | ||
stack.setNbt(compound); | ||
} catch (CommandSyntaxException e) { | ||
throw new JsonSyntaxException("Invalid output nbt: " + nbt); | ||
} | ||
|
||
return stack; | ||
} | ||
} |
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
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
Oops, something went wrong.