Advertisement
Exokem

Untitled

Mar 24th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.83 KB | None | 0 0
  1. //IRecipe
  2. public interface IExkvaRecipe extends IForgeRegistryEntry<IExkvaRecipe> {
  3.  
  4.     ItemStack getRecipeOutput();
  5.  
  6.     ItemStack getCraftingResult(InventoryCrafting var1);
  7.  
  8.     boolean matches(InventoryCrafting var1, World var2);
  9.  
  10.     boolean canFit(int var1, int var2);
  11.  
  12.     default NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
  13.         return ForgeHooks.defaultRecipeGetRemainingItems(inv);
  14.     }
  15.  
  16.     default NonNullList<Ingredient> getIngredients() {return NonNullList.create(); }
  17.  
  18.     default boolean isShaped() { return false; }
  19. }
  20.  
  21. //IShapedRecipe
  22. public interface IShapedExkvaRecipe extends IExkvaRecipe {
  23.  
  24.     int getRecipeWidth();
  25.  
  26.     int getRecipeHeight();
  27. }
  28.  
  29. //ShapedRecipe
  30. public class RecipeExkvaShaped extends IForgeRegistryEntry.Impl<IExkvaRecipe> implements IShapedExkvaRecipe {
  31.  
  32.     public final int recipeWidth;
  33.     public final int recipeHeight;
  34.     public final NonNullList<Ingredient> recipeItems;
  35.     private final ItemStack recipeOutput;
  36.     private final String group;
  37.  
  38.     public RecipeExkvaShaped(String group, int width, int height, NonNullList<Ingredient> ingredients, ItemStack result) {
  39.  
  40.         this.recipeWidth = width;
  41.         this.recipeHeight = height;
  42.         this.recipeItems = ingredients;
  43.         this.recipeOutput = result;
  44.         this.group = group;
  45.     }
  46.  
  47.     public int getRecipeWidth() {
  48.         return this.recipeWidth;
  49.     }
  50.  
  51.     public int getRecipeHeight() {
  52.         return this.recipeWidth;
  53.     }
  54.  
  55.     public String getGroup() {
  56.         return this.group; }
  57.  
  58.     public ItemStack getRecipeOutput() {
  59.         return this.recipeOutput; }
  60.  
  61.     public ItemStack getCraftingResult(InventoryCrafting inv) {
  62.         return this.getRecipeOutput().copy();
  63.     }
  64.  
  65.     public NonNullList<Ingredient> getIngredients() {
  66.         return this.recipeItems; }
  67.  
  68.     public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
  69.         NonNullList<ItemStack> nonnulllist = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);
  70.  
  71.         for(int i = 0; i < nonnulllist.size(); ++i) {
  72.             ItemStack itemstack = inv.getStackInSlot(i);
  73.             nonnulllist.set(i, ForgeHooks.getContainerItem(itemstack));
  74.         }
  75.  
  76.         return nonnulllist;
  77.     }
  78.  
  79.     public boolean canFit(int width, int height) {
  80.         return width >= this.recipeWidth && height >= this.recipeHeight;
  81.     }
  82.  
  83.     public boolean matches(InventoryCrafting inv, World worldIn) {
  84.  
  85.         for(int i = 0; i <= inv.getWidth() - this.recipeWidth; ++i) {
  86.             for(int j = 0; j <= inv.getHeight() - this.recipeHeight; ++j) {
  87.                 if(this.checkMatch(inv, i, j, true)) {
  88.                     return true;
  89.                 }
  90.                 if(this.checkMatch(inv, i, j, false)) {
  91.                     return true;
  92.                 }
  93.             }
  94.         }
  95.  
  96.         return false;
  97.     }
  98.  
  99.     public boolean checkMatch(InventoryCrafting inv, int a, int b, boolean bool) {
  100.  
  101.         for(int i = 0; i < inv.getWidth(); ++i) {
  102.  
  103.             for(int j = 0; j < inv.getHeight(); ++j) {
  104.                 int k = i - a;
  105.                 int l = j - b;
  106.                 Ingredient ingredient = Ingredient.EMPTY;
  107.                 if (k >= 0 && l >= 0 && k < this.recipeWidth && l < this.recipeHeight) {
  108.                     if (bool) {
  109.                         ingredient = (Ingredient)this.recipeItems.get(this.recipeWidth - k - 1 + l * this.recipeWidth);
  110.                     } else {
  111.                         ingredient = (Ingredient)this.recipeItems.get(k + l * this.recipeWidth);
  112.                     }
  113.                 }
  114.  
  115.                 if (!ingredient.apply(inv.getStackInRowAndColumn(i, j))) {
  116.                     return false;
  117.                 }
  118.             }
  119.         }
  120.  
  121.         return true;
  122.     }
  123.  
  124.     private static String[] patternFromJson(JsonArray jArr) {
  125.         String[] astring = new String[jArr.size()];
  126.         if (astring.length > 3) {
  127.             throw new JsonSyntaxException("Invalid pattern: too many rows, 3 is maximum");
  128.         } else if (astring.length == 0) {
  129.             throw new JsonSyntaxException("Invalid pattern: empty pattern not allowed");
  130.         } else {
  131.             for(int i = 0; i < astring.length; ++i) {
  132.                 String s = JsonUtils.getString(jArr.get(i), "pattern[" + i + "]");
  133.                 if (s.length() > 5) {
  134.                     throw new JsonSyntaxException("Invalid pattern: too many columns, 5 is maximum");
  135.                 }
  136.  
  137.                 if (i > 0 && astring[0].length() != s.length()) {
  138.                     throw new JsonSyntaxException("Invalid pattern: each row must be the same width");
  139.                 }
  140.  
  141.                 astring[i] = s;
  142.             }
  143.  
  144.             return astring;
  145.         }
  146.     }
  147. }
  148.  
  149. //?
  150. public class RecipeManager extends CraftingHelper {
  151.  
  152.     public RecipeManager() {}
  153.  
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement