-
Notifications
You must be signed in to change notification settings - Fork 5
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
10 changed files
with
129 additions
and
24 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
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
56 changes: 56 additions & 0 deletions
56
src/main/java/net/lyof/sortilege/brewing/custom/BrewingRecipe.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,56 @@ | ||
package net.lyof.sortilege.brewing.custom; | ||
|
||
import net.lyof.sortilege.brewing.BetterBrewingRegistry; | ||
import net.lyof.sortilege.brewing.IBetterBrewingRecipe; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.util.Identifier; | ||
|
||
import java.util.Map; | ||
|
||
public class BrewingRecipe implements IBetterBrewingRecipe { | ||
@Override | ||
public boolean isInput(ItemStack stack) { | ||
return stack.isOf(this.input); | ||
} | ||
|
||
@Override | ||
public boolean isIngredient(ItemStack stack) { | ||
return stack.isOf(this.ingredient); | ||
} | ||
|
||
@Override | ||
public ItemStack craft(ItemStack input, ItemStack ingredient) { | ||
return this.output.getDefaultStack(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "BrewingRecipe{" + | ||
"input=" + input + | ||
", ingredient=" + ingredient + | ||
", output=" + output + | ||
'}'; | ||
} | ||
|
||
public Item input; | ||
public Item ingredient; | ||
public Item output; | ||
|
||
public BrewingRecipe(Item in, Item add, Item out) { | ||
this.input = in; | ||
this.ingredient = add; | ||
this.output = out; | ||
} | ||
|
||
public static void read(Map<String, ?> json) { | ||
if (json.containsKey("input") && json.containsKey("ingredient") && json.containsKey("output")) { | ||
Item in = Registries.ITEM.get(new Identifier(String.valueOf(json.get("input")))); | ||
Item add = Registries.ITEM.get(new Identifier(String.valueOf(json.get("ingredient")))); | ||
Item out = Registries.ITEM.get(new Identifier(String.valueOf(json.get("output")))); | ||
|
||
BetterBrewingRegistry.register(new BrewingRecipe(in, add, out)); | ||
} | ||
} | ||
} |
6 changes: 2 additions & 4 deletions
6
src/main/java/net/lyof/sortilege/brewing/custom/PotionBrewingRecipe.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
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
46 changes: 46 additions & 0 deletions
46
src/main/java/net/lyof/sortilege/setup/ReloadListener.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 net.lyof.sortilege.setup; | ||
|
||
import com.google.gson.Gson; | ||
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener; | ||
import net.lyof.sortilege.Sortilege; | ||
import net.lyof.sortilege.brewing.BetterBrewingRegistry; | ||
import net.lyof.sortilege.brewing.custom.BrewingRecipe; | ||
import net.minecraft.resource.Resource; | ||
import net.minecraft.resource.ResourceManager; | ||
import net.minecraft.util.Identifier; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public class ReloadListener implements SimpleSynchronousResourceReloadListener { | ||
@Override | ||
public Identifier getFabricId() { | ||
return Sortilege.makeID("reload_listener"); | ||
} | ||
|
||
@Override | ||
public void reload(ResourceManager manager) { | ||
BetterBrewingRegistry.clear(); | ||
BetterBrewingRegistry.register(); | ||
|
||
for (Map.Entry<Identifier, Resource> entry : manager.findResources("recipes", | ||
path -> path.toString().endsWith(".json")).entrySet()) { | ||
|
||
try { | ||
Resource resource = entry.getValue(); | ||
|
||
String content = new String(resource.getInputStream().readAllBytes()); | ||
Map<String, ?> json = new Gson().fromJson(content, Map.class); | ||
|
||
if (!json.containsKey("type") || !Objects.equals(String.valueOf(json.get("type")), Sortilege.MOD_ID + ":brewing")) continue; | ||
|
||
BrewingRecipe.read(json); | ||
|
||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} |