diff --git a/block/AEBaseBlock.java b/block/AEBaseBlock.java index ad3c3910e..d6af90a7f 100644 --- a/block/AEBaseBlock.java +++ b/block/AEBaseBlock.java @@ -779,7 +779,7 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature if ( c != newColor ) { - ct.setColor( newColor ); + ct.recolourBlock( side, newColor, null ); return true; } return false; diff --git a/block/networking/BlockCableBus.java b/block/networking/BlockCableBus.java index b501a15e6..27e1c3873 100644 --- a/block/networking/BlockCableBus.java +++ b/block/networking/BlockCableBus.java @@ -28,6 +28,7 @@ import appeng.api.parts.IPart; import appeng.api.parts.IPartHost; import appeng.api.parts.PartItemStack; import appeng.api.parts.SelectedPart; +import appeng.api.util.AEColor; import appeng.block.AEBaseBlock; import appeng.client.render.BaseBlockRender; import appeng.client.render.BusRenderHelper; @@ -224,7 +225,7 @@ public class BlockCableBus extends AEBaseBlock implements IRedNetConnection { try { - return cb( world, x, y, z ).recolourBlock( side, colour, who ); + return cb( world, x, y, z ).recolourBlock( side, AEColor.values()[colour], who ); } catch (Throwable t) { diff --git a/client/ClientHelper.java b/client/ClientHelper.java index f1e3c8148..bb1ba3983 100644 --- a/client/ClientHelper.java +++ b/client/ClientHelper.java @@ -27,11 +27,13 @@ import net.minecraftforge.client.ForgeHooksClient; import net.minecraftforge.client.IItemRenderer; import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.client.event.MouseEvent; +import net.minecraftforge.client.event.RenderLivingEvent; import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.common.MinecraftForge; import org.lwjgl.opengl.GL11; +import appeng.api.util.AEColor; import appeng.block.AEBaseBlock; import appeng.client.render.BaseBlockRender; import appeng.client.render.TESRWrapper; @@ -56,6 +58,8 @@ import appeng.entity.EntityTinyTNTPrimed; import appeng.entity.RenderFloatingItem; import appeng.entity.RenderTinyTNTPrimed; import appeng.helpers.IMouseWheelItem; +import appeng.hooks.TickHandler; +import appeng.hooks.TickHandler.PlayerColor; import appeng.server.ServerHelper; import appeng.util.Platform; import cpw.mods.fml.client.registry.ClientRegistry; @@ -68,6 +72,21 @@ public class ClientHelper extends ServerHelper private static RenderItem itemRenderer = new RenderItem(); private static RenderBlocks blockRenderer = new RenderBlocks(); + @SubscribeEvent + public void postPlayerRender(RenderLivingEvent.Pre p) + { + PlayerColor player = TickHandler.instance.getPlayerColors().get( p.entity.getEntityId() ); + if ( player != null ) + { + AEColor col = player.myColor; + + float r = (float) (0xff & (col.mediumVariant >> 16)); + float g = (float) (0xff & (col.mediumVariant >> 8)); + float b = (float) (0xff & (col.mediumVariant)); + GL11.glColor3f( r / 255.0f, g / 255.0f, b / 255.0f ); + } + } + @Override public void doRenderItem(ItemStack itemstack, World w) { diff --git a/client/render/blocks/RenderBlockPaint.java b/client/render/blocks/RenderBlockPaint.java index 8276fa2fa..bbd2828af 100644 --- a/client/render/blocks/RenderBlockPaint.java +++ b/client/render/blocks/RenderBlockPaint.java @@ -1,5 +1,7 @@ package appeng.client.render.blocks; +import java.util.EnumSet; + import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; import net.minecraft.item.ItemStack; @@ -44,8 +46,19 @@ public class RenderBlockPaint extends BaseBlockRender double offoff = 0.001; + EnumSet validSides = EnumSet.noneOf( ForgeDirection.class ); + + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + { + if ( tp.isSideValid( side ) ) + validSides.add( side ); + } + for (Splot s : tp.getDots()) { + if ( !validSides.contains( s.side ) ) + continue; + if ( s.lumen ) { tess.setColorOpaque_I( s.color.whiteVariant ); diff --git a/client/render/items/ToolColorApplicatorRender.java b/client/render/items/ToolColorApplicatorRender.java index 0d57fdcee..0700b6736 100644 --- a/client/render/items/ToolColorApplicatorRender.java +++ b/client/render/items/ToolColorApplicatorRender.java @@ -2,6 +2,7 @@ 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; @@ -84,12 +85,20 @@ public class ToolColorApplicatorRender implements IItemRenderer GL11.glTranslatef( 4, 6, 0 ); GL11.glDisable( GL11.GL_LIGHTING ); + 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 ); + } - AEColor col = ipb.getColor( is ); + if ( is != null && is.getItem() instanceof ItemSnowball ) + col = AEColor.Transparent; + + if ( col != null ) + { tessellator.startDrawingQuads(); float z = 0; diff --git a/core/WorldSettings.java b/core/WorldSettings.java index c6521a1d8..364d206fe 100644 --- a/core/WorldSettings.java +++ b/core/WorldSettings.java @@ -15,6 +15,8 @@ import net.minecraftforge.common.config.Property; import appeng.api.util.WorldCoord; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketNewStorageDimension; +import appeng.hooks.TickHandler; +import appeng.hooks.TickHandler.PlayerColor; import appeng.me.GridStorage; import appeng.me.GridStorageSearch; import appeng.services.CompassService; @@ -130,6 +132,9 @@ public class WorldSettings extends Configuration AELog.error( e ); } } + + for (PlayerColor pc : TickHandler.instance.getPlayerColors().values()) + NetworkHandler.instance.sendToAll( pc.getPacket() ); } public void init() diff --git a/core/localization/GuiText.java b/core/localization/GuiText.java index 462146a80..d74767ad1 100644 --- a/core/localization/GuiText.java +++ b/core/localization/GuiText.java @@ -32,7 +32,7 @@ public enum GuiText OfSecondOutput, NoSecondOutput, RFTunnel, Stores, Next, SelectAmount, Lumen, Empty, ConfirmCrafting, - Stored, Crafting, Scheduled, CraftingStatus, Cancel, FromStorage, ToCraft, CraftingPlan, CalculatingWait, Start, Bytes, CraftingCPU, Automatic, CoProcessors, Simulation, Missing, InterfaceTerminal, NoCraftingCPUs, LightTunnel; + Stored, Crafting, Scheduled, CraftingStatus, Cancel, FromStorage, ToCraft, CraftingPlan, CalculatingWait, Start, Bytes, CraftingCPU, Automatic, CoProcessors, Simulation, Missing, InterfaceTerminal, NoCraftingCPUs, LightTunnel, Clean; String root; diff --git a/core/sync/AppEngPacketHandlerBase.java b/core/sync/AppEngPacketHandlerBase.java index 51ce567a9..1386c0ae2 100644 --- a/core/sync/AppEngPacketHandlerBase.java +++ b/core/sync/AppEngPacketHandlerBase.java @@ -22,6 +22,7 @@ import appeng.core.sync.packets.PacketMockExplosion; import appeng.core.sync.packets.PacketMultiPart; import appeng.core.sync.packets.PacketNEIRecipe; import appeng.core.sync.packets.PacketNewStorageDimension; +import appeng.core.sync.packets.PacketPaintedEntity; import appeng.core.sync.packets.PacketPartPlacement; import appeng.core.sync.packets.PacketPartialItem; import appeng.core.sync.packets.PacketPatternSlot; @@ -82,7 +83,9 @@ public class AppEngPacketHandlerBase PACKET_ASSEMBLER_ANIMATION(PacketAssemblerAnimation.class), - PACKET_COMPRESSED_NBT(PacketCompressedNBT.class); + PACKET_COMPRESSED_NBT(PacketCompressedNBT.class), + + PACKET_PAINTED_ENTITY(PacketPaintedEntity.class); final public Class pc; final public Constructor con; diff --git a/core/sync/packets/PacketPaintedEntity.java b/core/sync/packets/PacketPaintedEntity.java new file mode 100644 index 000000000..6e6c66755 --- /dev/null +++ b/core/sync/packets/PacketPaintedEntity.java @@ -0,0 +1,48 @@ +package appeng.core.sync.packets; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; + +import java.io.IOException; + +import net.minecraft.entity.player.EntityPlayer; +import appeng.api.util.AEColor; +import appeng.core.sync.AppEngPacket; +import appeng.core.sync.network.INetworkInfo; +import appeng.hooks.TickHandler; +import appeng.hooks.TickHandler.PlayerColor; + +public class PacketPaintedEntity extends AppEngPacket +{ + + private AEColor myColor; + private int entityId; + private int ticks; + + // automatic. + public PacketPaintedEntity(ByteBuf stream) throws IOException { + entityId = stream.readInt(); + myColor = AEColor.values()[stream.readByte()]; + ticks = stream.readInt(); + } + + @Override + public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player) + { + PlayerColor pc = new PlayerColor( entityId, myColor, ticks ); + TickHandler.instance.getPlayerColors().put( entityId, pc ); + } + + // api + public PacketPaintedEntity(int myEntity, AEColor myColor, int ticksLeft) { + + ByteBuf data = Unpooled.buffer(); + + data.writeInt( getPacketID() ); + data.writeInt( this.entityId = myEntity ); + data.writeByte( (this.myColor = myColor).ordinal() ); + data.writeInt( ticksLeft ); + + configureWrite( data ); + } +} diff --git a/fmp/CableBusPart.java b/fmp/CableBusPart.java index 953f9750a..981f98424 100644 --- a/fmp/CableBusPart.java +++ b/fmp/CableBusPart.java @@ -96,6 +96,12 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IReds return cb.getCableConnectionType( dir ); } + @Override + public boolean recolourBlock(ForgeDirection side, AEColor colour, EntityPlayer who) + { + return cb.recolourBlock( side, colour, who ); + } + @Override public AEColor getColor() { diff --git a/helpers/AEMultiTile.java b/helpers/AEMultiTile.java index bef994bd8..99539274f 100644 --- a/helpers/AEMultiTile.java +++ b/helpers/AEMultiTile.java @@ -1,9 +1,10 @@ package appeng.helpers; +import appeng.api.implementations.tiles.IColorableTile; import appeng.api.networking.IGridHost; import appeng.api.parts.IPartHost; -public interface AEMultiTile extends IGridHost, IPartHost +public interface AEMultiTile extends IGridHost, IPartHost, IColorableTile { } diff --git a/hooks/TickHandler.java b/hooks/TickHandler.java index 51d220ca1..c6b062d33 100644 --- a/hooks/TickHandler.java +++ b/hooks/TickHandler.java @@ -1,6 +1,7 @@ package appeng.hooks; import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.Queue; @@ -11,7 +12,9 @@ import net.minecraft.world.World; import net.minecraftforge.event.world.ChunkEvent; import net.minecraftforge.event.world.WorldEvent; import appeng.api.networking.IGridNode; +import appeng.api.util.AEColor; import appeng.core.AELog; +import appeng.core.sync.packets.PacketPaintedEntity; import appeng.crafting.CraftingJob; import appeng.entity.EntityFloatingItem; import appeng.me.Grid; @@ -54,6 +57,47 @@ public class TickHandler final private HandlerRep server = new HandlerRep(); final private HandlerRep client = new HandlerRep(); + static public class PlayerColor + { + + public final AEColor myColor; + protected final int myEntity; + protected int ticksLeft; + + public PacketPaintedEntity getPacket() + { + return new PacketPaintedEntity( myEntity, myColor, ticksLeft ); + } + + public PlayerColor(int id, AEColor col, int ticks) { + myEntity = id; + myColor = col; + ticksLeft = ticks; + } + + }; + + final private HashMap cliPlayerColors = new HashMap(); + final private HashMap srvPlayerColors = new HashMap(); + + public HashMap getPlayerColors() + { + if ( Platform.isServer() ) + return srvPlayerColors; + return cliPlayerColors; + } + + private void tickColors(HashMap playerSet) + { + Iterator i = playerSet.values().iterator(); + while (i.hasNext()) + { + PlayerColor pc = i.next(); + if ( pc.ticksLeft-- <= 0 ) + i.remove(); + } + } + HandlerRep getRepo() { if ( Platform.isServer() ) @@ -143,6 +187,7 @@ public class TickHandler if ( ev.type == Type.CLIENT && ev.phase == Phase.START ) { + tickColors( cliPlayerColors ); EntityFloatingItem.ageStatic = (EntityFloatingItem.ageStatic + 1) % 60000; } @@ -165,12 +210,13 @@ public class TickHandler // for no there is no reason to care about this on the client... else if ( ev.type == Type.SERVER && ev.phase == Phase.END ) { + tickColors( srvPlayerColors ); // ready tiles. HandlerRep repo = getRepo(); while (!repo.tiles.isEmpty()) { AEBaseTile bt = repo.tiles.poll(); - if (! bt.isInvalid() ) + if ( !bt.isInvalid() ) bt.onReady(); } diff --git a/items/tools/powered/ToolColorApplicator.java b/items/tools/powered/ToolColorApplicator.java index 6d32e8151..29d89f01b 100644 --- a/items/tools/powered/ToolColorApplicator.java +++ b/items/tools/powered/ToolColorApplicator.java @@ -11,8 +11,10 @@ import net.minecraft.block.BlockDispenser; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemSnowball; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.common.util.ForgeDirection; @@ -22,6 +24,7 @@ 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.implementations.tiles.IColorableTile; import appeng.api.networking.security.BaseActionSource; import appeng.api.storage.ICellInventory; import appeng.api.storage.ICellInventoryHandler; @@ -30,6 +33,7 @@ import appeng.api.storage.StorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; import appeng.api.util.AEColor; +import appeng.block.misc.BlockPaint; import appeng.client.render.items.ToolColorApplicatorRender; import appeng.core.AEConfig; import appeng.core.features.AEFeature; @@ -42,6 +46,7 @@ import appeng.items.contents.CellUpgrades; import appeng.items.misc.ItemPaintBall; import appeng.items.tools.powered.powersink.AEBasePoweredItem; import appeng.me.storage.CellInventoryHandler; +import appeng.tile.misc.TilePaint; import appeng.util.ItemSorters; import appeng.util.Platform; import appeng.util.item.AEItemStack; @@ -166,7 +171,36 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe else paintBall = null; - if ( paintBall != null && paintBall.getItem() instanceof ItemPaintBall ) + if ( paintBall != null && paintBall.getItem() instanceof ItemSnowball ) + { + ForgeDirection oside = ForgeDirection.getOrientation( side ); + TileEntity te = w.getTileEntity( x, y, z ); + // clean cables. + if ( te instanceof IColorableTile ) + { + if ( getAECurrentPower( is ) > powerPerUse && ((IColorableTile) te).getColor() != AEColor.Transparent ) + { + if ( ((IColorableTile) te).recolourBlock( oside, AEColor.Transparent, p ) ) + { + inv.extractItems( AEItemStack.create( paintBall ), Actionable.MODULATE, new BaseActionSource() ); + extractAEPower( is, powerPerUse ); + return true; + } + } + } + + // clean paint balls.. + Block testBlk = w.getBlock( x + oside.offsetX, y + oside.offsetY, z + oside.offsetZ ); + TileEntity painte = w.getTileEntity( x + oside.offsetX, y + oside.offsetY, z + oside.offsetZ ); + if ( getAECurrentPower( is ) > powerPerUse && testBlk instanceof BlockPaint && painte instanceof TilePaint ) + { + inv.extractItems( AEItemStack.create( paintBall ), Actionable.MODULATE, new BaseActionSource() ); + extractAEPower( is, powerPerUse ); + ((TilePaint) painte).cleanSide( oside.getOpposite() ); + return true; + } + } + else if ( paintBall != null && paintBall.getItem() instanceof ItemPaintBall ) { ItemPaintBall ipb = (ItemPaintBall) paintBall.getItem(); AEColor color = ipb.getColor( paintBall ); @@ -264,6 +298,9 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe ItemStack selected = getColor( 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 ); @@ -309,7 +346,14 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe @Override public boolean isBlackListed(ItemStack cellItem, IAEItemStack requsetedAddition) { - return requsetedAddition == null || !(requsetedAddition.getItem() instanceof ItemPaintBall && requsetedAddition.getItemDamage() < 20); + if ( requsetedAddition != null ) + { + if ( requsetedAddition.getItem() instanceof ItemSnowball ) + return false; + + return !(requsetedAddition.getItem() instanceof ItemPaintBall && requsetedAddition.getItemDamage() < 20); + } + return true; } @Override diff --git a/items/tools/powered/ToolMassCannon.java b/items/tools/powered/ToolMassCannon.java index 8c574cb76..b0bf17c66 100644 --- a/items/tools/powered/ToolMassCannon.java +++ b/items/tools/powered/ToolMassCannon.java @@ -8,6 +8,7 @@ import net.minecraft.block.BlockDispenser; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.passive.EntitySheep; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; @@ -33,14 +34,18 @@ import appeng.api.storage.StorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEStack; import appeng.api.storage.data.IItemList; +import appeng.api.util.AEColor; import appeng.core.AEConfig; import appeng.core.AELog; import appeng.core.CommonHelper; import appeng.core.features.AEFeature; import appeng.core.localization.GuiText; import appeng.core.localization.PlayerMessages; +import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketMatterCannon; import appeng.hooks.DispenserMatterCannon; +import appeng.hooks.TickHandler; +import appeng.hooks.TickHandler.PlayerColor; import appeng.items.contents.CellConfig; import appeng.items.contents.CellUpgrades; import appeng.items.misc.ItemPaintBall; @@ -144,34 +149,7 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell ItemStack type = ((IAEItemStack) aeammo).getItemStack(); if ( type.getItem() instanceof ItemPaintBall ) { - MovingObjectPosition pos = w.rayTraceBlocks( vec3, vec31, false ); - if ( pos != null && pos.typeOfHit == MovingObjectType.BLOCK ) - { - ForgeDirection side = ForgeDirection.getOrientation( pos.sideHit ); - - int x = pos.blockX + side.offsetX; - int y = pos.blockY + side.offsetY; - int z = pos.blockZ + side.offsetZ; - - Block whatsThere = w.getBlock( x, y, z ); - if ( whatsThere == AEApi.instance().blocks().blockPaint.block() ) - { - - } - else if ( whatsThere.isReplaceable( w, x, y, z ) && w.isAirBlock( x, y, z ) ) - { - w.setBlock( x, y, z, AEApi.instance().blocks().blockPaint.block(), 0, 3 ); - } - - TileEntity te = w.getTileEntity( x, y, z ); - if ( te instanceof TilePaint ) - { - pos.hitVec.xCoord -= x; - pos.hitVec.yCoord -= y; - pos.hitVec.zCoord -= z; - ((TilePaint) te).addBlot( type, side.getOpposite(), pos.hitVec ); - } - } + shootPaintBalls( type, w, p, vec3, vec31, direction, d0, d1, d2 ); } return item; } @@ -193,6 +171,123 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell return item; } + private void shootPaintBalls(ItemStack type, World w, EntityPlayer p, Vec3 vec3, Vec3 vec31, Vec3 direction, double d0, double d1, double d2) + { + AxisAlignedBB bb = AxisAlignedBB.getBoundingBox( Math.min( vec3.xCoord, vec31.xCoord ), Math.min( vec3.yCoord, vec31.yCoord ), + Math.min( vec3.zCoord, vec31.zCoord ), Math.max( vec3.xCoord, vec31.xCoord ), Math.max( vec3.yCoord, vec31.yCoord ), + Math.max( vec3.zCoord, vec31.zCoord ) ).expand( 16, 16, 16 ); + + Entity entity = null; + List list = w.getEntitiesWithinAABBExcludingEntity( p, bb ); + double Closeest = 9999999.0D; + int l; + + for (l = 0; l < list.size(); ++l) + { + Entity entity1 = (Entity) list.get( l ); + + if ( entity1.isDead == false && entity1 != p && !(entity1 instanceof EntityItem) ) + { + if ( entity1.isEntityAlive() ) + { + // prevent killing / flying of mounts. + if ( entity1.riddenByEntity == p ) + continue; + + float f1 = 0.3F; + AxisAlignedBB axisalignedbb1 = entity1.boundingBox.expand( (double) f1, (double) f1, (double) f1 ); + MovingObjectPosition movingobjectposition1 = axisalignedbb1.calculateIntercept( vec3, vec31 ); + + if ( movingobjectposition1 != null ) + { + double nd = vec3.squareDistanceTo( movingobjectposition1.hitVec ); + + if ( nd < Closeest ) + { + entity = entity1; + Closeest = nd; + } + } + } + } + } + + MovingObjectPosition pos = w.rayTraceBlocks( vec3, vec31, false ); + + Vec3 Srec = Vec3.createVectorHelper( d0, d1, d2 ); + if ( entity != null && pos != null && pos.hitVec.squareDistanceTo( Srec ) > Closeest ) + { + pos = new MovingObjectPosition( entity ); + } + else if ( entity != null && pos == null ) + { + pos = new MovingObjectPosition( entity ); + } + + try + { + CommonHelper.proxy.sendToAllNearExcept( null, d0, d1, d2, 128, w, new PacketMatterCannon( d0, d1, d2, (float) direction.xCoord, + (float) direction.yCoord, (float) direction.zCoord, (byte) (pos == null ? 32 : pos.hitVec.squareDistanceTo( Srec ) + 1) ) ); + + } + catch (Exception err) + { + AELog.error( err ); + } + + if ( pos != null && type != null && type.getItem() instanceof ItemPaintBall ) + { + ItemPaintBall ipb = (ItemPaintBall) type.getItem(); + + AEColor col = ipb.getColor( type ); + // boolean lit = ipb.isLumen( type ); + + if ( pos.typeOfHit == MovingObjectType.ENTITY ) + { + int id = pos.entityHit.getEntityId(); + PlayerColor marker = new PlayerColor( id, col, 20 * 30 ); + TickHandler.instance.getPlayerColors().put( id, marker ); + + if ( pos.entityHit instanceof EntitySheep ) + { + EntitySheep sh = (EntitySheep) pos.entityHit; + sh.setFleeceColor( col.ordinal() ); + } + + pos.entityHit.attackEntityFrom( DamageSource.causePlayerDamage( p ), (float) 0 ); + NetworkHandler.instance.sendToAll( marker.getPacket() ); + } + else if ( pos.typeOfHit == MovingObjectType.BLOCK ) + { + ForgeDirection side = ForgeDirection.getOrientation( pos.sideHit ); + + int x = pos.blockX + side.offsetX; + int y = pos.blockY + side.offsetY; + int z = pos.blockZ + side.offsetZ; + + Block whatsThere = w.getBlock( x, y, z ); + if ( whatsThere == AEApi.instance().blocks().blockPaint.block() ) + { + + } + else if ( whatsThere.isReplaceable( w, x, y, z ) && w.isAirBlock( x, y, z ) ) + { + w.setBlock( x, y, z, AEApi.instance().blocks().blockPaint.block(), 0, 3 ); + } + + TileEntity te = w.getTileEntity( x, y, z ); + if ( te instanceof TilePaint ) + { + pos.hitVec.xCoord -= x; + pos.hitVec.yCoord -= y; + pos.hitVec.zCoord -= z; + ((TilePaint) te).addBlot( type, side.getOpposite(), pos.hitVec ); + } + } + + } + } + private void standardAmmo(float penitration, World w, EntityPlayer p, Vec3 vec3, Vec3 vec31, Vec3 direction, double d0, double d1, double d2) { boolean hasDestroyedSomething = true; diff --git a/parts/CableBusContainer.java b/parts/CableBusContainer.java index c045179a1..9c1d19067 100644 --- a/parts/CableBusContainer.java +++ b/parts/CableBusContainer.java @@ -799,16 +799,13 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer } @Override - public boolean recolourBlock(ForgeDirection side, int colour, EntityPlayer who) + public boolean recolourBlock(ForgeDirection side, AEColor colour, EntityPlayer who) { IPart cable = getPart( ForgeDirection.UNKNOWN ); if ( cable != null ) { IPartCable pc = (IPartCable) cable; - - AEColor colors[] = AEColor.values(); - if ( colors.length > colour ) - return pc.changeColor( colors[colour], who ); + return pc.changeColor( colour, who ); } return false; } diff --git a/parts/ICableBusContainer.java b/parts/ICableBusContainer.java index f74be2b6f..08155da8d 100644 --- a/parts/ICableBusContainer.java +++ b/parts/ICableBusContainer.java @@ -10,6 +10,7 @@ import net.minecraft.util.Vec3; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import appeng.api.parts.SelectedPart; +import appeng.api.util.AEColor; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -34,7 +35,7 @@ public interface ICableBusContainer SelectedPart selectPart(Vec3 v3); - boolean recolourBlock(ForgeDirection side, int colour, EntityPlayer who); + boolean recolourBlock(ForgeDirection side, AEColor colour, EntityPlayer who); boolean isLadder(EntityLivingBase entity); diff --git a/parts/NullCableBusContainer.java b/parts/NullCableBusContainer.java index a0fdad011..af5af111d 100644 --- a/parts/NullCableBusContainer.java +++ b/parts/NullCableBusContainer.java @@ -10,6 +10,7 @@ import net.minecraft.util.Vec3; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import appeng.api.parts.SelectedPart; +import appeng.api.util.AEColor; public class NullCableBusContainer implements ICableBusContainer { @@ -69,7 +70,7 @@ public class NullCableBusContainer implements ICableBusContainer } @Override - public boolean recolourBlock(ForgeDirection side, int colour, EntityPlayer who) + public boolean recolourBlock(ForgeDirection side, AEColor colour, EntityPlayer who) { return false; } diff --git a/tile/crafting/TileCraftingMonitorTile.java b/tile/crafting/TileCraftingMonitorTile.java index 5c80989eb..e34ab58dd 100644 --- a/tile/crafting/TileCraftingMonitorTile.java +++ b/tile/crafting/TileCraftingMonitorTile.java @@ -4,7 +4,9 @@ import io.netty.buffer.ByteBuf; import java.io.IOException; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; import appeng.api.implementations.tiles.IColorableTile; import appeng.api.storage.data.IAEItemStack; import appeng.api.util.AEColor; @@ -126,10 +128,15 @@ public class TileCraftingMonitorTile extends TileCraftingTile implements IColora return paintedColor; } - public void setColor(AEColor newPaintedColor) + @Override + public boolean recolourBlock(ForgeDirection side, AEColor newPaintedColor, EntityPlayer who) { + if ( paintedColor == newPaintedColor ) + return false; + paintedColor = newPaintedColor; markDirty(); markForUpdate(); + return true; } } diff --git a/tile/misc/TilePaint.java b/tile/misc/TilePaint.java index 2f8e1c5ba..2bc4c1ff8 100644 --- a/tile/misc/TilePaint.java +++ b/tile/misc/TilePaint.java @@ -121,11 +121,15 @@ public class TilePaint extends AEBaseTile for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { - Block blk = worldObj.getBlock( xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ ); - if ( !blk.isSideSolid( worldObj, xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ, side.getOpposite() ) ) + if ( !isSideValid( side ) ) removeSide( side ); } + updateData(); + } + + private void updateData() + { isLit = 0; for (Splot s : dots) { @@ -144,6 +148,22 @@ public class TilePaint extends AEBaseTile worldObj.setBlock( xCoord, yCoord, zCoord, Blocks.air ); } + public void cleanSide(ForgeDirection side) + { + if ( dots == null ) + return; + + removeSide( side ); + + updateData(); + } + + public boolean isSideValid(ForgeDirection side) + { + Block blk = worldObj.getBlock( xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ ); + return blk.isSideSolid( worldObj, xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ, side.getOpposite() ); + } + private void removeSide(ForgeDirection side) { Iterator i = dots.iterator(); diff --git a/tile/misc/TileSecurity.java b/tile/misc/TileSecurity.java index 23d6fa358..de679a456 100644 --- a/tile/misc/TileSecurity.java +++ b/tile/misc/TileSecurity.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.EnumSet; import java.util.HashMap; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -328,11 +329,16 @@ public class TileSecurity extends AENetworkTile implements ITerminalHost, IAEApp return paintedColor; } - public void setColor(AEColor newPaintedColor) + @Override + public boolean recolourBlock(ForgeDirection side, AEColor newPaintedColor, EntityPlayer who) { + if ( paintedColor == newPaintedColor ) + return false; + paintedColor = newPaintedColor; markDirty(); markForUpdate(); + return true; } } diff --git a/tile/networking/TileCableBus.java b/tile/networking/TileCableBus.java index f65c4056c..a339884e4 100644 --- a/tile/networking/TileCableBus.java +++ b/tile/networking/TileCableBus.java @@ -345,4 +345,10 @@ public class TileCableBus extends AEBaseTile implements AEMultiTile, ICustomColl cb.updateConnections(); } + @Override + public boolean recolourBlock(ForgeDirection side, AEColor colour, EntityPlayer who) + { + return cb.recolourBlock( side, colour, who ); + } + } diff --git a/tile/storage/TileChest.java b/tile/storage/TileChest.java index b30e89cb3..d29663a28 100644 --- a/tile/storage/TileChest.java +++ b/tile/storage/TileChest.java @@ -827,10 +827,15 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, IFluidHan return paintedColor; } - public void setColor(AEColor newPaintedColor) + @Override + public boolean recolourBlock(ForgeDirection side, AEColor newPaintedColor, EntityPlayer who) { + if ( paintedColor == newPaintedColor ) + return false; + paintedColor = newPaintedColor; markDirty(); markForUpdate(); + return true; } }