equivalent-exchange-3/ee3_common/com/pahimar/ee3/item/crafting/RecipesAlchemicalBagDyes.java

149 lines
4.6 KiB
Java
Raw Normal View History

package com.pahimar.ee3.item.crafting;
import java.util.ArrayList;
2013-03-08 04:45:55 +01:00
import net.minecraft.block.BlockCloth;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
import com.pahimar.ee3.item.ItemAlchemicalBag;
/**
* Equivalent-Exchange-3
*
* RecipesAlchemicalBagDyes
*
* @author pahimar
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
*
*/
public class RecipesAlchemicalBagDyes implements IRecipe {
@Override
public boolean matches(InventoryCrafting inventoryCrafting, World world) {
ItemStack itemStack = null;
ArrayList<ItemStack> arrayList = new ArrayList<ItemStack>();
for (int i = 0; i < inventoryCrafting.getSizeInventory(); ++i) {
2013-03-08 04:45:55 +01:00
ItemStack currentStack = inventoryCrafting.getStackInSlot(i);
2013-03-08 04:45:55 +01:00
if (currentStack != null) {
2013-03-08 04:45:55 +01:00
if (currentStack.getItem() instanceof ItemAlchemicalBag) {
if (itemStack != null)
return false;
2013-03-08 04:45:55 +01:00
itemStack = currentStack;
}
else {
if (currentStack.itemID != Item.dyePowder.itemID)
return false;
2013-03-08 04:45:55 +01:00
arrayList.add(currentStack);
}
}
}
return itemStack != null && !arrayList.isEmpty();
}
@Override
public ItemStack getCraftingResult(InventoryCrafting inventoryCrafting) {
2013-03-08 04:45:55 +01:00
ItemStack itemStack = null;
ItemAlchemicalBag itemAlchemicalBag = null;
int[] colorChannels = new int[3];
int i = 0;
int j = 0;
int k, j1, k1, l1;
int currentColor, newColor;
float red, green, blue;
for (k = 0; k < inventoryCrafting.getSizeInventory(); ++k) {
2013-03-08 04:45:55 +01:00
ItemStack currentStack = inventoryCrafting.getStackInSlot(k);
if (currentStack != null) {
2013-03-08 04:45:55 +01:00
if (currentStack.getItem() instanceof ItemAlchemicalBag) {
2013-03-08 04:45:55 +01:00
itemAlchemicalBag = (ItemAlchemicalBag) currentStack.getItem();
if (itemStack != null)
2013-03-08 04:45:55 +01:00
return null;
itemStack = currentStack.copy();
itemStack.stackSize = 1;
if (itemAlchemicalBag.hasColor(currentStack)) {
2013-03-08 04:45:55 +01:00
currentColor = itemAlchemicalBag.getColor(itemStack);
red = (currentColor >> 16 & 255) / 255.0F;
green = (currentColor >> 8 & 255) / 255.0F;
blue = (currentColor & 255) / 255.0F;
i = (int) (i + Math.max(red, Math.max(green, blue)) * 255.0F);
colorChannels[0] = (int) (colorChannels[0] + red * 255.0F);
colorChannels[1] = (int) (colorChannels[1] + green * 255.0F);
colorChannels[2] = (int) (colorChannels[2] + blue * 255.0F);
2013-03-08 04:45:55 +01:00
++j;
}
}
else {
if (currentStack.itemID != Item.dyePowder.itemID)
2013-03-08 04:45:55 +01:00
return null;
float[] dyeColorChannels = EntitySheep.fleeceColorTable[BlockCloth.getBlockFromDye(currentStack.getItemDamage())];
j1 = (int) (dyeColorChannels[0] * 255.0F);
k1 = (int) (dyeColorChannels[1] * 255.0F);
newColor = (int) (dyeColorChannels[2] * 255.0F);
2013-03-08 04:45:55 +01:00
i += Math.max(j1, Math.max(k1, newColor));
colorChannels[0] += j1;
colorChannels[1] += k1;
colorChannels[2] += newColor;
++j;
}
}
}
if (itemAlchemicalBag == null)
2013-03-08 04:45:55 +01:00
return null;
else {
2013-03-08 04:45:55 +01:00
k = colorChannels[0] / j;
l1 = colorChannels[1] / j;
currentColor = colorChannels[2] / j;
red = (float) i / (float) j;
green = Math.max(k, Math.max(l1, currentColor));
k = (int) (k * red / green);
l1 = (int) (l1 * red / green);
currentColor = (int) (currentColor * red / green);
2013-03-08 04:45:55 +01:00
newColor = (k << 8) + l1;
newColor = (newColor << 8) + currentColor;
itemAlchemicalBag.setColor(itemStack, newColor);
return itemStack;
}
}
@Override
public int getRecipeSize() {
return 10;
}
@Override
public ItemStack getRecipeOutput() {
return null;
}
}