mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-22 19:39:24 +01:00
Closes #1154
This commit is contained in:
parent
7c7e87bea4
commit
32716bfca9
5 changed files with 93 additions and 24 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<LensConversionRecipe> MAIN_PAGE_RECIPES = new ArrayList<LensConversionRecipe>();
|
||||
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<LensConversionRecipe> getRecipesFor(ItemStack input){
|
||||
public static List<LensConversionRecipe> getRecipesFor(ItemStack input) {
|
||||
List<LensConversionRecipe> 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<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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue