From 32716bfca932f60681f83535fb57c11bc7ea9aad Mon Sep 17 00:00:00 2001 From: Shadows_of_Fire Date: Fri, 27 Jul 2018 21:40:36 -0400 Subject: [PATCH] Closes #1154 --- .../api/recipe/ColorLensChangerByDyeMeta.java | 11 ++-- .../mod/config/values/ConfigBoolValues.java | 4 +- .../mod/items/lens/LensColor.java | 5 +- .../mod/items/lens/LensRecipeHandler.java | 44 +++++++++++---- .../mod/recipe/ColorLensRotator.java | 53 +++++++++++++++++++ 5 files changed, 93 insertions(+), 24 deletions(-) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/recipe/ColorLensRotator.java diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/ColorLensChangerByDyeMeta.java b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/ColorLensChangerByDyeMeta.java index 20e97cd60..1368c2ce8 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/ColorLensChangerByDyeMeta.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/ColorLensChangerByDyeMeta.java @@ -19,18 +19,13 @@ import net.minecraft.util.math.BlockPos; * Changes an item's color by changing its metadata. * Much like dye and wool, 0 is white and 15 is black and it will cycle around. */ -public class ColorLensChangerByDyeMeta implements IColorLensChanger{ +public class ColorLensChangerByDyeMeta implements IColorLensChanger { @Override - public ItemStack modifyItem(ItemStack stack, IBlockState hitBlockState, BlockPos hitBlock, IAtomicReconstructor tile){ + 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; } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java index 234e5d95a..fc836b17a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java @@ -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; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensColor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensColor.java index 4981829e6..608a5d27e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensColor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensColor.java @@ -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 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 diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensRecipeHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensRecipeHandler.java index 361cdf1a0..356a905a2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensRecipeHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensRecipeHandler.java @@ -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,8 +34,10 @@ 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{ +public final class LensRecipeHandler { public static final ArrayList MAIN_PAGE_RECIPES = new ArrayList(); public static LensConversionRecipe recipeColorLens; @@ -50,7 +54,7 @@ public final class LensRecipeHandler{ public static LensConversionRecipe recipeFluidLaser; public static EnchBookConversion recipeEnchBook; - public static void init(){ + public static void init() { //Crystal Blocks ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(fromBlock(Blocks.REDSTONE_BLOCK), new ItemStack(InitBlocks.blockCrystal, 1, TheCrystals.REDSTONE.ordinal()), 400); MAIN_PAGE_RECIPES.add(RecipeUtil.lastReconstructorRecipe()); @@ -112,11 +116,15 @@ public final class LensRecipeHandler{ recipeWhiteWall = RecipeUtil.lastReconstructorRecipe(); ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(Ingredient.fromStacks(new ItemStack(Blocks.QUARTZ_BLOCK, 1, 1)), new ItemStack(InitBlocks.blockTestifiBucksGreenWall), 10); recipeGreenWall = RecipeUtil.lastReconstructorRecipe(); - + ActuallyAdditionsAPI.RECONSTRUCTOR_LENS_CONVERSION_RECIPES.add(recipeEnchBook = new EnchBookConversion()); IColorLensChanger changer = new ColorLensChangerByDyeMeta(); - ActuallyAdditionsAPI.addReconstructorLensColorChangeItem(Items.DYE, changer); + 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); @@ -127,21 +135,35 @@ public final class LensRecipeHandler{ } @Deprecated //Use lens-checking method below. - public static List getRecipesFor(ItemStack input){ + public static List getRecipesFor(ItemStack input) { List possibleRecipes = new ArrayList<>(); - for(LensConversionRecipe recipe : ActuallyAdditionsAPI.RECONSTRUCTOR_LENS_CONVERSION_RECIPES) - if(recipe.getInput().apply(input)) possibleRecipes.add(recipe); + for (LensConversionRecipe recipe : ActuallyAdditionsAPI.RECONSTRUCTOR_LENS_CONVERSION_RECIPES) + if (recipe.getInput().apply(input)) possibleRecipes.add(recipe); return possibleRecipes; } @Nullable - public static LensConversionRecipe findMatchingRecipe(ItemStack input, Lens lens){ - for(LensConversionRecipe recipe : ActuallyAdditionsAPI.RECONSTRUCTOR_LENS_CONVERSION_RECIPES) - if(recipe.matches(input, lens)) return recipe; + public static LensConversionRecipe findMatchingRecipe(ItemStack input, Lens lens) { + for (LensConversionRecipe recipe : ActuallyAdditionsAPI.RECONSTRUCTOR_LENS_CONVERSION_RECIPES) + if (recipe.matches(input, lens)) return recipe; return null; } - + private static Ingredient fromBlock(Block b) { return Ingredient.fromItems(Item.getItemFromBlock(b)); } + + private static void initOredictDyeRotator() { + List stacks = NonNullList.withSize(16, ItemStack.EMPTY); + List 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 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); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/ColorLensRotator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/ColorLensRotator.java new file mode 100644 index 000000000..e62a4609b --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/ColorLensRotator.java @@ -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_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 rotations; + + public ColorLensRotator(List 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; + } + +}