Snippets
Created by
Adam Walker
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | package com.hrznstudio.gadgetry.api;
import com.google.gson.JsonObject;
import com.hrznstudio.gadgetry.recipe.GadgetryRecipeSerializers;
import com.hrznstudio.gadgetry.recipe.GadgetryRecipeTypes;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.JsonUtils;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.IRegistry;
import net.minecraft.world.World;
import net.minecraftforge.common.crafting.RecipeType;
public class AlloyFurnaceRecipe implements IRecipe {
private final ResourceLocation id;
private final Ingredient input;
private final Ingredient secondaryInput;
private final ItemStack output;
private final int cookingTime;
public AlloyFurnaceRecipe(ResourceLocation id, Ingredient input, Ingredient secondaryInput, ItemStack output, int cookingTime) {
this.id = id;
this.input = input;
this.secondaryInput = secondaryInput;
this.output = output;
this.cookingTime = cookingTime;
}
public Ingredient getInput() {
return input;
}
public Ingredient getSecondaryInput() {
return secondaryInput;
}
public int getCookingTime() {
return cookingTime;
}
@Override
public boolean matches(IInventory inv, World worldIn) {
return input.test(inv.getStackInSlot(0)) && secondaryInput.test(inv.getStackInSlot(1));
}
@Override
public ItemStack getCraftingResult(IInventory inv) {
return output;
}
@Override
public boolean canFit(int width, int height) {
return width >= 2 || height >= 2;
}
@Override
public ItemStack getRecipeOutput() {
return output;
}
@Override
public ResourceLocation getId() {
return id;
}
@Override
public IRecipeSerializer<?> getSerializer() {
return GadgetryRecipeSerializers.ALLOY_FURNACE;
}
@Override
public RecipeType<? extends IRecipe> getType() {
return GadgetryRecipeTypes.ALLOY_FURNACE;
}
public static class Serializer implements IRecipeSerializer<AlloyFurnaceRecipe> {
private static ResourceLocation NAME = new ResourceLocation("gadgetry", "alloy_furnace");
public AlloyFurnaceRecipe read(ResourceLocation recipeId, JsonObject json) {
String s = JsonUtils.getString(json, "group", "");
Ingredient ingredient;
if (JsonUtils.isJsonArray(json, "input")) {
ingredient = Ingredient.fromJson(JsonUtils.getJsonArray(json, "input"));
} else {
ingredient = Ingredient.fromJson(JsonUtils.getJsonObject(json, "input"));
}
Ingredient ingredient2;
if (JsonUtils.isJsonArray(json, "secondary")) {
ingredient2 = Ingredient.fromJson(JsonUtils.getJsonArray(json, "secondary"));
} else {
ingredient2 = Ingredient.fromJson(JsonUtils.getJsonObject(json, "secondary"));
}
String s1 = JsonUtils.getString(json, "result");
Item item = IRegistry.field_212630_s.func_212608_b(new ResourceLocation(s1));
if (item != null) {
ItemStack itemstack = new ItemStack(item);
int lvt_9_1_ = JsonUtils.getInt(json, "cookingtime", 200);
return new AlloyFurnaceRecipe(recipeId, ingredient, ingredient2, itemstack, lvt_9_1_);
} else {
throw new IllegalStateException(s1 + " did not exist");
}
}
public AlloyFurnaceRecipe read(ResourceLocation recipeId, PacketBuffer buffer) {
Ingredient ingredient = Ingredient.fromBuffer(buffer);
Ingredient ingredient2 = Ingredient.fromBuffer(buffer);
ItemStack itemstack = buffer.readItemStack();
int i = buffer.readVarInt();
return new AlloyFurnaceRecipe(recipeId, ingredient, ingredient2, itemstack, i);
}
public void write(PacketBuffer buffer, AlloyFurnaceRecipe recipe) {
recipe.input.writeToBuffer(buffer);
recipe.secondaryInput.writeToBuffer(buffer);
buffer.writeItemStack(recipe.output);
buffer.writeVarInt(recipe.cookingTime);
}
@Override
public ResourceLocation getName() {
return NAME;
}
}
}
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.