Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CultivatorRecipe implements Recipe<SimpleContainer> {
- private final ResourceLocation id;
- private final ItemStack output;
- private final NonNullList<Ingredient> recipeItems;
- public CultivatorRecipe(ResourceLocation id, ItemStack output,
- NonNullList<Ingredient> recipeItems) {
- this.id = id;
- this.output = output;
- this.recipeItems = recipeItems;
- }
- @Override
- public boolean matches(SimpleContainer pContainer, Level pLevel) {
- return !recipeItems.isEmpty() && recipeItems.get(0).test(pContainer.getItem(0));
- }
- @Override
- public ItemStack assemble(SimpleContainer pContainer) {
- return output.copy();
- }
- @Override
- public boolean canCraftInDimensions(int pWidth, int pHeight) {
- return true;
- }
- @Override
- public ItemStack getResultItem() {
- return output;
- }
- @Override
- public NonNullList<Ingredient> getIngredients() {
- return recipeItems;
- }
- @Override
- public ResourceLocation getId() {
- return id;
- }
- @Override
- public RecipeSerializer<?> getSerializer() {
- return Serializer.INSTANCE;
- }
- @Override
- public RecipeType<?> getType() {
- return Type.INSTANCE;
- }
- public static class Type implements RecipeType<CultivatorRecipe> {
- private Type() { }
- public static final Type INSTANCE = new Type();
- }
- public static class Serializer implements RecipeSerializer<CultivatorRecipe> {
- public static final Serializer INSTANCE = new Serializer();
- public static final ResourceLocation ID = new ResourceLocation(UnusualPrehistory.MODID,"cultivator");
- @Override
- public CultivatorRecipe fromJson(ResourceLocation id, JsonObject json) {
- ItemStack output = ShapedRecipe.itemStackFromJson(GsonHelper.getAsJsonObject(json, "output"));
- JsonArray ingredients = GsonHelper.getAsJsonArray(json, "ingredients");
- NonNullList<Ingredient> inputs = NonNullList.withSize(1, Ingredient.EMPTY);
- for (int i = 0; i < inputs.size(); i++) {
- inputs.set(i, Ingredient.fromJson(ingredients.get(i)));
- }
- return new CultivatorRecipe(id, output, inputs);
- }
- @Override
- public CultivatorRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf buf) {
- NonNullList<Ingredient> inputs = NonNullList.withSize(buf.readInt(), Ingredient.EMPTY);
- for (int i = 0; i < inputs.size(); i++) {
- inputs.set(i, Ingredient.fromNetwork(buf));
- }
- ItemStack output = buf.readItem();
- return new CultivatorRecipe(id, output, inputs);
- }
- @Override
- public void toNetwork(FriendlyByteBuf buf, CultivatorRecipe recipe) {
- buf.writeInt(recipe.getIngredients().size());
- for (Ingredient ing : recipe.getIngredients()) {
- ing.toNetwork(buf);
- }
- buf.writeItemStack(recipe.output, false);
- }
- public RecipeSerializer<?> setRegistryName(ResourceLocation name) {
- return INSTANCE;
- }
- public ResourceLocation getRegistryName() {
- return ID;
- }
- public Class<RecipeSerializer<?>> getRegistryType() {
- return Serializer.castClass(RecipeSerializer.class);
- }
- @SuppressWarnings("unchecked") // Need this wrapper, because generics
- private static <G> Class<G> castClass(Class<?> cls) {
- return (Class<G>)cls;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement