2018-07-28 03:40:36 +02:00
|
|
|
package de.ellpeck.actuallyadditions.mod.recipe;
|
|
|
|
|
|
|
|
import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor;
|
|
|
|
import de.ellpeck.actuallyadditions.api.recipe.IColorLensChanger;
|
2021-03-01 21:30:45 +01:00
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
import net.minecraft.item.DyeColor;
|
2018-07-28 03:40:36 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
|
2021-02-27 16:33:00 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2018-07-28 03:40:36 +02:00
|
|
|
public class ColorLensRotator implements IColorLensChanger {
|
|
|
|
|
2021-03-01 21:30:45 +01:00
|
|
|
public static final Map<String, DyeColor> STRING_TO_ENUM = new HashMap<>();
|
2021-02-27 16:33:00 +01:00
|
|
|
|
2018-07-28 03:40:36 +02:00
|
|
|
static {
|
2021-02-27 16:33:00 +01:00
|
|
|
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++) {
|
2021-03-01 21:30:45 +01:00
|
|
|
STRING_TO_ENUM.put("dye" + dyes[i], DyeColor.byMetadata(i));
|
2021-02-27 16:33:00 +01:00
|
|
|
}
|
2018-07-28 03:40:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
final List<ItemStack> rotations;
|
|
|
|
|
|
|
|
public ColorLensRotator(List<ItemStack> rotations) {
|
|
|
|
this.rotations = rotations;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
public ItemStack modifyItem(ItemStack stack, BlockState hitBlockState, BlockPos hitBlock, IAtomicReconstructor tile) {
|
2018-07-28 03:40:36 +02:00
|
|
|
|
|
|
|
int idx = -1;
|
|
|
|
|
|
|
|
for (int i : OreDictionary.getOreIDs(stack)) {
|
|
|
|
String s = OreDictionary.getOreName(i);
|
|
|
|
if (s.startsWith("dye")) {
|
2021-03-01 21:30:45 +01:00
|
|
|
DyeColor color = STRING_TO_ENUM.get(s);
|
2018-07-28 03:40:36 +02:00
|
|
|
if (color != null) {
|
|
|
|
idx = color.getMetadata();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-27 16:33:00 +01:00
|
|
|
if (idx == -1) {
|
|
|
|
return ItemStack.EMPTY;
|
|
|
|
}
|
2018-07-28 03:40:36 +02:00
|
|
|
|
2019-02-27 19:53:05 +01:00
|
|
|
ItemStack s = this.rotations.get((idx + 1) % this.rotations.size()).copy();
|
2018-07-28 03:40:36 +02:00
|
|
|
s.setCount(stack.getCount());
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|