package org.freeforums.geforce.securitycraft.blocks; import java.util.ArrayList; import java.util.HashSet; import java.util.Random; import java.util.Set; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.Direction; import net.minecraft.util.IIcon; import net.minecraft.world.ChunkPosition; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import org.freeforums.geforce.securitycraft.main.mod_SecurityCraft; import org.freeforums.geforce.securitycraft.tileentity.TileEntityEmpedWire; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @SuppressWarnings({"rawtypes", "unused", "unchecked"}) public class BlockEMPedWire extends BlockContainer { /** * When false, power transmission methods do not look at other redstone wires. Used internally during * updateCurrentStrength. */ private boolean field_150181_a = true; private Set field_150179_b = new HashSet(); @SideOnly(Side.CLIENT) private IIcon field_94413_c; @SideOnly(Side.CLIENT) private IIcon field_94410_cO; @SideOnly(Side.CLIENT) private IIcon field_94411_cP; @SideOnly(Side.CLIENT) private IIcon field_94412_cQ; public BlockEMPedWire() { super(Material.circuits); this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.0625F, 1.0F); } /** * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been * cleared to be reused) */ public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) { return null; } /** * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. */ public boolean isOpaqueCube() { return false; } /** * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) */ public boolean renderAsNormalBlock() { return false; } /** * The type of render function that is called for this block */ public int getRenderType() { return 5; } @SideOnly(Side.CLIENT) /** * Returns a integer with hex for 0xrrggbb with this color multiplied against the blocks color. Note only called * when first determining what to render. */ public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { return 8388608; } /** * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z */ public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) { return World.doesBlockHaveSolidTopSurface(par1World, par2, par3 - 1, par4) || par1World.getBlock(par2, par3 - 1, par4) == Blocks.glowstone; } public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random){ if(!par1World.isRemote){ //par1World.setBlock(par2, par3, par4, Block.redstoneWire); } } /** * Calls World.notifyBlocksOfNeighborChange() for all neighboring blocks, but only if the given block is a redstone * wire. */ private void notifyWireNeighborsOfNeighborChange(World par1World, int par2, int par3, int par4) { if (par1World.getBlock(par2, par3, par4) == this) { par1World.notifyBlocksOfNeighborChange(par2, par3, par4, this); par1World.notifyBlocksOfNeighborChange(par2 - 1, par3, par4, this); par1World.notifyBlocksOfNeighborChange(par2 + 1, par3, par4, this); par1World.notifyBlocksOfNeighborChange(par2, par3, par4 - 1, this); par1World.notifyBlocksOfNeighborChange(par2, par3, par4 + 1, this); par1World.notifyBlocksOfNeighborChange(par2, par3 - 1, par4, this); par1World.notifyBlocksOfNeighborChange(par2, par3 + 1, par4, this); } } private void func_150177_e(World p_150177_1_, int p_150177_2_, int p_150177_3_, int p_150177_4_) { this.func_150175_a(p_150177_1_, p_150177_2_, p_150177_3_, p_150177_4_, p_150177_2_, p_150177_3_, p_150177_4_); ArrayList arraylist = new ArrayList(this.field_150179_b); this.field_150179_b.clear(); for (int l = 0; l < arraylist.size(); ++l) { ChunkPosition chunkposition = (ChunkPosition)arraylist.get(l); p_150177_1_.notifyBlocksOfNeighborChange(chunkposition.chunkPosX, chunkposition.chunkPosY, chunkposition.chunkPosZ, this); } } private void func_150175_a(World p_150175_1_, int p_150175_2_, int p_150175_3_, int p_150175_4_, int p_150175_5_, int p_150175_6_, int p_150175_7_) { int k1 = p_150175_1_.getBlockMetadata(p_150175_2_, p_150175_3_, p_150175_4_); byte b0 = 0; int i3 = this.func_150178_a(p_150175_1_, p_150175_5_, p_150175_6_, p_150175_7_, b0); this.field_150181_a = false; int l1 = p_150175_1_.getStrongestIndirectPower(p_150175_2_, p_150175_3_, p_150175_4_); this.field_150181_a = true; if (l1 > 0 && l1 > i3 - 1) { i3 = l1; } int i2 = 0; for (int j2 = 0; j2 < 4; ++j2) { int k2 = p_150175_2_; int l2 = p_150175_4_; if (j2 == 0) { k2 = p_150175_2_ - 1; } if (j2 == 1) { ++k2; } if (j2 == 2) { l2 = p_150175_4_ - 1; } if (j2 == 3) { ++l2; } if (k2 != p_150175_5_ || l2 != p_150175_7_) { i2 = this.func_150178_a(p_150175_1_, k2, p_150175_3_, l2, i2); } if (p_150175_1_.getBlock(k2, p_150175_3_, l2).isNormalCube() && !p_150175_1_.getBlock(p_150175_2_, p_150175_3_ + 1, p_150175_4_).isNormalCube()) { if ((k2 != p_150175_5_ || l2 != p_150175_7_) && p_150175_3_ >= p_150175_6_) { i2 = this.func_150178_a(p_150175_1_, k2, p_150175_3_ + 1, l2, i2); } } else if (!p_150175_1_.getBlock(k2, p_150175_3_, l2).isNormalCube() && (k2 != p_150175_5_ || l2 != p_150175_7_) && p_150175_3_ <= p_150175_6_) { i2 = this.func_150178_a(p_150175_1_, k2, p_150175_3_ - 1, l2, i2); } } if (i2 > i3) { i3 = i2 - 1; } else if (i3 > 0) { --i3; } else { i3 = 0; } if (l1 > i3 - 1) { i3 = l1; } if (k1 != i3) { p_150175_1_.setBlockMetadataWithNotify(p_150175_2_, p_150175_3_, p_150175_4_, i3, 2); this.field_150179_b.add(new ChunkPosition(p_150175_2_, p_150175_3_, p_150175_4_)); this.field_150179_b.add(new ChunkPosition(p_150175_2_ - 1, p_150175_3_, p_150175_4_)); this.field_150179_b.add(new ChunkPosition(p_150175_2_ + 1, p_150175_3_, p_150175_4_)); this.field_150179_b.add(new ChunkPosition(p_150175_2_, p_150175_3_ - 1, p_150175_4_)); this.field_150179_b.add(new ChunkPosition(p_150175_2_, p_150175_3_ + 1, p_150175_4_)); this.field_150179_b.add(new ChunkPosition(p_150175_2_, p_150175_3_, p_150175_4_ - 1)); this.field_150179_b.add(new ChunkPosition(p_150175_2_, p_150175_3_, p_150175_4_ + 1)); } } private int func_150178_a(World p_150178_1_, int p_150178_2_, int p_150178_3_, int p_150178_4_, int p_150178_5_) { if (p_150178_1_.getBlock(p_150178_2_, p_150178_3_, p_150178_4_) != this) { return p_150178_5_; } else { int i1 = p_150178_1_.getBlockMetadata(p_150178_2_, p_150178_3_, p_150178_4_); return i1 > p_150178_5_ ? i1 : p_150178_5_; } } private void func_150172_m(World p_150172_1_, int p_150172_2_, int p_150172_3_, int p_150172_4_) { if (p_150172_1_.getBlock(p_150172_2_, p_150172_3_, p_150172_4_) == this) { p_150172_1_.notifyBlocksOfNeighborChange(p_150172_2_, p_150172_3_, p_150172_4_, this); p_150172_1_.notifyBlocksOfNeighborChange(p_150172_2_ - 1, p_150172_3_, p_150172_4_, this); p_150172_1_.notifyBlocksOfNeighborChange(p_150172_2_ + 1, p_150172_3_, p_150172_4_, this); p_150172_1_.notifyBlocksOfNeighborChange(p_150172_2_, p_150172_3_, p_150172_4_ - 1, this); p_150172_1_.notifyBlocksOfNeighborChange(p_150172_2_, p_150172_3_, p_150172_4_ + 1, this); p_150172_1_.notifyBlocksOfNeighborChange(p_150172_2_, p_150172_3_ - 1, p_150172_4_, this); p_150172_1_.notifyBlocksOfNeighborChange(p_150172_2_, p_150172_3_ + 1, p_150172_4_, this); } } /** * Called whenever the block is added into the world. Args: world, x, y, z */ public void onBlockAdded(World p_149726_1_, int p_149726_2_, int p_149726_3_, int p_149726_4_) { super.onBlockAdded(p_149726_1_, p_149726_2_, p_149726_3_, p_149726_4_); if (!p_149726_1_.isRemote) { this.func_150177_e(p_149726_1_, p_149726_2_, p_149726_3_, p_149726_4_); p_149726_1_.notifyBlocksOfNeighborChange(p_149726_2_, p_149726_3_ + 1, p_149726_4_, this); p_149726_1_.notifyBlocksOfNeighborChange(p_149726_2_, p_149726_3_ - 1, p_149726_4_, this); this.func_150172_m(p_149726_1_, p_149726_2_ - 1, p_149726_3_, p_149726_4_); this.func_150172_m(p_149726_1_, p_149726_2_ + 1, p_149726_3_, p_149726_4_); this.func_150172_m(p_149726_1_, p_149726_2_, p_149726_3_, p_149726_4_ - 1); this.func_150172_m(p_149726_1_, p_149726_2_, p_149726_3_, p_149726_4_ + 1); if (p_149726_1_.getBlock(p_149726_2_ - 1, p_149726_3_, p_149726_4_).isNormalCube()) { this.func_150172_m(p_149726_1_, p_149726_2_ - 1, p_149726_3_ + 1, p_149726_4_); } else { this.func_150172_m(p_149726_1_, p_149726_2_ - 1, p_149726_3_ - 1, p_149726_4_); } if (p_149726_1_.getBlock(p_149726_2_ + 1, p_149726_3_, p_149726_4_).isNormalCube()) { this.func_150172_m(p_149726_1_, p_149726_2_ + 1, p_149726_3_ + 1, p_149726_4_); } else { this.func_150172_m(p_149726_1_, p_149726_2_ + 1, p_149726_3_ - 1, p_149726_4_); } if (p_149726_1_.getBlock(p_149726_2_, p_149726_3_, p_149726_4_ - 1).isNormalCube()) { this.func_150172_m(p_149726_1_, p_149726_2_, p_149726_3_ + 1, p_149726_4_ - 1); } else { this.func_150172_m(p_149726_1_, p_149726_2_, p_149726_3_ - 1, p_149726_4_ - 1); } if (p_149726_1_.getBlock(p_149726_2_, p_149726_3_, p_149726_4_ + 1).isNormalCube()) { this.func_150172_m(p_149726_1_, p_149726_2_, p_149726_3_ + 1, p_149726_4_ + 1); } else { this.func_150172_m(p_149726_1_, p_149726_2_, p_149726_3_ - 1, p_149726_4_ + 1); } } } public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_) { super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_); if (!p_149749_1_.isRemote) { p_149749_1_.notifyBlocksOfNeighborChange(p_149749_2_, p_149749_3_ + 1, p_149749_4_, this); p_149749_1_.notifyBlocksOfNeighborChange(p_149749_2_, p_149749_3_ - 1, p_149749_4_, this); p_149749_1_.notifyBlocksOfNeighborChange(p_149749_2_ + 1, p_149749_3_, p_149749_4_, this); p_149749_1_.notifyBlocksOfNeighborChange(p_149749_2_ - 1, p_149749_3_, p_149749_4_, this); p_149749_1_.notifyBlocksOfNeighborChange(p_149749_2_, p_149749_3_, p_149749_4_ + 1, this); p_149749_1_.notifyBlocksOfNeighborChange(p_149749_2_, p_149749_3_, p_149749_4_ - 1, this); this.func_150177_e(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_); this.func_150172_m(p_149749_1_, p_149749_2_ - 1, p_149749_3_, p_149749_4_); this.func_150172_m(p_149749_1_, p_149749_2_ + 1, p_149749_3_, p_149749_4_); this.func_150172_m(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_ - 1); this.func_150172_m(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_ + 1); if (p_149749_1_.getBlock(p_149749_2_ - 1, p_149749_3_, p_149749_4_).isNormalCube()) { this.func_150172_m(p_149749_1_, p_149749_2_ - 1, p_149749_3_ + 1, p_149749_4_); } else { this.func_150172_m(p_149749_1_, p_149749_2_ - 1, p_149749_3_ - 1, p_149749_4_); } if (p_149749_1_.getBlock(p_149749_2_ + 1, p_149749_3_, p_149749_4_).isNormalCube()) { this.func_150172_m(p_149749_1_, p_149749_2_ + 1, p_149749_3_ + 1, p_149749_4_); } else { this.func_150172_m(p_149749_1_, p_149749_2_ + 1, p_149749_3_ - 1, p_149749_4_); } if (p_149749_1_.getBlock(p_149749_2_, p_149749_3_, p_149749_4_ - 1).isNormalCube()) { this.func_150172_m(p_149749_1_, p_149749_2_, p_149749_3_ + 1, p_149749_4_ - 1); } else { this.func_150172_m(p_149749_1_, p_149749_2_, p_149749_3_ - 1, p_149749_4_ - 1); } if (p_149749_1_.getBlock(p_149749_2_, p_149749_3_, p_149749_4_ + 1).isNormalCube()) { this.func_150172_m(p_149749_1_, p_149749_2_, p_149749_3_ + 1, p_149749_4_ + 1); } else { this.func_150172_m(p_149749_1_, p_149749_2_, p_149749_3_ - 1, p_149749_4_ + 1); } } } /** * Returns the current strength at the specified block if it is greater than the passed value, or the passed value * otherwise. Signature: (world, x, y, z, strength) */ private int getMaxCurrentStrength(World par1World, int par2, int par3, int par4, int par5) { if (par1World.getBlock(par2, par3, par4) != this) { return par5; } else { int i1 = par1World.getBlockMetadata(par2, par3, par4); return i1 > par5 ? i1 : par5; } } /** * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are * their own) Args: x, y, z, neighbor blockID */ public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, Block par5) { if (!par1World.isRemote) { boolean flag = this.canPlaceBlockAt(par1World, par2, par3, par4); if (flag) { } else { this.dropBlockAsItem(par1World, par2, par3, par4, 0, 0); par1World.setBlockToAir(par2, par3, par4); } super.onNeighborBlockChange(par1World, par2, par3, par4, par5); } } /** * Returns the ID of the items to drop on destruction. */ public Item getItemDropped(int par1, Random par2Random, int par3) { return Items.redstone; } /** * Can this block provide power. Only wire currently seems to have this change based on its state. */ public boolean canProvidePower() { return true; } /** * Returns true if redstone wire can connect to the specified block. Params: World, X, Y, Z, side (not a normal * notch-side, this can be 0, 1, 2, 3 or -1) */ public static boolean isPowerProviderOrWire(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) { Block block = par1IBlockAccess.getBlock(par2, par3, par4); if (block == Blocks.redstone_wire) { return true; } else if (!Blocks.unpowered_repeater.func_149907_e(block)) { return block.canConnectRedstone(par1IBlockAccess, par2, par3, par4, par5); } else { int i1 = par1IBlockAccess.getBlockMetadata(par2, par3, par4); return par5 == (i1 & 3) || par5 == Direction.rotateOpposite[i1 & 3]; } } @SideOnly(Side.CLIENT) /** * A randomly called display update to be able to add particles or other items for display */ public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random) { int l = par1World.getBlockMetadata(par2, par3, par4); if (l > 0) { double d0 = (double)par2 + 0.5D + ((double)par5Random.nextFloat() - 0.5D) * 0.2D; double d1 = (double)((float)par3 + 0.0625F); double d2 = (double)par4 + 0.5D + ((double)par5Random.nextFloat() - 0.5D) * 0.2D; float f = (float)l / 15.0F; float f1 = f * 0.6F + 0.4F; if (l == 0) { f1 = 0.0F; } float f2 = f * f * 0.7F - 0.5F; float f3 = f * f * 0.6F - 0.7F; if (f2 < 0.0F) { f2 = 0.0F; } if (f3 < 0.0F) { f3 = 0.0F; } par1World.spawnParticle("reddust", d0, d1, d2, (double)f1, (double)f2, (double)f3); } } /** * Returns true if the block coordinate passed can provide power, or is a redstone wire, or if its a repeater that * is powered. */ public static boolean isPoweredOrRepeater(IBlockAccess par0IBlockAccess, int par1, int par2, int par3, int par4) { if (isPowerProviderOrWire(par0IBlockAccess, par1, par2, par3, par4)) { return true; } else { Block i1 = par0IBlockAccess.getBlock(par1, par2, par3); if (i1 == Blocks.powered_repeater) { int j1 = par0IBlockAccess.getBlockMetadata(par1, par2, par3); return par4 == (j1 & 3); } else { return false; } } } @SideOnly(Side.CLIENT) /** * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative) */ public Item getItem(World par1World, int par2, int par3, int par4) { return Items.redstone; } @SideOnly(Side.CLIENT) /** * When this method is called, your block should register all the icons it needs with the given IconRegister. This * is the only chance you get to register icons. */ public void registerBlockIcons(IIconRegister par1IconRegister) { this.field_94413_c = par1IconRegister.registerIcon(this.getTextureName() + "_" + "cross"); this.field_94410_cO = par1IconRegister.registerIcon(this.getTextureName() + "_" + "line"); this.field_94411_cP = par1IconRegister.registerIcon(this.getTextureName() + "_" + "cross_overlay"); this.field_94412_cQ = par1IconRegister.registerIcon(this.getTextureName() + "_" + "line_overlay"); this.blockIcon = this.field_94413_c; } @SideOnly(Side.CLIENT) public static IIcon getRedstoneWireIcon(String par0Str) { return par0Str.equals("cross") ? mod_SecurityCraft.empedWire.field_94413_c : (par0Str.equals("line") ? mod_SecurityCraft.empedWire.field_94410_cO : (par0Str.equals("cross_overlay") ? mod_SecurityCraft.empedWire.field_94411_cP : (par0Str.equals("line_overlay") ? mod_SecurityCraft.empedWire.field_94412_cQ : null))); } public TileEntity createNewTileEntity(World world, int par2) { return new TileEntityEmpedWire(); } }