From 161f88e42cda47de105b53e171d56c40f169e32f Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Mon, 26 May 2014 03:26:37 -0500 Subject: [PATCH] Added Paint Balls. Added Color Applicator. --- client/render/items/PaintBallRender.java | 99 ++++++ .../items/ToolColorApplicatorRender.java | 138 ++++++++ core/AEConfig.java | 30 +- core/Registration.java | 7 + core/features/AEFeature.java | 6 +- core/localization/GuiText.java | 2 +- core/sync/packets/PacketClick.java | 6 + core/sync/packets/PacketValueConfig.java | 11 +- ...nipulator.java => DispenserBlockTool.java} | 7 +- hooks/IBlockTool.java | 12 + items/misc/ItemPaintBall.java | 63 ++++ items/tools/powered/ToolColorApplicator.java | 328 ++++++++++++++++++ .../tools/powered/ToolEntropyManipulator.java | 8 +- parts/PartPlacement.java | 4 +- 14 files changed, 694 insertions(+), 27 deletions(-) create mode 100644 client/render/items/PaintBallRender.java create mode 100644 client/render/items/ToolColorApplicatorRender.java rename hooks/{DispenserEntropyManipulator.java => DispenserBlockTool.java} (81%) create mode 100644 hooks/IBlockTool.java create mode 100644 items/misc/ItemPaintBall.java create mode 100644 items/tools/powered/ToolColorApplicator.java diff --git a/client/render/items/PaintBallRender.java b/client/render/items/PaintBallRender.java new file mode 100644 index 00000000..e9a0a7e9 --- /dev/null +++ b/client/render/items/PaintBallRender.java @@ -0,0 +1,99 @@ +package appeng.client.render.items; + +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraftforge.client.IItemRenderer; + +import org.lwjgl.opengl.GL11; + +import appeng.api.util.AEColor; +import appeng.client.texture.ExtraItemTextures; +import appeng.items.misc.ItemPaintBall; + +public class PaintBallRender implements IItemRenderer +{ + + @Override + public boolean handleRenderType(ItemStack item, ItemRenderType type) + { + return true; + } + + @Override + public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) + { + return helper == ItemRendererHelper.ENTITY_BOBBING || helper == ItemRendererHelper.ENTITY_ROTATION; + } + + @Override + public void renderItem(ItemRenderType type, ItemStack item, Object... data) + { + IIcon par2Icon = item.getIconIndex(); + if ( item.getItemDamage() >= 20 ) + par2Icon = ExtraItemTextures.ItemPaintBallShimmer.getIcon(); + + float f4 = ((IIcon) par2Icon).getMinU(); + float f5 = ((IIcon) par2Icon).getMaxU(); + float f6 = ((IIcon) par2Icon).getMinV(); + float f7 = ((IIcon) par2Icon).getMaxV(); + float f12 = 0.0625F; + + ItemPaintBall ipb = (ItemPaintBall) item.getItem(); + + Tessellator tessellator = Tessellator.instance; + GL11.glPushMatrix(); + GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS ); + + AEColor col = ipb.getColor( item ); + + int colorValue = item.getItemDamage() >= 20 ? col.mediumVariant : col.mediumVariant; + int r = (colorValue >> 16) & 0xff; + int g = (colorValue >> 8) & 0xff; + int b = (colorValue >> 0) & 0xff; + + int full = (int) (255 * 0.3); + float fail = 0.7f; + + if ( item.getItemDamage() >= 20 ) + GL11.glColor4ub( (byte) (full + r * fail), (byte) (full + g * fail), (byte) (full + b * fail), (byte) 255 ); + else + GL11.glColor4ub( (byte) r, (byte) g, (byte) b, (byte) 255 ); + + if ( type == ItemRenderType.INVENTORY ) + { + GL11.glScalef( 16F, 16F, 10F ); + GL11.glTranslatef( 0.0F, 1.0F, 0.0F ); + GL11.glRotatef( 180F, 1.0F, 0.0F, 0.0F ); + GL11.glEnable( GL11.GL_ALPHA_TEST ); + + tessellator.startDrawingQuads(); + tessellator.setNormal( 0.0F, 1.0F, 0.0F ); + tessellator.addVertexWithUV( 0, 0, 0, (double) f4, (double) f7 ); + tessellator.addVertexWithUV( 1, 0, 0, (double) f5, (double) f7 ); + tessellator.addVertexWithUV( 1, 1, 0, (double) f5, (double) f6 ); + tessellator.addVertexWithUV( 0, 1, 0, (double) f4, (double) f6 ); + tessellator.draw(); + } + else + { + if ( type == ItemRenderType.EQUIPPED_FIRST_PERSON ) + GL11.glTranslatef( 0.0F, 0.0F, 0.0F ); + else + GL11.glTranslatef( -0.5F, -0.3F, 0.01F ); + ItemRenderer.renderItemIn2D( tessellator, f5, f6, f4, f7, ((IIcon) par2Icon).getIconWidth(), ((IIcon) par2Icon).getIconHeight(), f12 ); + + GL11.glDisable( GL11.GL_CULL_FACE ); + GL11.glColor4f( 1, 1, 1, 1.0F ); + GL11.glScalef( 1F, 1.1F, 1F ); + GL11.glTranslatef( 0.0F, 1.07F, f12 / -2.0f ); + GL11.glRotatef( 180F, 1.0F, 0.0F, 0.0F ); + } + + GL11.glColor4f( 1, 1, 1, 1.0F ); + + GL11.glPopAttrib(); + GL11.glPopMatrix(); + } +} diff --git a/client/render/items/ToolColorApplicatorRender.java b/client/render/items/ToolColorApplicatorRender.java new file mode 100644 index 00000000..0d57fdce --- /dev/null +++ b/client/render/items/ToolColorApplicatorRender.java @@ -0,0 +1,138 @@ +package appeng.client.render.items; + +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraftforge.client.IItemRenderer; + +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 +{ + + @Override + public boolean handleRenderType(ItemStack item, ItemRenderType type) + { + return true; + } + + @Override + public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) + { + return helper == ItemRendererHelper.ENTITY_BOBBING || helper == ItemRendererHelper.ENTITY_ROTATION; + } + + @Override + public void renderItem(ItemRenderType type, ItemStack item, Object... data) + { + IIcon par2Icon = item.getIconIndex(); + + float f4 = ((IIcon) par2Icon).getMinU(); + float f5 = ((IIcon) par2Icon).getMaxU(); + float f6 = ((IIcon) par2Icon).getMinV(); + float f7 = ((IIcon) par2Icon).getMaxV(); + float f12 = 0.0625F; + + Tessellator tessellator = Tessellator.instance; + GL11.glPushMatrix(); + GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS ); + + int direction = 1; + if ( type == ItemRenderType.INVENTORY ) + { + GL11.glColor4f( 1, 1, 1, 1.0F ); + GL11.glScalef( 16F, 16F, 10F ); + GL11.glTranslatef( 0.0F, 1.0F, 0.0F ); + GL11.glRotatef( 180F, 1.0F, 0.0F, 0.0F ); + GL11.glEnable( GL11.GL_ALPHA_TEST ); + + tessellator.startDrawingQuads(); + tessellator.setNormal( 0.0F, 1.0F, 0.0F ); + tessellator.addVertexWithUV( 0, 0, 0, (double) f4, (double) f7 ); + tessellator.addVertexWithUV( 1, 0, 0, (double) f5, (double) f7 ); + tessellator.addVertexWithUV( 1, 1, 0, (double) f5, (double) f6 ); + tessellator.addVertexWithUV( 0, 1, 0, (double) f4, (double) f6 ); + tessellator.draw(); + } + else + { + if ( type == ItemRenderType.EQUIPPED_FIRST_PERSON ) + GL11.glTranslatef( 0.0F, 0.0F, 0.0F ); + else if ( type == ItemRenderType.EQUIPPED ) + GL11.glTranslatef( 0.0F, 0.0F, 0.0F ); + else + GL11.glTranslatef( -0.5F, -0.3F, 0.01F ); + ItemRenderer.renderItemIn2D( tessellator, f5, f6, f4, f7, ((IIcon) par2Icon).getIconWidth(), ((IIcon) par2Icon).getIconHeight(), f12 ); + + GL11.glDisable( GL11.GL_CULL_FACE ); + GL11.glColor4f( 1, 1, 1, 1.0F ); + GL11.glScalef( -1F, -1F, 1F ); + GL11.glTranslatef( -1.125F, 0.0f, f12 / -2.0f ); + GL11.glRotatef( 180F, 1.0F, 0.0F, 0.0F ); + } + + float u = ExtraItemTextures.White.getIcon().getInterpolatedU( 8.1 ); + float v = ExtraItemTextures.White.getIcon().getInterpolatedV( 8.1 ); + + GL11.glScalef( 1F / 16F, 1F / 16F, 1F ); + GL11.glTranslatef( 4, 6, 0 ); + GL11.glDisable( GL11.GL_LIGHTING ); + + ItemStack is = ((ToolColorApplicator) item.getItem()).getColor( item ); + if ( is != null && is.getItem() instanceof ItemPaintBall ) + { + ItemPaintBall ipb = (ItemPaintBall) is.getItem(); + + AEColor col = ipb.getColor( is ); + tessellator.startDrawingQuads(); + float z = 0; + + for (int g = 0; g < 7; g++)// 8 + { + int x = g - 3 * direction; + int y = g + 3 * direction; + + if ( type != ItemRenderType.INVENTORY ) + { + x += 2; + } + + if ( g < 6 ) + { + tessellator.setColorOpaque_I( col.whiteVariant ); + tessellator.addVertexWithUV( x, y, z, (double) u, (double) v ); + tessellator.addVertexWithUV( x + 1, y, z, (double) u, (double) v ); + tessellator.addVertexWithUV( x + 1, y + 1, z, (double) u, (double) v ); + tessellator.addVertexWithUV( x, y + 1, z, (double) u, (double) v ); + } + + y -= direction; + tessellator.setColorOpaque_I( col.mediumVariant ); + tessellator.addVertexWithUV( x, y, z, (double) u, (double) v ); + tessellator.addVertexWithUV( x + 1, y, z, (double) u, (double) v ); + tessellator.addVertexWithUV( x + 1, y + 1, z, (double) u, (double) v ); + tessellator.addVertexWithUV( x, y + 1, z, (double) u, (double) v ); + + x += direction; + if ( g < 6 ) + { + tessellator.setColorOpaque_I( col.blackVariant ); + tessellator.addVertexWithUV( x, y, z, (double) u, (double) v ); + tessellator.addVertexWithUV( x + 1, y, z, (double) u, (double) v ); + tessellator.addVertexWithUV( x + 1, y + 1, z, (double) u, (double) v ); + tessellator.addVertexWithUV( x, y + 1, z, (double) u, (double) v ); + } + } + tessellator.draw(); + } + + GL11.glPopAttrib(); + GL11.glPopMatrix(); + } +} diff --git a/core/AEConfig.java b/core/AEConfig.java index 8b13491b..af02d41c 100644 --- a/core/AEConfig.java +++ b/core/AEConfig.java @@ -94,6 +94,7 @@ public class AEConfig extends Configuration implements IConfigureableObject, ICo public int manipulator_battery = 200000; public int mattercannon_battery = 200000; public int portablecell_battery = 20000; + public int colorapplicator_battery = 20000; public int staff_battery = 8000; public AEConfig(String path) { @@ -134,8 +135,10 @@ public class AEConfig extends Configuration implements IConfigureableObject, ICo minMeteoriteDistanceSq = minMeteoriteDistance * minMeteoriteDistance; - addCustomCategoryComment("wireless", "Range= WirelessBaseRange + WirelessBoosterRangeMultiplier * Math.pow( boosters, WirelessBoosterExp )\nPowerDrain= WirelessBaseCost + WirelessCostMultiplier * Math.pow( boosters, 1 + boosters / WirelessHighWirelessCount )" ); - + addCustomCategoryComment( + "wireless", + "Range= WirelessBaseRange + WirelessBoosterRangeMultiplier * Math.pow( boosters, WirelessBoosterExp )\nPowerDrain= WirelessBaseCost + WirelessCostMultiplier * Math.pow( boosters, 1 + boosters / WirelessHighWirelessCount )" ); + WirelessBaseCost = get( "wireless", "WirelessBaseCost", WirelessBaseCost ).getDouble( WirelessBaseCost ); WirelessCostMultiplier = get( "wireless", "WirelessCostMultiplier", WirelessCostMultiplier ).getDouble( WirelessCostMultiplier ); WirelessBaseRange = get( "wireless", "WirelessBaseRange", WirelessBaseRange ).getDouble( WirelessBaseRange ); @@ -149,6 +152,7 @@ public class AEConfig extends Configuration implements IConfigureableObject, ICo staff_battery = get( "battery", "staff", staff_battery ).getInt( staff_battery ); manipulator_battery = get( "battery", "manipulator", manipulator_battery ).getInt( manipulator_battery ); portablecell_battery = get( "battery", "portablecell", portablecell_battery ).getInt( portablecell_battery ); + colorapplicator_battery = get( "battery", "colorapplicator", colorapplicator_battery ).getInt( colorapplicator_battery ); mattercannon_battery = get( "battery", "mattercannon", mattercannon_battery ).getInt( mattercannon_battery ); for (AEFeature feature : AEFeature.values()) @@ -169,9 +173,9 @@ public class AEConfig extends Configuration implements IConfigureableObject, ICo { String Category = e.getClass().getSimpleName(); Enum value = settings.getSetting( e ); - + Property p = this.get( Category, e.name(), value.name(), getListComment( value ) ); - + try { value = Enum.valueOf( value.getClass(), p.getString() ); @@ -186,7 +190,7 @@ public class AEConfig extends Configuration implements IConfigureableObject, ICo try { - selectedPowerUnit = PowerUnits.valueOf( get( "Client", "PowerUnit", selectedPowerUnit.name(), getListComment(selectedPowerUnit) ).getString() ); + selectedPowerUnit = PowerUnits.valueOf( get( "Client", "PowerUnit", selectedPowerUnit.name(), getListComment( selectedPowerUnit ) ).getString() ); } catch (Throwable t) { @@ -221,21 +225,21 @@ public class AEConfig extends Configuration implements IConfigureableObject, ICo private String getListComment(Enum value) { String comment = null; - + if ( value != null ) { - EnumSet set = EnumSet.allOf(value.getClass() ); - - for ( Object Oeg : set ) + EnumSet set = EnumSet.allOf( value.getClass() ); + + for (Object Oeg : set) { - Enum eg = (Enum)Oeg; + Enum eg = (Enum) Oeg; if ( comment == null ) comment = "Possible Values: " + eg.name(); else - comment += ", "+eg.name(); + comment += ", " + eg.name(); } } - + return comment; } @@ -270,7 +274,7 @@ public class AEConfig extends Configuration implements IConfigureableObject, ICo get( "spatialio", "storageProviderID", storageProviderID ).set( storageProviderID ); } - get( "Client", "PowerUnit", selectedPowerUnit.name(), getListComment(selectedPowerUnit) ).set( selectedPowerUnit.name() ); + get( "Client", "PowerUnit", selectedPowerUnit.name(), getListComment( selectedPowerUnit ) ).set( selectedPowerUnit.name() ); if ( hasChanged() ) super.save(); diff --git a/core/Registration.java b/core/Registration.java index 97490103..9cfd243e 100644 --- a/core/Registration.java +++ b/core/Registration.java @@ -41,6 +41,7 @@ import appeng.block.misc.BlockCharger; import appeng.block.misc.BlockCondenser; import appeng.block.misc.BlockInscriber; import appeng.block.misc.BlockInterface; +import appeng.block.misc.BlockPaint; import appeng.block.misc.BlockQuartzGrowthAccelerator; import appeng.block.misc.BlockQuartzTorch; import appeng.block.misc.BlockSecurity; @@ -99,6 +100,7 @@ import appeng.items.materials.ItemMultiMaterial; import appeng.items.materials.MaterialType; import appeng.items.misc.ItemCrystalSeed; import appeng.items.misc.ItemEncodedPattern; +import appeng.items.misc.ItemPaintBall; import appeng.items.parts.ItemFacade; import appeng.items.parts.ItemMultiPart; import appeng.items.parts.PartType; @@ -110,6 +112,7 @@ import appeng.items.tools.ToolBiometricCard; import appeng.items.tools.ToolMemoryCard; import appeng.items.tools.ToolNetworkTool; import appeng.items.tools.powered.ToolChargedStaff; +import appeng.items.tools.powered.ToolColorApplicator; import appeng.items.tools.powered.ToolEntropyManipulator; import appeng.items.tools.powered.ToolMassCannon; import appeng.items.tools.powered.ToolPortableCell; @@ -286,6 +289,7 @@ public class Registration blocks.blockQuartzOre = addFeature( OreQuartz.class ); blocks.blockQuartzOreCharged = addFeature( OreQuartzCharged.class ); blocks.blockMatrixFrame = addFeature( BlockMatrixFrame.class ); + blocks.blockPaint = addFeature( BlockPaint.class ); blocks.blockQuartz = addFeature( BlockQuartz.class ); blocks.blockFluix = addFeature( BlockFluix.class ); blocks.blockSkyStone = addFeature( BlockSkyStone.class ); @@ -361,6 +365,8 @@ public class Registration items.itemMemoryCard = addFeature( ToolMemoryCard.class ); items.itemChargedStaff = addFeature( ToolChargedStaff.class ); items.itemEntropyManipulator = addFeature( ToolEntropyManipulator.class ); + items.itemColorApplicator = addFeature( ToolColorApplicator.class ); + items.itemWirelessTerminal = addFeature( ToolWirelessTerminal.class ); items.itemNetworkTool = addFeature( ToolNetworkTool.class ); items.itemPortableCell = addFeature( ToolPortableCell.class ); @@ -368,6 +374,7 @@ public class Registration items.itemFacade = addFeature( ItemFacade.class ); items.itemCrystalSeed = addFeature( ItemCrystalSeed.class ); + items.itemPaintBall = addFeature( ItemPaintBall.class ); addFeature( ToolEraser.class ); addFeature( ToolMeteoritePlacer.class ); diff --git a/core/features/AEFeature.java b/core/features/AEFeature.java index 9505e74c..6ff60a7f 100644 --- a/core/features/AEFeature.java +++ b/core/features/AEFeature.java @@ -24,7 +24,7 @@ public enum AEFeature QuartzHoe("Tools"), QuartzSpade("Tools"), QuartzSword("Tools"), QuartzPickaxe("Tools"), QuartzAxe("Tools"), QuartzKnife("Tools"), QuartzWrench("Tools"), - ChargedStaff("Tools"), EntropyManipulator("Tools"), MatterCannon("Tools"), WirelessAccessTerminal("Tools"), + ChargedStaff("Tools"), EntropyManipulator("Tools"), MatterCannon("Tools"), WirelessAccessTerminal("Tools"), ColorApplicator("Tools"), Crafting("NetworkFeatures"), PowerGen("NetworkFeatures"), Security("NetworkFeatures"), @@ -48,11 +48,11 @@ public enum AEFeature DuplicateItems("Misc", false), Profiler("Services", false), VersionChecker("Services"), Debug("Misc", false), Creative("Misc"), - GrinderLogging("Misc",false), Logging("Misc"), IntegrationLogging("Misc", false), CustomRecipes("Crafting", false), WebsiteRecipes("Misc", false), + GrinderLogging("Misc", false), Logging("Misc"), IntegrationLogging("Misc", false), CustomRecipes("Crafting", false), WebsiteRecipes("Misc", false), enableFacadeCrafting("Crafting"), inWorldSingularity("Crafting"), inWorldFluix("Crafting"), inWorldPurification("Crafting"), UpdateLogging("Misc", false), - AlphaPass("Rendering"); + AlphaPass("Rendering"), PaintBalls("Tools"); String Category; boolean visible = true; diff --git a/core/localization/GuiText.java b/core/localization/GuiText.java index e3749de8..fa4355cf 100644 --- a/core/localization/GuiText.java +++ b/core/localization/GuiText.java @@ -30,7 +30,7 @@ public enum GuiText StoredPower, MaxPower, RequiredPower, Efficiency, InWorldCrafting, inWorldFluix, inWorldPurification, inWorldSingularity, - OfSecondOutput, NoSecondOutput, RFTunnel, Stores, Next, SelectAmount; + OfSecondOutput, NoSecondOutput, RFTunnel, Stores, Next, SelectAmount, Lumen, Empty; String root; diff --git a/core/sync/packets/PacketClick.java b/core/sync/packets/PacketClick.java index a6d0fdc9..57d3ff6b 100644 --- a/core/sync/packets/PacketClick.java +++ b/core/sync/packets/PacketClick.java @@ -13,6 +13,7 @@ import appeng.api.implementations.items.MemoryCardMessages; import appeng.core.sync.AppEngPacket; import appeng.core.sync.network.INetworkInfo; import appeng.items.tools.ToolNetworkTool; +import appeng.items.tools.powered.ToolColorApplicator; public class PacketClick extends AppEngPacket { @@ -46,6 +47,11 @@ public class PacketClick extends AppEngPacket mem.notifyUser( player, MemoryCardMessages.SETTINGS_CLEARED ); is.setTagCompound( null ); } + else if ( is != null && AEApi.instance().items().itemColorApplicator.sameAsStack( is ) ) + { + ToolColorApplicator mem = (ToolColorApplicator) is.getItem(); + mem.cycleColors( is, mem.getColor( is ), 1 ); + } } // api diff --git a/core/sync/packets/PacketValueConfig.java b/core/sync/packets/PacketValueConfig.java index ad57f64f..6ee0b386 100644 --- a/core/sync/packets/PacketValueConfig.java +++ b/core/sync/packets/PacketValueConfig.java @@ -11,6 +11,7 @@ import java.io.IOException; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; +import net.minecraft.item.ItemStack; import appeng.api.config.FuzzyMode; import appeng.api.util.IConfigManager; import appeng.api.util.IConfigureableObject; @@ -24,6 +25,7 @@ import appeng.container.implementations.ContainerSecurity; import appeng.container.implementations.ContainerStorageBus; import appeng.core.sync.AppEngPacket; import appeng.core.sync.network.INetworkInfo; +import appeng.helpers.IMouseWheelItem; public class PacketValueConfig extends AppEngPacket { @@ -44,7 +46,14 @@ public class PacketValueConfig extends AppEngPacket { Container c = player.openContainer; - if ( Name.equals( "QuartzKnife.Name" ) && c instanceof ContainerQuartzKnife ) + if ( Name.equals( "Item" ) && player.getHeldItem() != null && player.getHeldItem().getItem() instanceof IMouseWheelItem ) + { + ItemStack is = player.getHeldItem(); + IMouseWheelItem si = (IMouseWheelItem) is.getItem(); + si.onWheel( is, Value.equals( "WheelUp" ) ); + return; + } + else if ( Name.equals( "QuartzKnife.Name" ) && c instanceof ContainerQuartzKnife ) { ContainerQuartzKnife qk = (ContainerQuartzKnife) c; qk.setName( Value ); diff --git a/hooks/DispenserEntropyManipulator.java b/hooks/DispenserBlockTool.java similarity index 81% rename from hooks/DispenserEntropyManipulator.java rename to hooks/DispenserBlockTool.java index d2bfe207..13e48378 100644 --- a/hooks/DispenserEntropyManipulator.java +++ b/hooks/DispenserBlockTool.java @@ -8,20 +8,19 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; import net.minecraft.world.WorldServer; -import appeng.items.tools.powered.ToolEntropyManipulator; import appeng.util.Platform; -final public class DispenserEntropyManipulator extends BehaviorDefaultDispenseItem +final public class DispenserBlockTool extends BehaviorDefaultDispenseItem { @Override protected ItemStack dispenseStack(IBlockSource dispenser, ItemStack dispensedItem) { Item i = dispensedItem.getItem(); - if ( i instanceof ToolEntropyManipulator ) + if ( i instanceof IBlockTool ) { EnumFacing enumfacing = BlockDispenser.func_149937_b( dispenser.getBlockMetadata() ); - ToolEntropyManipulator tm = (ToolEntropyManipulator) i; + IBlockTool tm = (IBlockTool) i; World w = dispenser.getWorld(); if ( w instanceof WorldServer ) diff --git a/hooks/IBlockTool.java b/hooks/IBlockTool.java new file mode 100644 index 00000000..ee707ae0 --- /dev/null +++ b/hooks/IBlockTool.java @@ -0,0 +1,12 @@ +package appeng.hooks; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public interface IBlockTool +{ + + boolean onItemUse(ItemStack dispensedItem, EntityPlayer player, World w, int x, int y, int z, int ordinal, float hitx, float hity, float hitz); + +} diff --git a/items/misc/ItemPaintBall.java b/items/misc/ItemPaintBall.java new file mode 100644 index 00000000..10a6e218 --- /dev/null +++ b/items/misc/ItemPaintBall.java @@ -0,0 +1,63 @@ +package appeng.items.misc; + +import java.util.EnumSet; +import java.util.List; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.client.MinecraftForgeClient; +import appeng.api.util.AEColor; +import appeng.client.render.items.PaintBallRender; +import appeng.core.features.AEFeature; +import appeng.core.localization.GuiText; +import appeng.items.AEBaseItem; +import appeng.util.Platform; + +public class ItemPaintBall extends AEBaseItem +{ + + public ItemPaintBall() { + super( ItemPaintBall.class ); + setfeature( EnumSet.of( AEFeature.PaintBalls ) ); + hasSubtypes = true; + if ( Platform.isClient() ) + MinecraftForgeClient.registerItemRenderer( this, new PaintBallRender() ); + } + + @Override + public String getItemStackDisplayName(ItemStack is) + { + return super.getItemStackDisplayName( is ) + " - " + getExtraName( is ); + } + + public String getExtraName(ItemStack is) + { + return (is.getItemDamage() >= 20 ? GuiText.Lumen + " " : "") + getColor( is ); + } + + public AEColor getColor(ItemStack is) + { + int dmg = is.getItemDamage(); + if ( dmg >= 20 ) + dmg -= 20; + + if ( dmg >= AEColor.values().length ) + return AEColor.Transparent; + + return AEColor.values()[dmg]; + } + + @Override + public void getSubItems(Item i, CreativeTabs ct, List l) + { + for (AEColor c : AEColor.values()) + if ( c != AEColor.Transparent ) + l.add( new ItemStack( this, 1, c.ordinal() ) ); + + for (AEColor c : AEColor.values()) + if ( c != AEColor.Transparent ) + l.add( new ItemStack( this, 1, 20 + c.ordinal() ) ); + } + +} diff --git a/items/tools/powered/ToolColorApplicator.java b/items/tools/powered/ToolColorApplicator.java new file mode 100644 index 00000000..0630ad07 --- /dev/null +++ b/items/tools/powered/ToolColorApplicator.java @@ -0,0 +1,328 @@ +package appeng.items.tools.powered; + +import java.util.Collections; +import java.util.EnumSet; +import java.util.LinkedList; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockDispenser; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import net.minecraftforge.client.MinecraftForgeClient; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.AEApi; +import appeng.api.config.Actionable; +import appeng.api.config.FuzzyMode; +import appeng.api.config.SortDir; +import appeng.api.implementations.items.IItemGroup; +import appeng.api.implementations.items.IStorageCell; +import appeng.api.networking.security.BaseActionSource; +import appeng.api.storage.ICellInventory; +import appeng.api.storage.ICellInventoryHandler; +import appeng.api.storage.IMEInventory; +import appeng.api.storage.StorageChannel; +import appeng.api.storage.data.IAEItemStack; +import appeng.api.storage.data.IItemList; +import appeng.api.util.AEColor; +import appeng.client.render.items.ToolColorApplicatorRender; +import appeng.core.AEConfig; +import appeng.core.features.AEFeature; +import appeng.core.localization.GuiText; +import appeng.helpers.IMouseWheelItem; +import appeng.hooks.DispenserBlockTool; +import appeng.hooks.IBlockTool; +import appeng.items.contents.CellConfig; +import appeng.items.contents.CellUpgrades; +import appeng.items.misc.ItemPaintBall; +import appeng.items.tools.powered.powersink.AEBasePoweredItem; +import appeng.me.storage.CellInventoryHandler; +import appeng.util.ItemSorters; +import appeng.util.Platform; +import appeng.util.item.AEItemStack; + +public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCell, IItemGroup, IBlockTool, IMouseWheelItem +{ + + public ToolColorApplicator() { + super( ToolColorApplicator.class, null ); + setfeature( EnumSet.of( AEFeature.ColorApplicator, AEFeature.StorageCells, AEFeature.PoweredTools ) ); + maxStoredPower = AEConfig.instance.colorapplicator_battery; + if ( Platform.isClient() ) + MinecraftForgeClient.registerItemRenderer( this, new ToolColorApplicatorRender() ); + } + + @Override + public void postInit() + { + super.postInit(); + BlockDispenser.dispenseBehaviorRegistry.putObject( this, new DispenserBlockTool() ); + } + + public ItemStack getColor(ItemStack is) + { + NBTTagCompound c = is.getTagCompound(); + if ( c != null && c.hasKey( "color" ) ) + { + NBTTagCompound color = c.getCompoundTag( "color" ); + ItemStack oldColor = ItemStack.loadItemStackFromNBT( color ); + if ( oldColor != null ) + return oldColor; + } + + return findNextColor( is, null, 0 ); + } + + private ItemStack findNextColor(ItemStack is, ItemStack anchor, int scrollOffset) + { + ItemStack newColor = null; + + IMEInventory inv = AEApi.instance().registries().cell().getCellInventory( is, StorageChannel.ITEMS ); + if ( inv != null ) + { + IItemList itemList = inv.getAvailableItems( AEApi.instance().storage().createItemList() ); + if ( anchor == null ) + { + IAEItemStack firstItem = itemList.getFirstItem(); + if ( firstItem != null ) + newColor = firstItem.getItemStack(); + } + else + { + LinkedList list = new LinkedList(); + + for (IAEItemStack i : itemList) + list.add( i ); + + ItemSorters.Direction = SortDir.ASCENDING; + ItemSorters.init(); + Collections.sort( list, ItemSorters.ConfigBased_SortByName ); + + if ( list.size() <= 0 ) + return null; + + IAEItemStack where = list.getFirst(); + int cycles = 1 + list.size(); + + while (cycles > 0 && !where.equals( anchor )) + { + list.addLast( list.removeFirst() ); + cycles--; + where = list.getFirst(); + } + + if ( scrollOffset > 0 ) + list.addLast( list.removeFirst() ); + + if ( scrollOffset < 0 ) + list.addFirst( list.removeLast() ); + + return list.get( 0 ).getItemStack(); + } + } + + if ( newColor != null ) + setColor( is, newColor ); + + return newColor; + } + + public void setColor(ItemStack is, ItemStack newColor) + { + NBTTagCompound data = Platform.openNbtData( is ); + if ( newColor == null ) + data.removeTag( "color" ); + else + { + NBTTagCompound color = new NBTTagCompound(); + newColor.writeToNBT( color ); + data.setTag( "color", color ); + } + } + + @Override + public boolean onItemUse(ItemStack is, EntityPlayer p, World w, int x, int y, int z, int side, float hitx, float hity, float hitz) + { + Block blk = w.getBlock( x, y, z ); + double powerPerUse = 100; + + ItemStack paintBall = getColor( is ); + + IMEInventory inv = AEApi.instance().registries().cell().getCellInventory( is, StorageChannel.ITEMS ); + if ( inv != null ) + { + IAEItemStack option = inv.extractItems( AEItemStack.create( paintBall ), Actionable.SIMULATE, new BaseActionSource() ); + + if ( option != null ) + { + paintBall = option.getItemStack(); + paintBall.stackSize = 1; + } + else + paintBall = null; + + if ( paintBall != null && paintBall.getItem() instanceof ItemPaintBall ) + { + ItemPaintBall ipb = (ItemPaintBall) paintBall.getItem(); + AEColor color = ipb.getColor( paintBall ); + + if ( getAECurrentPower( is ) > powerPerUse ) + { + if ( color != AEColor.Transparent && blk.recolourBlock( w, x, y, z, ForgeDirection.getOrientation( side ), color.ordinal() ) ) + { + inv.extractItems( AEItemStack.create( paintBall ), Actionable.MODULATE, new BaseActionSource() ); + extractAEPower( is, powerPerUse ); + return true; + } + } + + } + } + + if ( p.isSneaking() ) + { + cycleColors( is, paintBall, 1 ); + } + + return false; + } + + public void cycleColors(ItemStack is, ItemStack paintBall, int i) + { + if ( paintBall == null ) + { + setColor( is, getColor( is ) ); + } + else + { + setColor( is, findNextColor( is, paintBall, i ) ); + } + } + + @Override + public String getItemStackDisplayName(ItemStack par1ItemStack) + { + String extra = GuiText.Empty.getLocal(); + + ItemStack selected = getColor( par1ItemStack ); + + if ( selected != null && selected.getItem() instanceof ItemPaintBall ) + extra = ((ItemPaintBall) selected.getItem()).getExtraName( selected ); + + return super.getItemStackDisplayName( par1ItemStack ) + " - " + extra; + } + + @Override + public void addInformation(ItemStack is, EntityPlayer player, List lines, boolean advancedItemTooltips) + { + super.addInformation( is, player, lines, advancedItemTooltips ); + + IMEInventory cdi = AEApi.instance().registries().cell().getCellInventory( is, StorageChannel.ITEMS ); + + if ( cdi instanceof CellInventoryHandler ) + { + ICellInventory cd = ((ICellInventoryHandler) cdi).getCellInv(); + if ( cd != null ) + { + lines.add( cd.getUsedBytes() + " " + GuiText.Of.getLocal() + " " + cd.getTotalBytes() + " " + GuiText.BytesUsed.getLocal() ); + lines.add( cd.getStoredItemTypes() + " " + GuiText.Of.getLocal() + " " + cd.getTotalItemTypes() + " " + GuiText.Types.getLocal() ); + } + } + } + + @Override + public int getBytes(ItemStack cellItem) + { + return 512; + } + + @Override + public int BytePerType(ItemStack iscellItem) + { + return 8; + } + + @Override + public int getTotalTypes(ItemStack cellItem) + { + return 27; + } + + @Override + public boolean isBlackListed(ItemStack cellItem, IAEItemStack requsetedAddition) + { + return requsetedAddition == null || !(requsetedAddition.getItem() instanceof ItemPaintBall); + } + + @Override + public boolean storableInStorageCell() + { + return true; + } + + @Override + public boolean isStorageCell(ItemStack i) + { + return true; + } + + @Override + public IInventory getUpgradesInventory(ItemStack is) + { + return new CellUpgrades( is, 2 ); + } + + @Override + public IInventory getConfigInventory(ItemStack is) + { + return new CellConfig( is ); + } + + @Override + public FuzzyMode getFuzzyMode(ItemStack is) + { + String fz = Platform.openNbtData( is ).getString( "FuzzyMode" ); + try + { + return FuzzyMode.valueOf( fz ); + } + catch (Throwable t) + { + return FuzzyMode.IGNORE_ALL; + } + } + + @Override + public String getUnlocalizedGroupName(ItemStack is) + { + return GuiText.StorageCells.getUnlocalized(); + } + + @Override + public void setFuzzyMode(ItemStack is, FuzzyMode fzMode) + { + Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() ); + } + + @Override + public boolean isEditable(ItemStack is) + { + return true; + } + + @Override + public double getIdleDrain() + { + return 0.5; + } + + @Override + public void onWheel(ItemStack is, boolean up) + { + cycleColors( is, getColor( is ), up ? 1 : -1 ); + } + +} diff --git a/items/tools/powered/ToolEntropyManipulator.java b/items/tools/powered/ToolEntropyManipulator.java index c194d87a..5a25d62b 100644 --- a/items/tools/powered/ToolEntropyManipulator.java +++ b/items/tools/powered/ToolEntropyManipulator.java @@ -24,12 +24,13 @@ import net.minecraftforge.oredict.OreDictionary; import appeng.block.misc.BlockTinyTNT; import appeng.core.AEConfig; import appeng.core.features.AEFeature; -import appeng.hooks.DispenserEntropyManipulator; +import appeng.hooks.DispenserBlockTool; +import appeng.hooks.IBlockTool; import appeng.items.tools.powered.powersink.AEBasePoweredItem; import appeng.util.InWorldToolOperationResult; import appeng.util.Platform; -public class ToolEntropyManipulator extends AEBasePoweredItem +public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockTool { static class Combo @@ -160,8 +161,7 @@ public class ToolEntropyManipulator extends AEBasePoweredItem public void postInit() { super.postInit(); - - BlockDispenser.dispenseBehaviorRegistry.putObject( this, new DispenserEntropyManipulator() ); + BlockDispenser.dispenseBehaviorRegistry.putObject( this, new DispenserBlockTool() ); } @Override diff --git a/parts/PartPlacement.java b/parts/PartPlacement.java index f19db928..1c10dff0 100644 --- a/parts/PartPlacement.java +++ b/parts/PartPlacement.java @@ -65,7 +65,9 @@ public class PartPlacement else if ( event.entityPlayer != null ) { ItemStack held = event.entityPlayer.getHeldItem(); - if ( event.entityPlayer.isSneaking() && held != null && AEApi.instance().items().itemMemoryCard.sameAsStack( held ) ) + boolean supportedItem = AEApi.instance().items().itemMemoryCard.sameAsStack( held ) + || AEApi.instance().items().itemColorApplicator.sameAsStack( held ); + if ( event.entityPlayer.isSneaking() && held != null && supportedItem ) { try {