Guest User

Untitled

a guest
Mar 26th, 2022
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. public class TankCrafterRecipe implements Recipe<SimpleContainer> {
  2. ResourceLocation TYPE_ID = new ResourceLocation(TankMod.MOD_ID, "crafter");
  3. private final ResourceLocation id;
  4. private final ItemStack output;
  5. private final NonNullList<Ingredient> recipeItems;
  6.  
  7. public TankCrafterRecipe(ResourceLocation id, ItemStack output,
  8. NonNullList<Ingredient> recipeItems) {
  9. this.id = id;
  10. this.output = output;
  11. this.TYPE_ID = TYPE_ID;
  12. this.recipeItems = recipeItems;
  13. }
  14.  
  15. @Override
  16. public boolean matches(SimpleContainer inventory, Level world) {
  17. if (recipeItems.get(0).test(inventory.getItem(0))) {
  18. if (recipeItems.get(1).test(inventory.getItem(1))) {
  19. if (recipeItems.get(2).test(inventory.getItem(2))) {
  20. if (recipeItems.get(3).test(inventory.getItem(3))) {
  21. if (recipeItems.get(4).test(inventory.getItem(4))) {
  22. if (recipeItems.get(5).test(inventory.getItem(5))) {
  23. if (recipeItems.get(6).test(inventory.getItem(6))) {
  24. return recipeItems.get(7).test(inventory.getItem(7));
  25. }}}}}}}
  26. return false;
  27. }
  28.  
  29.  
  30. @Override
  31. public ItemStack assemble(SimpleContainer p_44001_) {
  32. return output;
  33. }
  34.  
  35. @Override
  36. public boolean canCraftInDimensions(int p_43999_, int p_44000_) {
  37. return true;
  38. }
  39.  
  40. @Override
  41. public ItemStack getResultItem() {
  42. return output.copy();
  43. }
  44.  
  45. @Override
  46. public ResourceLocation getId() {
  47. return id;
  48. }
  49.  
  50. @Override
  51. public RecipeSerializer<?> getSerializer() {
  52. return Serializer.INSTANCE;
  53. }
  54.  
  55. @Override
  56. public RecipeType<?> getType() {
  57. return Type.INSTANCE;
  58. }
  59.  
  60. public static class Type implements RecipeType<TankCrafterRecipe> {
  61. public Type() { }
  62. public static final Type INSTANCE = new Type();
  63. public static final String ID = "crafter";
  64. }
  65.  
  66. public static class Serializer extends ForgeRegistryEntry<RecipeSerializer<?>> implements RecipeSerializer<TankCrafterRecipe> {
  67. public static final Serializer INSTANCE = new Serializer();
  68. public static final String ID = "crafter";
  69. public Serializer() {
  70. setRegistryName(TankMod.MOD_ID, "crafter");
  71. }
  72. @Override
  73. public TankCrafterRecipe fromJson(ResourceLocation id, JsonObject json) {
  74. ItemStack output = ShapedRecipe.itemStackFromJson(GsonHelper.getAsJsonObject(json, "output"));
  75.  
  76. JsonArray ingredients = GsonHelper.getAsJsonArray(json, "ingredients");
  77. NonNullList<Ingredient> inputs = NonNullList.withSize(8, Ingredient.EMPTY);
  78.  
  79. for (int i = 0; i < inputs.size(); i++) {
  80. inputs.set(i, Ingredient.fromJson(ingredients.get(i)));
  81. }
  82.  
  83. return new TankCrafterRecipe(id, output, inputs);
  84. }
  85.  
  86. @Override
  87. public TankCrafterRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf buf) {
  88. NonNullList<Ingredient> inputs = NonNullList.withSize(buf.readInt(), Ingredient.EMPTY);
  89.  
  90. for (int i = 0; i < inputs.size(); i++) {
  91. inputs.set(i, Ingredient.fromNetwork(buf));
  92. }
  93.  
  94. ItemStack output = buf.readItem();
  95. return new TankCrafterRecipe(id, output,
  96. inputs);
  97. }
  98.  
  99. @Override
  100. public void toNetwork(FriendlyByteBuf buf, TankCrafterRecipe recipe) {
  101. buf.writeInt(recipe.getIngredients().size());
  102. for (Ingredient ing : recipe.getIngredients()) {
  103. ing.toNetwork(buf);
  104. }
  105. buf.writeItemStack(recipe.getResultItem(), false);
  106. }
  107. }
  108. }
  109.  
Advertisement
Add Comment
Please, Sign In to add comment