diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java index 08c993a2e..172c775f4 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java @@ -44,8 +44,6 @@ public final class ActuallyAdditionsAPI { // public static final List TREASURE_CHEST_LOOT = new ArrayList<>(); //public static final List RECONSTRUCTOR_LENS_CONVERSION_RECIPES = new ArrayList<>(); public static final List EMPOWERER_RECIPES = new ArrayList<>(); - public static final Map RECONSTRUCTOR_LENS_COLOR_CHANGERS = new HashMap<>(); - public static final List COLOR_CHANGE_RECIPES = new ArrayList<>(); public static final List SOLID_FUEL_RECIPES = new ArrayList<>(); public static final List LIQUID_FUEL_RECIPES = new ArrayList<>(); @@ -267,20 +265,6 @@ public final class ActuallyAdditionsAPI { public static void addReconstructorLensConversionRecipe(Ingredient input, ItemStack output, int energyUse) { //addReconstructorLensConversionRecipe(input, output, energyUse, lensDefaultConversion); } - - /** - * Adds an item and the way it is modified to the Atomic Reconstructor's color lens. - * This also works for blocks, but they have to be in their item form. - * The way it is modified is an instance of IColorLensChanger. When modifying the item, - * its modifyItem() method will be called with a stack containing the item. - * - * @param item The item (or block's item) to add - * @param changer The change mechanism - */ - public static void addReconstructorLensColorChangeItem(Item item, IColorLensChanger changer) { - RECONSTRUCTOR_LENS_COLOR_CHANGERS.put(item, changer); - } - /** * Adds an ingredient to the Coffee Machine ingredient list * diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/ColorLensChangerByDyeMeta.java b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/ColorLensChangerByDyeMeta.java deleted file mode 100644 index 33ad026b5..000000000 --- a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/ColorLensChangerByDyeMeta.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * This file ("ColorLensChangerByDyeMeta.java") is part of the Actually Additions mod for Minecraft. - * It is created and owned by Ellpeck and distributed - * under the Actually Additions License to be found at - * http://ellpeck.de/actaddlicense - * View the source code at https://github.com/Ellpeck/ActuallyAdditions - * - * © 2015-2017 Ellpeck - */ - -package de.ellpeck.actuallyadditions.api.recipe; - -import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor; -import net.minecraft.block.BlockState; -import net.minecraft.item.ItemStack; -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 { - - @Override - public ItemStack modifyItem(ItemStack stack, BlockState hitBlockState, BlockPos hitBlock, IAtomicReconstructor tile) { - ItemStack newStack = stack.copy(); - int meta = newStack.getDamageValue(); - newStack.setDamageValue((meta + 1) % 16); - return newStack; - } -} diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/IColorLensChanger.java b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/IColorLensChanger.java deleted file mode 100644 index 9f055b56f..000000000 --- a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/IColorLensChanger.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file ("IColorLensChanger.java") is part of the Actually Additions mod for Minecraft. - * It is created and owned by Ellpeck and distributed - * under the Actually Additions License to be found at - * http://ellpeck.de/actaddlicense - * View the source code at https://github.com/Ellpeck/ActuallyAdditions - * - * © 2015-2017 Ellpeck - */ - -package de.ellpeck.actuallyadditions.api.recipe; - -import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor; -import net.minecraft.block.BlockState; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPos; - -/** - * Used for the Atomic Reconstructor's Color Lens changing algorythm. - * When registering a new item to be changed, it needs an IColorLensChanger which - * is the method with which the item will be changed. - *

- * See ColorLensChangerByDyeMeta for reference. - */ -public interface IColorLensChanger { - - /** - * Modifies the given item. - * Will only be called with stacks containing items that are registered with - * this IColorLensChanger. - * - * @param stack the stack to modify - * @param hitBlockState The state of the block that was hit - * @param hitBlock the block that was hit (usually air, or the block that is also in the stack) - * @param tile the Reconstructor doing the color conversion - * - * @return the modified stack. Please make sure to return a modified COPY of the input stack. - */ - ItemStack modifyItem(ItemStack stack, BlockState hitBlockState, BlockPos hitBlock, IAtomicReconstructor tile); - -} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ColorChangeRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ColorChangeRecipe.java index 795a865b8..042ca9e44 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ColorChangeRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ColorChangeRecipe.java @@ -1,6 +1,7 @@ package de.ellpeck.actuallyadditions.mod.crafting; import com.google.gson.JsonObject; +import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import net.minecraft.data.IFinishedRecipe; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; @@ -13,11 +14,11 @@ import net.minecraft.util.IItemProvider; import net.minecraft.util.JSONUtils; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; -import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistryEntry; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.Optional; public class ColorChangeRecipe implements IRecipe { public static final String NAME = "color_change"; @@ -52,6 +53,10 @@ public class ColorChangeRecipe implements IRecipe { return false; } + public static Optional getRecipeForStack(ItemStack stack) { + return ActuallyAdditionsAPI.COLOR_CHANGE_RECIPES.stream().filter(recipe -> recipe.matches(stack)).findFirst(); + } + @Nonnull @Override public ItemStack getResultItem() { 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 0ed189bd8..9b0267e30 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 @@ -10,23 +10,20 @@ package de.ellpeck.actuallyadditions.mod.items.lens; -import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor; import de.ellpeck.actuallyadditions.api.lens.Lens; -import de.ellpeck.actuallyadditions.api.recipe.IColorLensChanger; +import de.ellpeck.actuallyadditions.mod.crafting.ColorChangeRecipe; import de.ellpeck.actuallyadditions.mod.util.StackUtil; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.entity.item.ItemEntity; import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.Direction; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import java.util.List; -import java.util.Map; import java.util.Random; public class LensColor extends Lens { @@ -56,12 +53,10 @@ public class LensColor extends Lens { if (tile.getEnergy() >= ENERGY_USE) { BlockState state = tile.getWorldObject().getBlockState(hitBlock); Block block = state.getBlock(); - // int meta = block.getMetaFromState(state); - ItemStack returnStack = this.tryConvert(new ItemStack(block), hitState, hitBlock, tile); - if (returnStack != null && returnStack.getItem() instanceof BlockItem) { + ItemStack returnStack = this.tryConvert(new ItemStack(block)); + if (!returnStack.isEmpty() && returnStack.getItem() instanceof BlockItem) { Block toPlace = Block.byItem(returnStack.getItem()); BlockState state2Place = toPlace.defaultBlockState(); - //getStateForPlacement(tile.getWorldObject(), hitBlock, Direction.UP, 0, 0, 0, FakePlayerFactory.getMinecraft((ServerWorld) tile.getWorldObject()), Hand.MAIN_HAND); //TODO tile.getWorldObject().setBlock(hitBlock, state2Place, 2); tile.extractEnergy(ENERGY_USE); } @@ -69,8 +64,8 @@ public class LensColor extends Lens { List items = tile.getWorldObject().getEntitiesOfClass(ItemEntity.class, new AxisAlignedBB(hitBlock.getX(), hitBlock.getY(), hitBlock.getZ(), hitBlock.getX() + 1, hitBlock.getY() + 1, hitBlock.getZ() + 1)); for (ItemEntity item : items) { - if (item.isAlive() && StackUtil.isValid(item.getItem()) && tile.getEnergy() >= ENERGY_USE) { - ItemStack newStack = this.tryConvert(item.getItem(), hitState, hitBlock, tile); + if (item.isAlive() && !item.getItem().isEmpty() && tile.getEnergy() >= ENERGY_USE) { + ItemStack newStack = this.tryConvert(item.getItem()); if (StackUtil.isValid(newStack)) { item.remove(); @@ -85,16 +80,8 @@ public class LensColor extends Lens { return false; } - private ItemStack tryConvert(ItemStack stack, BlockState hitState, BlockPos hitBlock, IAtomicReconstructor tile) { - if (StackUtil.isValid(stack)) { - Item item = stack.getItem(); - 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; + private ItemStack tryConvert(ItemStack stack) { + return ColorChangeRecipe.getRecipeForStack(stack).map(ColorChangeRecipe::getResultItem).orElse(ItemStack.EMPTY); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/MethodHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/MethodHandler.java index 78dfac133..3e0cfb663 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/MethodHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/MethodHandler.java @@ -162,7 +162,6 @@ public class MethodHandler implements IMethodHandler { ItemStack output = recipe.get().getResultItem().copy(); if (!output.isEmpty()) { tile.getWorldObject().levelEvent(2001, pos, Block.getId(state)); - //recipe.transformHook(ItemStack.EMPTY, state, pos, tile); //TODO empty method if (output.getItem() instanceof BlockItem) { Block toPlace = Block.byItem(output.getItem()); BlockState state2Place = toPlace.defaultBlockState(); //.getStateForPlacement(tile.getWorldObject(), pos, facing, 0, 0, 0, output.getMetadata(), FakePlayerFactory.getMinecraft((WorldServer) tile.getWorldObject()), Hand.MAIN_HAND); //TODO