ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/ColorLensRotator.java
Shadows_of_Fire 32716bfca9 Closes #1154
2018-07-27 21:40:36 -04:00

54 lines
1.7 KiB
Java

package de.ellpeck.actuallyadditions.mod.recipe;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor;
import de.ellpeck.actuallyadditions.api.recipe.IColorLensChanger;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.oredict.OreDictionary;
public class ColorLensRotator implements IColorLensChanger {
public static final Map<String, EnumDyeColor> STRING_TO_ENUM = new HashMap<>();
static {
String[] dyes = { "White", "Orange", "Magenta", "LightBlue", "Yellow", "Lime", "Pink", "Gray", "LightGray", "Cyan", "Purple", "Blue", "Brown", "Green", "Red", "Black" };
for (int i = 0; i < dyes.length; i++)
STRING_TO_ENUM.put("dye" + dyes[i], EnumDyeColor.byMetadata(i));
}
final List<ItemStack> rotations;
public ColorLensRotator(List<ItemStack> rotations) {
this.rotations = rotations;
}
@Override
public ItemStack modifyItem(ItemStack stack, IBlockState hitBlockState, BlockPos hitBlock, IAtomicReconstructor tile) {
int idx = -1;
for (int i : OreDictionary.getOreIDs(stack)) {
String s = OreDictionary.getOreName(i);
if (s.startsWith("dye")) {
EnumDyeColor color = STRING_TO_ENUM.get(s);
if (color != null) {
idx = color.getMetadata();
break;
}
}
}
if (idx == -1) return ItemStack.EMPTY;
ItemStack s = rotations.get((idx + 1) % rotations.size()).copy();
s.setCount(stack.getCount());
return s;
}
}