Gave color changing more freedom.

Bump API version to 10
This commit is contained in:
Ellpeck 2016-05-06 12:26:41 +02:00
parent d842367252
commit 73ebec3930
4 changed files with 18 additions and 9 deletions

View file

@ -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<CrusherRecipe> crusherRecipes = new ArrayList<CrusherRecipe>();
public static List<BallOfFurReturn> ballOfFurReturnItems = new ArrayList<BallOfFurReturn>();

View file

@ -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){

View file

@ -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.
*
* <p>
* See ColorLensChangerByDyeMeta for reference.
*/
public interface IColorLensChanger{
@ -17,8 +20,11 @@ public interface IColorLensChanger{
* 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);
ItemStack modifyItem(ItemStack stack, IBlockState hitBlockState, BlockPos hitBlock, IAtomicReconstructor tile);
}

View file

@ -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<EntityItem> items = (ArrayList<EntityItem>)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<Item, IColorLensChanger> changer : ActuallyAdditionsAPI.reconstructorLensColorChangers.entrySet()){
if(item == changer.getKey()){
return changer.getValue().modifyItem(stack);
return changer.getValue().modifyItem(stack, hitState, hitBlock, tile);
}
}
}