forked from Nyancatpig/Cultural-Delights-1.18.2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
297 additions
and
20 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
18 changes: 18 additions & 0 deletions
18
src/main/java/com/ncpbails/culturaldelights/event/ModEventBusEvents.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,18 @@ | ||
package com.ncpbails.culturaldelights.event; | ||
|
||
import com.ncpbails.culturaldelights.CulturalDelights; | ||
import com.ncpbails.culturaldelights.recipe.BambooMatRecipe; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.world.item.crafting.RecipeSerializer; | ||
import net.minecraftforge.event.RegistryEvent; | ||
import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
import net.minecraftforge.fml.common.Mod; | ||
|
||
@Mod.EventBusSubscriber(modid = CulturalDelights.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) | ||
public class ModEventBusEvents { | ||
|
||
@SubscribeEvent | ||
public static void registerRecipeTypes(final RegistryEvent.Register<RecipeSerializer<?>> event) { | ||
Registry.register(Registry.RECIPE_TYPE, BambooMatRecipe.Type.ID, BambooMatRecipe.Type.INSTANCE); | ||
} | ||
} |
132 changes: 132 additions & 0 deletions
132
src/main/java/com/ncpbails/culturaldelights/recipe/BambooMatRecipe.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,132 @@ | ||
package com.ncpbails.culturaldelights.recipe; | ||
|
||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonObject; | ||
import com.ncpbails.culturaldelights.CulturalDelights; | ||
import net.minecraft.core.NonNullList; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.util.GsonHelper; | ||
import net.minecraft.world.SimpleContainer; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.crafting.*; | ||
import net.minecraft.world.level.Level; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
public class BambooMatRecipe implements Recipe<SimpleContainer> { | ||
|
||
private final ResourceLocation id; | ||
private final ItemStack output; | ||
private final NonNullList<Ingredient> recipeItems; | ||
|
||
public BambooMatRecipe(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.get(0).test(pContainer.getItem(1)); | ||
} | ||
|
||
@Override | ||
public ItemStack assemble(SimpleContainer p_44001_) { | ||
return output; | ||
} | ||
|
||
@Override | ||
public boolean canCraftInDimensions(int p_43999_, int p_44000_) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public ItemStack getResultItem() { | ||
return output.copy(); | ||
} | ||
|
||
@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<BambooMatRecipe> { | ||
private Type() { } | ||
public static final Type INSTANCE = new Type(); | ||
public static final String ID = "mat_rolling"; | ||
} | ||
|
||
public static class Serializer implements RecipeSerializer<BambooMatRecipe> { | ||
public static final Serializer INSTANCE = new Serializer(); | ||
public static final ResourceLocation ID = | ||
new ResourceLocation(CulturalDelights.MOD_ID,"mat_rolling"); | ||
|
||
@Override | ||
public BambooMatRecipe 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 BambooMatRecipe(id, output, inputs); | ||
} | ||
|
||
@Override | ||
public BambooMatRecipe 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 BambooMatRecipe(id, output, inputs); | ||
} | ||
|
||
@Override | ||
public void toNetwork(FriendlyByteBuf buf, BambooMatRecipe recipe) { | ||
buf.writeInt(recipe.getIngredients().size()); | ||
for (Ingredient ing : recipe.getIngredients()) { | ||
ing.toNetwork(buf); | ||
} | ||
buf.writeItemStack(recipe.getResultItem(), false); | ||
} | ||
|
||
@Override | ||
public RecipeSerializer<?> setRegistryName(ResourceLocation name) { | ||
return INSTANCE; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public ResourceLocation getRegistryName() { | ||
return ID; | ||
} | ||
|
||
@Override | ||
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; | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/ncpbails/culturaldelights/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,23 @@ | ||
package com.ncpbails.culturaldelights.recipe; | ||
|
||
import com.ncpbails.culturaldelights.CulturalDelights; | ||
import net.minecraft.world.item.crafting.RecipeSerializer; | ||
import net.minecraftforge.eventbus.api.IEventBus; | ||
import net.minecraftforge.registries.DeferredRegister; | ||
import net.minecraftforge.registries.ForgeRegistries; | ||
import net.minecraftforge.registries.RegistryObject; | ||
|
||
public class ModRecipes { | ||
|
||
public static final DeferredRegister<RecipeSerializer<?>> SERIALIZERS = | ||
DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, CulturalDelights.MOD_ID); | ||
|
||
|
||
public static final RegistryObject<RecipeSerializer<BambooMatRecipe>> MAT_ROLLING_SERIALIZER = | ||
SERIALIZERS.register("mat_rolling", () -> BambooMatRecipe.Serializer.INSTANCE); | ||
|
||
|
||
public static void register(IEventBus eventBus) { | ||
SERIALIZERS.register(eventBus); | ||
} | ||
} |
Oops, something went wrong.