/
DyeWaypointCompassRecipe.java
70 lines (60 loc) · 2.21 KB
/
DyeWaypointCompassRecipe.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package knightminer.inspirations.tools.recipe;
import com.google.gson.JsonObject;
import knightminer.inspirations.library.recipe.RecipeSerializers;
import knightminer.inspirations.tools.item.WaypointCompassItem;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.item.crafting.ShapelessRecipe;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nonnull;
public class DyeWaypointCompassRecipe extends ShapelessRecipe {
public DyeWaypointCompassRecipe(ResourceLocation id, String group, ItemStack output, NonNullList<Ingredient> inputs) {
super(id, group, output, inputs);
}
public DyeWaypointCompassRecipe(ShapelessRecipe recipe) {
super(recipe.getId(), recipe.getGroup(),
recipe.getRecipeOutput(),
recipe.getIngredients()
);
}
@Override
@Nonnull
public ItemStack getCraftingResult(@Nonnull CraftingInventory crafting){
ItemStack output = this.getRecipeOutput().copy();
for (int i = 0; i < crafting.getSizeInventory(); i++) {
ItemStack stack = crafting.getStackInSlot(i);
if(stack.getItem() instanceof WaypointCompassItem) {
if (stack.hasTag()) {
output.setTag(stack.getOrCreateTag().copy());
}
break;
}
}
return output;
}
@Override
public IRecipeSerializer<?> getSerializer() {
return RecipeSerializers.dye_waypoint_compass;
}
public static class Serializer extends ShapelessRecipe.Serializer {
// This recipe has the exact same options as the parent type, redirect to that code.
@Nonnull
@Override
public DyeWaypointCompassRecipe read(@Nonnull ResourceLocation recipeID, PacketBuffer buffer) {
return new DyeWaypointCompassRecipe(CRAFTING_SHAPELESS.read(recipeID, buffer));
}
@Nonnull
@Override
public DyeWaypointCompassRecipe read(@Nonnull ResourceLocation recipeID, JsonObject json) {
return new DyeWaypointCompassRecipe(CRAFTING_SHAPELESS.read(recipeID, json));
}
@Override
public void write(PacketBuffer buffer, ShapelessRecipe recipe) {
Serializer.CRAFTING_SHAPELESS.write(buffer, recipe);
}
}
}