65ba8acbec
Added a recipe to copy settings from one panel component to another Some internal changes
106 lines
No EOL
3 KiB
Java
106 lines
No EOL
3 KiB
Java
/*
|
|
* This file is part of Industrial Wires.
|
|
* Copyright (C) 2016-2017 malte0811
|
|
*
|
|
* Industrial Wires is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Industrial Wires is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
package malte0811.industrialWires.crafting;
|
|
|
|
import blusunrize.immersiveengineering.api.ApiUtils;
|
|
import malte0811.industrialWires.IndustrialWires;
|
|
import malte0811.industrialWires.controlpanel.PanelComponent;
|
|
import malte0811.industrialWires.items.ItemPanelComponent;
|
|
import net.minecraft.inventory.InventoryCrafting;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.item.crafting.IRecipe;
|
|
import net.minecraft.world.World;
|
|
|
|
import javax.annotation.Nonnull;
|
|
import javax.annotation.Nullable;
|
|
|
|
public class RecipeComponentCopy implements IRecipe {
|
|
|
|
@Override
|
|
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
|
|
boolean found = false;
|
|
int foundX = -1;
|
|
int foundY = -1;
|
|
for (int x = 0; x < inv.getWidth(); x++) {
|
|
for (int y = 0; y < inv.getHeight(); y++) {
|
|
ItemStack here = inv.getStackInRowAndColumn(x, y);
|
|
PanelComponent pc1 = ItemPanelComponent.componentFromStack(here);
|
|
if (pc1!=null) {
|
|
if (x==foundX&&y==foundY) {
|
|
continue;
|
|
}
|
|
if (found) {
|
|
return false;
|
|
}
|
|
if (y+1<inv.getHeight()) {
|
|
ItemStack below = inv.getStackInRowAndColumn(x, y + 1);
|
|
PanelComponent pc2 = ItemPanelComponent.componentFromStack(below);
|
|
if (pc2 == null || pc2.getClass() != pc1.getClass()) {
|
|
return false;
|
|
}
|
|
found = true;
|
|
foundX = x;
|
|
foundY = y + 1;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return found;
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) {
|
|
int[] pos = getTopComponent(inv);
|
|
if (pos != null) {
|
|
return ApiUtils.copyStackWithAmount(inv.getStackInRowAndColumn(pos[0], pos[1]), 2);
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public int getRecipeSize() {
|
|
return 2;
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getRecipeOutput() {
|
|
return null;
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public ItemStack[] getRemainingItems(@Nonnull InventoryCrafting inv) {
|
|
return new ItemStack[inv.getSizeInventory()];
|
|
}
|
|
|
|
@Nullable
|
|
private int[] getTopComponent(@Nonnull InventoryCrafting inv) {
|
|
for (int x = 0; x < inv.getWidth(); x++) {
|
|
for (int y = 0; y < inv.getHeight() - 1; y++) {
|
|
ItemStack here = inv.getStackInRowAndColumn(x, y);
|
|
if (here!=null && here.getItem() == IndustrialWires.panelComponent) {
|
|
return new int[]{x, y};
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
} |