Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mod_Tutorial.commom;
- import java.util.Random;
- import net.minecraft.src.Block;
- import net.minecraft.src.IBlockAccess;
- import net.minecraft.src.Material;
- import net.minecraft.src.World;
- public class PhotonicGenerator extends GenericBlock
- {
- public boolean solar;
- public PhotonicGenerator(int id, int texture, Material material)
- {
- super(id, texture, material);
- solar = false;
- setHardness(1F);
- setTickRandomly(true);
- setStepSound(Block.soundMetalFootstep);
- setBlockName("Photonic Generator");
- }
- /**
- * Grabs the current texture file used for this block
- */
- public String getTextureFile()
- {
- return mod_Tutorial.CUSTOM_TEXTURES + "photonic_generator.png";
- }
- /**
- * Returns the block texture based on the side being looked at. Args: side
- */
- public int getBlockTextureFromSide(int i)
- {
- /*
- * 0 = bottom
- * 1 = top
- * 2 = east
- * 3 = west
- * 4 = north
- * 5 = south
- */
- switch(i)
- {
- case 0:
- return 0;
- case 1:
- return 1;
- case 2:
- return 2;
- case 3:
- return 3;
- case 4:
- return 4;
- case 5:
- return 5;
- default:
- return 0;
- }
- }
- public int tickRate()
- {
- //how often does the system check for update
- return 120;
- }
- //this is required for the block when it is added to the world
- //i j k are x y z coordinates
- public void onBlockAdded(World world, int i, int j, int k)
- {
- if(world.getBlockMetadata(i, j, k) == 0)
- {
- super.onBlockAdded(world, i, j, k);
- }
- //check to see if its getting light, this is custom for our block
- if (solar)
- {
- notifyNeighbors(world, i, j, k);
- }
- //this sets up the block to be updated in the world based on the tick rate
- world.scheduleBlockUpdate(i, j, k, blockID, tickRate());
- }
- /**
- * Can this block provide power. Only wire currently seems to have this change based on its state.
- */
- public boolean canProvidePower()
- {
- return solar;
- }
- /**
- * Is this block indirectly powering the block on the specified side
- */
- public boolean isIndirectlyPoweringTo(World world, int i, int j, int k, int l)
- {
- //return isPoweringTo(world, i, j, k, l);
- return l == 0 ? this.isPoweringTo(world, i, j, k, l) : false;
- }
- /**
- * Returns true or false based on whether the block the torch is attached to is providing indirect power.
- */
- private boolean isIndirectlyPowered(World par1World, int par2, int par3, int par4)
- {
- int var5 = par1World.getBlockMetadata(par2, par3, par4);
- return var5 == 5 && par1World.isBlockIndirectlyProvidingPowerTo(par2, par3 - 1, par4, 0) ? true : (var5 == 3 && par1World.isBlockIndirectlyProvidingPowerTo(par2, par3, par4 - 1, 2) ? true : (var5 == 4 && par1World.isBlockIndirectlyProvidingPowerTo(par2, par3, par4 + 1, 3) ? true : (var5 == 1 && par1World.isBlockIndirectlyProvidingPowerTo(par2 - 1, par3, par4, 4) ? true : var5 == 2 && par1World.isBlockIndirectlyProvidingPowerTo(par2 + 1, par3, par4, 5))));
- }
- /**
- * Is this block powering the block on the specified side
- */
- public boolean isPoweringTo(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
- {
- if (!solar)
- {
- return false;
- }
- else
- {
- int var6 = par1IBlockAccess.getBlockMetadata(par2, par3, par4);
- return var6 == 5 && par5 == 1 ? false : (var6 == 3 && par5 == 3 ? false : (var6 == 4 && par5 == 2 ? false : (var6 == 1 && par5 == 5 ? false : var6 != 2 || par5 != 4)));
- }
- }
- /**
- * Called right before the block is destroyed by a player. Args: world, x, y, z, metaData
- */
- public void onBlockDestroyedByPlayer(World world, int i, int j, int k, int l)
- {
- notifyNeighbors(world, i, j, k);
- }
- //i j k are equal to x y z
- private void notifyNeighbors(World world, int i, int j, int k)
- {
- world.notifyBlocksOfNeighborChange(i, j + 1, k, this.blockID); //above
- world.notifyBlocksOfNeighborChange(i, j - 1, k, this.blockID); //below
- world.notifyBlocksOfNeighborChange(i - 1, j, k, this.blockID); //
- world.notifyBlocksOfNeighborChange(i + 1, j, k, this.blockID); //
- world.notifyBlocksOfNeighborChange(i, j, k - 1, this.blockID); //
- world.notifyBlocksOfNeighborChange(i, j, k + 1, this.blockID); //
- }
- /**
- * Ticks the block if it's been scheduled
- */
- public void updateTick(World world, int i, int j, int k, Random par5Random)
- {
- //check to see if the sun is up
- solar = super.isSolar(world, i, j, k, this.blockID);
- //tell the neighbors
- notifyNeighbors(world, i, j, k);
- //schedule another update
- world.scheduleBlockUpdate(i, j, k, this.blockID, tickRate());
- }
- /**
- * 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, int par5)
- {
- super.onNeighborBlockChange(par1World, par2, par3, par4, par5);
- par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate());
- }
- /**
- * 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 true;
- }
- /**
- * Determine if this block can make a redstone connection on the side provided,
- * Useful to control which sides are inputs and outputs for redstone wires.
- *
- * Side:
- * -1: UP
- * 0: NORTH
- * 1: EAST
- * 2: SOUTH
- * 3: WEST
- *
- * @param world The current world
- * @param x X Position
- * @param y Y Position
- * @param z Z Position
- * @param side The side that is trying to make the connection
- * @return True to make the connection
- */
- public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side)
- {
- return Block.blocksList[blockID].canProvidePower() && side != -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement