Guest User

Untitled

a guest
Mar 25th, 2022
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. public static class Serializer extends ForgeRegistryEntry<RecipeSerializer<?>> implements RecipeSerializer<TankCrafterRecipe> {
  2. public static final Serializer INSTANCE = new Serializer();
  3. public static final String ID = "crafter";
  4.  
  5. @Override
  6. public TankCrafterRecipe fromJson(ResourceLocation id, JsonObject json) {
  7. ItemStack output = ShapedRecipe.itemStackFromJson(GsonHelper.getAsJsonObject(json, "output"));
  8.  
  9. JsonArray ingredients = GsonHelper.getAsJsonArray(json, "ingredients");
  10. NonNullList<Ingredient> inputs = NonNullList.withSize(8, Ingredient.EMPTY);
  11.  
  12. for (int i = 0; i < inputs.size(); i++) {
  13. inputs.set(i, Ingredient.fromJson(ingredients.get(i)));
  14. }
  15.  
  16. return new TankCrafterRecipe(id, output, inputs);
  17. }
  18.  
  19. @Override
  20. public TankCrafterRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf buf) {
  21. NonNullList<Ingredient> inputs = NonNullList.withSize(buf.readInt(), Ingredient.EMPTY);
  22.  
  23. for (int i = 0; i < inputs.size(); i++) {
  24. inputs.set(i, Ingredient.fromNetwork(buf));
  25. }
  26.  
  27. ItemStack output = buf.readItem();
  28. return new TankCrafterRecipe(id, output,
  29. inputs);
  30. }
  31.  
  32. @Override
  33. public void toNetwork(FriendlyByteBuf buf, TankCrafterRecipe recipe) {
  34. buf.writeInt(recipe.getIngredients().size());
  35. for (Ingredient ing : recipe.getIngredients()) {
  36. ing.toNetwork(buf);
  37. }
  38. buf.writeItemStack(recipe.getResultItem(), false);
  39. }
  40. }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment