From 0fd9ea6689cc540291781b36cb6f077588a0fa99 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Mon, 28 Jul 2014 01:24:32 -0500 Subject: [PATCH] Color Applicator can now use Dyes as well as Paint Balls, this is less efficient however. --- .../items/ToolColorApplicatorRender.java | 12 +-- items/tools/powered/ToolColorApplicator.java | 73 ++++++++++++++++--- 2 files changed, 64 insertions(+), 21 deletions(-) diff --git a/client/render/items/ToolColorApplicatorRender.java b/client/render/items/ToolColorApplicatorRender.java index 0700b6736..432aef883 100644 --- a/client/render/items/ToolColorApplicatorRender.java +++ b/client/render/items/ToolColorApplicatorRender.java @@ -2,7 +2,6 @@ package appeng.client.render.items; import net.minecraft.client.renderer.ItemRenderer; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.item.ItemSnowball; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraftforge.client.IItemRenderer; @@ -11,7 +10,6 @@ import org.lwjgl.opengl.GL11; import appeng.api.util.AEColor; import appeng.client.texture.ExtraItemTextures; -import appeng.items.misc.ItemPaintBall; import appeng.items.tools.powered.ToolColorApplicator; public class ToolColorApplicatorRender implements IItemRenderer @@ -87,15 +85,7 @@ public class ToolColorApplicatorRender implements IItemRenderer AEColor col = null; - ItemStack is = ((ToolColorApplicator) item.getItem()).getColor( item ); - if ( is != null && is.getItem() instanceof ItemPaintBall ) - { - ItemPaintBall ipb = (ItemPaintBall) is.getItem(); - col = ipb.getColor( is ); - } - - if ( is != null && is.getItem() instanceof ItemSnowball ) - col = AEColor.Transparent; + col = ((ToolColorApplicator) item.getItem()).getActiveColor( item ); if ( col != null ) { diff --git a/items/tools/powered/ToolColorApplicator.java b/items/tools/powered/ToolColorApplicator.java index 7811e2b5c..63b6c56eb 100644 --- a/items/tools/powered/ToolColorApplicator.java +++ b/items/tools/powered/ToolColorApplicator.java @@ -3,6 +3,7 @@ package appeng.items.tools.powered; import java.util.Collections; import java.util.Comparator; import java.util.EnumSet; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -19,6 +20,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.oredict.OreDictionary; import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.FuzzyMode; @@ -54,6 +56,21 @@ import appeng.util.item.AEItemStack; public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCell, IItemGroup, IBlockTool, IMouseWheelItem { + final static HashMap oreToColor = new HashMap(); + + static + { + + for (AEColor col : AEColor.values()) + { + if ( col == AEColor.Transparent ) + continue; + + oreToColor.put( OreDictionary.getOreID( "dye" + col.name() ), col ); + } + + }; + public ToolColorApplicator() { super( ToolColorApplicator.class, null ); setfeature( EnumSet.of( AEFeature.ColorApplicator, AEFeature.StorageCells, AEFeature.PoweredTools ) ); @@ -83,6 +100,38 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe return findNextColor( is, null, 0 ); } + public AEColor getColorFromItem(ItemStack paintBall) + { + if ( paintBall == null ) + return null; + + if ( paintBall.getItem() instanceof ItemSnowball ) + return AEColor.Transparent; + + if ( paintBall.getItem() instanceof ItemPaintBall ) + { + ItemPaintBall ipb = (ItemPaintBall) paintBall.getItem(); + return ipb.getColor( paintBall ); + } + else + { + int[] id = OreDictionary.getOreIDs( paintBall ); + + for (int oreID : id) + { + if ( oreToColor.containsKey( oreID ) ) + return oreToColor.get( oreID ); + } + } + + return null; + } + + public AEColor getActiveColor(ItemStack tol) + { + return getColorFromItem( getColor( tol ) ); + } + private ItemStack findNextColor(ItemStack is, ItemStack anchor, int scrollOffset) { ItemStack newColor = null; @@ -205,12 +254,11 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe return true; } } - else if ( paintBall != null && paintBall.getItem() instanceof ItemPaintBall ) + else if ( paintBall != null ) { - ItemPaintBall ipb = (ItemPaintBall) paintBall.getItem(); - AEColor color = ipb.getColor( paintBall ); + AEColor color = getColorFromItem( paintBall ); - if ( getAECurrentPower( is ) > powerPerUse ) + if ( color != null && getAECurrentPower( is ) > powerPerUse ) { if ( color != AEColor.Transparent && recolourBlock( blk, ForgeDirection.getOrientation( side ), w, x, y, z, ForgeDirection.getOrientation( side ), color ) ) @@ -301,13 +349,10 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe { String extra = GuiText.Empty.getLocal(); - ItemStack selected = getColor( par1ItemStack ); + AEColor selected = getActiveColor( par1ItemStack ); - if ( selected != null && selected.getItem() instanceof ItemSnowball ) - extra = GuiText.Clean.getLocal(); - - if ( selected != null && selected.getItem() instanceof ItemPaintBall ) - extra = ((ItemPaintBall) selected.getItem()).getExtraName( selected ); + if ( selected != null ) + extra = Platform.gui_localize( selected.unlocalizedName ); return super.getItemStackDisplayName( par1ItemStack ) + " - " + extra; } @@ -353,6 +398,14 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe { if ( requsetedAddition != null ) { + int[] id = OreDictionary.getOreIDs( requsetedAddition.getItemStack() ); + + for (int x : id) + { + if ( oreToColor.containsKey( x ) ) + return false; + } + if ( requsetedAddition.getItem() instanceof ItemSnowball ) return false;