This commit is contained in:
Shadows_of_Fire 2018-07-27 21:40:36 -04:00
parent 7c7e87bea4
commit 32716bfca9
5 changed files with 93 additions and 24 deletions

View file

@ -25,12 +25,7 @@ public class ColorLensChangerByDyeMeta implements IColorLensChanger{
public ItemStack modifyItem(ItemStack stack, IBlockState hitBlockState, BlockPos hitBlock, IAtomicReconstructor tile) {
ItemStack newStack = stack.copy();
int meta = newStack.getItemDamage();
if(meta >= 15){
newStack.setItemDamage(0);
}
else{
newStack.setItemDamage(meta+1);
}
newStack.setItemDamage((meta + 1) % 16);
return newStack;
}
}

View file

@ -54,7 +54,9 @@ public enum ConfigBoolValues{
LASER_RELAY_LOSS("Laser Relay Energy Loss", ConfigCategories.MACHINE_VALUES, true, "If Energy Laser Relays should have energy loss"),
SUPER_DUPER_HARD_MODE("Super Duper Hard Recipes", ConfigCategories.OTHER, false, "Turn this on to make recipes for items from the mod really hard. (This is a joke feature poking fun at the whole FTB Infinity Expert Mode style of playing. You shouldn't really turn this on as it makes the mod completely unplayable.)"),
MOST_BLAND_PERSON_EVER("No Colored Item Names", ConfigCategories.OTHER, false, "If you want to be really boring and lame, you can turn on this setting to disable colored names on Actually Additions items. Because why would you want things to look pretty anyways, right?");
MOST_BLAND_PERSON_EVER("No Colored Item Names", ConfigCategories.OTHER, false, "If you want to be really boring and lame, you can turn on this setting to disable colored names on Actually Additions items. Because why would you want things to look pretty anyways, right?"),
COLOR_LENS_USES_OREDICT("Color Lens Oredict", ConfigCategories.OTHER, false, "If true, the Lens of Color will attempt to pull from the oredict instead of only using vanilla dyes.");
public final String name;
public final String category;

View file

@ -90,16 +90,13 @@ public class LensColor extends Lens{
private ItemStack tryConvert(ItemStack stack, IBlockState hitState, BlockPos hitBlock, IAtomicReconstructor tile){
if(StackUtil.isValid(stack)){
Item item = stack.getItem();
if(item != null){
for(Map.Entry<Item, IColorLensChanger> changer : ActuallyAdditionsAPI.RECONSTRUCTOR_LENS_COLOR_CHANGERS.entrySet()){
if(item == changer.getKey()){
return changer.getValue().modifyItem(stack, hitState, hitBlock, tile);
}
}
}
}
return ItemStack.EMPTY.copy();
return ItemStack.EMPTY;
}
@Override

View file

@ -21,9 +21,11 @@ import de.ellpeck.actuallyadditions.api.recipe.ColorLensChangerByDyeMeta;
import de.ellpeck.actuallyadditions.api.recipe.IColorLensChanger;
import de.ellpeck.actuallyadditions.api.recipe.LensConversionRecipe;
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheCrystals;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
import de.ellpeck.actuallyadditions.mod.recipe.ColorLensRotator;
import de.ellpeck.actuallyadditions.mod.recipe.EnchBookConversion;
import de.ellpeck.actuallyadditions.mod.util.RecipeUtil;
import net.minecraft.block.Block;
@ -32,6 +34,8 @@ import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.NonNullList;
import net.minecraftforge.oredict.OreDictionary;
public final class LensRecipeHandler {
@ -116,7 +120,11 @@ public final class LensRecipeHandler{
ActuallyAdditionsAPI.RECONSTRUCTOR_LENS_CONVERSION_RECIPES.add(recipeEnchBook = new EnchBookConversion());
IColorLensChanger changer = new ColorLensChangerByDyeMeta();
if (ConfigBoolValues.COLOR_LENS_USES_OREDICT.isEnabled()) {
initOredictDyeRotator();
} else {
ActuallyAdditionsAPI.addReconstructorLensColorChangeItem(Items.DYE, changer);
}
ActuallyAdditionsAPI.addReconstructorLensColorChangeItem(Item.getItemFromBlock(Blocks.WOOL), changer);
ActuallyAdditionsAPI.addReconstructorLensColorChangeItem(Item.getItemFromBlock(Blocks.STAINED_GLASS), changer);
ActuallyAdditionsAPI.addReconstructorLensColorChangeItem(Item.getItemFromBlock(Blocks.STAINED_GLASS_PANE), changer);
@ -144,4 +152,18 @@ public final class LensRecipeHandler{
private static Ingredient fromBlock(Block b) {
return Ingredient.fromItems(Item.getItemFromBlock(b));
}
private static void initOredictDyeRotator() {
List<ItemStack> stacks = NonNullList.withSize(16, ItemStack.EMPTY);
List<ItemStack> dyeItems = new ArrayList<>();
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++) {
List<ItemStack> ores = OreDictionary.getOres("dye" + dyes[i]);
dyeItems.addAll(ores);
stacks.set(i, ores.get(ores.size() - 1));
}
ColorLensRotator rotator = new ColorLensRotator(stacks);
for (ItemStack s : dyeItems)
ActuallyAdditionsAPI.addReconstructorLensColorChangeItem(s.getItem(), rotator);
}
}

View file

@ -0,0 +1,53 @@
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;
}
}