From 73ebec3930860b631ddde58c45f3e14f52773229 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 6 May 2016 12:26:41 +0200 Subject: [PATCH] Gave color changing more freedom. Bump API version to 10 --- .../actuallyadditions/api/ActuallyAdditionsAPI.java | 2 +- .../api/recipe/ColorLensChangerByDyeMeta.java | 5 ++++- .../api/recipe/IColorLensChanger.java | 12 +++++++++--- .../actuallyadditions/mod/items/lens/LensColor.java | 8 ++++---- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java index 986594a0d..dec6a9c5e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java @@ -27,7 +27,7 @@ public class ActuallyAdditionsAPI{ public static final String MOD_ID = "actuallyadditions"; public static final String API_ID = MOD_ID+"api"; - public static final String API_VERSION = "9"; + public static final String API_VERSION = "10"; public static List crusherRecipes = new ArrayList(); public static List ballOfFurReturnItems = new ArrayList(); 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 18849a55e..02831cfdb 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/ColorLensChangerByDyeMeta.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/ColorLensChangerByDyeMeta.java @@ -1,6 +1,9 @@ package de.ellpeck.actuallyadditions.api.recipe; +import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor; +import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; /** * Changes an item's color by changing its metadata. @@ -9,7 +12,7 @@ import net.minecraft.item.ItemStack; public class ColorLensChangerByDyeMeta implements IColorLensChanger{ @Override - public ItemStack modifyItem(ItemStack stack){ + public ItemStack modifyItem(ItemStack stack, IBlockState hitBlockState, BlockPos hitBlock, IAtomicReconstructor tile){ ItemStack newStack = stack.copy(); int meta = newStack.getItemDamage(); if(meta >= 15){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/IColorLensChanger.java b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/IColorLensChanger.java index 2edc0f386..e30de60e2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/IColorLensChanger.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/IColorLensChanger.java @@ -1,12 +1,15 @@ package de.ellpeck.actuallyadditions.api.recipe; +import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor; +import net.minecraft.block.state.IBlockState; 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{ @@ -16,9 +19,12 @@ public interface IColorLensChanger{ * Will only be called with stacks containing items that are registered with * this IColorLensChanger. * - * @param stack the stack to modify + * @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); + ItemStack modifyItem(ItemStack stack, IBlockState hitBlockState, BlockPos hitBlock, IAtomicReconstructor tile); } 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 2aa839191..a6ed85598 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 @@ -58,7 +58,7 @@ public class LensColor extends Lens{ if(hitBlock != null){ if(tile.getEnergy() >= ENERGY_USE){ int meta = PosUtil.getMetadata(hitBlock, tile.getWorldObject()); - ItemStack returnStack = this.tryConvert(new ItemStack(PosUtil.getBlock(hitBlock, tile.getWorldObject()), 1, meta)); + ItemStack returnStack = this.tryConvert(new ItemStack(PosUtil.getBlock(hitBlock, tile.getWorldObject()), 1, meta), hitState, hitBlock, tile); if(returnStack != null && returnStack.getItem() instanceof ItemBlock){ PosUtil.setBlock(hitBlock, tile.getWorldObject(), Block.getBlockFromItem(returnStack.getItem()), returnStack.getItemDamage(), 2); @@ -69,7 +69,7 @@ public class LensColor extends Lens{ ArrayList items = (ArrayList)tile.getWorldObject().getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(hitBlock.getX(), hitBlock.getY(), hitBlock.getZ(), hitBlock.getX()+1, hitBlock.getY()+1, hitBlock.getZ()+1)); for(EntityItem item : items){ if(!item.isDead && item.getEntityItem() != null && tile.getEnergy() >= ENERGY_USE){ - ItemStack newStack = this.tryConvert(item.getEntityItem()); + ItemStack newStack = this.tryConvert(item.getEntityItem(), hitState, hitBlock, tile); if(newStack != null){ item.setDead(); @@ -84,13 +84,13 @@ public class LensColor extends Lens{ return false; } - private ItemStack tryConvert(ItemStack stack){ + private ItemStack tryConvert(ItemStack stack, IBlockState hitState, BlockPos hitBlock, IAtomicReconstructor tile){ if(stack != null){ Item item = stack.getItem(); if(item != null){ for(Map.Entry changer : ActuallyAdditionsAPI.reconstructorLensColorChangers.entrySet()){ if(item == changer.getKey()){ - return changer.getValue().modifyItem(stack); + return changer.getValue().modifyItem(stack, hitState, hitBlock, tile); } } }