-
Notifications
You must be signed in to change notification settings - Fork 2
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
5ae7eb9
commit 82723f5
Showing
6 changed files
with
163 additions
and
6 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
15 changes: 15 additions & 0 deletions
15
src/main/java/com/besson/tutorialmod/recipe/ModRecipes.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,15 @@ | ||
package com.besson.tutorialmod.recipe; | ||
|
||
import com.besson.tutorialmod.TutorialMod; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.registry.Registry; | ||
import net.minecraft.util.Identifier; | ||
|
||
public class ModRecipes { | ||
public static void registerRecipes(){ | ||
Registry.register(Registries.RECIPE_SERIALIZER,new Identifier(TutorialMod.MOD_ID,PolishingMachineRecipe.Serializer.ID), | ||
PolishingMachineRecipe.Serializer.INSTANCE); | ||
Registry.register(Registries.RECIPE_TYPE,new Identifier(TutorialMod.MOD_ID,PolishingMachineRecipe.Type.ID), | ||
PolishingMachineRecipe.Type.INSTANCE); | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
src/main/java/com/besson/tutorialmod/recipe/PolishingMachineRecipe.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,104 @@ | ||
package com.besson.tutorialmod.recipe; | ||
|
||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonObject; | ||
import net.minecraft.inventory.SimpleInventory; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.recipe.*; | ||
import net.minecraft.registry.DynamicRegistryManager; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.JsonHelper; | ||
import net.minecraft.util.collection.DefaultedList; | ||
import net.minecraft.world.World; | ||
|
||
import java.util.List; | ||
|
||
public class PolishingMachineRecipe implements Recipe<SimpleInventory> { | ||
private final Identifier id; | ||
private final ItemStack output; | ||
private final List<Ingredient> recipeItems; | ||
|
||
public PolishingMachineRecipe(Identifier id, ItemStack output, List<Ingredient> recipeItems) { | ||
this.id = id; | ||
this.output = output; | ||
this.recipeItems = recipeItems; | ||
} | ||
|
||
@Override | ||
public boolean matches(SimpleInventory inventory, World world) { | ||
if (world.isClient()){ | ||
return false; | ||
} | ||
return recipeItems.get(0).test(inventory.getStack(0)); | ||
} | ||
|
||
@Override | ||
public ItemStack craft(SimpleInventory inventory, DynamicRegistryManager registryManager) { | ||
return output; | ||
} | ||
|
||
@Override | ||
public boolean fits(int width, int height) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public ItemStack getOutput(DynamicRegistryManager registryManager) { | ||
return output; | ||
} | ||
|
||
@Override | ||
public Identifier getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public RecipeSerializer<?> getSerializer() { | ||
return Serializer.INSTANCE; | ||
} | ||
|
||
@Override | ||
public RecipeType<?> getType() { | ||
return Type.INSTANCE; | ||
} | ||
public static class Type implements RecipeType<PolishingMachineRecipe>{ | ||
public static final Type INSTANCE = new Type(); | ||
public static final String ID = "polishing_machine"; | ||
} | ||
public static class Serializer implements RecipeSerializer<PolishingMachineRecipe>{ | ||
public static final Serializer INSTANCE = new Serializer(); | ||
public static final String ID = "polishing_machine"; | ||
@Override | ||
public PolishingMachineRecipe read(Identifier id, JsonObject json) { | ||
ItemStack output = ShapedRecipe.outputFromJson(JsonHelper.getObject(json,"output")); | ||
|
||
JsonArray ingredients = JsonHelper.getArray(json,"ingredients"); | ||
DefaultedList<Ingredient> inputs = DefaultedList.ofSize(1,Ingredient.EMPTY); | ||
for (int i = 0; i < inputs.size(); i++){ | ||
inputs.set(i,Ingredient.fromJson(ingredients.get(i))); | ||
} | ||
return new PolishingMachineRecipe(id,output,inputs); | ||
} | ||
|
||
@Override | ||
public PolishingMachineRecipe read(Identifier id, PacketByteBuf buf) { | ||
DefaultedList<Ingredient> inputs = DefaultedList.ofSize(1,Ingredient.EMPTY); | ||
|
||
for (int i = 0; i < inputs.size(); i++){ | ||
inputs.set(i,Ingredient.fromPacket(buf)); | ||
} | ||
ItemStack output = buf.readItemStack(); | ||
return new PolishingMachineRecipe(id,output,inputs); | ||
} | ||
|
||
@Override | ||
public void write(PacketByteBuf buf, PolishingMachineRecipe recipe) { | ||
buf.writeInt(recipe.getIngredients().size()); | ||
for (Ingredient ingredient: recipe.getIngredients()){ | ||
ingredient.write(buf); | ||
} | ||
buf.writeItemStack(recipe.getOutput(null)); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/resources/data/tutorialmod/recipes/d_from_polishing_machine.json
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,11 @@ | ||
{ | ||
"type": "tutorialmod:polishing_machine", | ||
"ingredients": [ | ||
{ | ||
"item": "minecraft:coal" | ||
} | ||
], | ||
"output": { | ||
"item": "minecraft:diamond" | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/resources/data/tutorialmod/recipes/ie_from_polishing_machine.json
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,12 @@ | ||
{ | ||
"type": "tutorialmod:polishing_machine", | ||
"ingredients": [ | ||
{ | ||
"item": "tutorialmod:raw_ice_ether" | ||
} | ||
], | ||
"output": { | ||
"item": "tutorialmod:ice_ether", | ||
"count": 3 | ||
} | ||
} |