Java Code Examples for net.minecraft.world.World#isBlockIndirectlyGettingPowered()

The following examples show how to use net.minecraft.world.World#isBlockIndirectlyGettingPowered() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TileInfusionClaw.java    From Gadomancy with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void updateEntity() {
    World world = getWorldObj();

    if(!world.isRemote) {
        if(redstoneState == null) {
            redstoneState = world.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
        }

        if(cooldown > 0) {
            cooldown--;
            if(cooldown == (int)(7.5f*20)) {
                performClickBlock();
            }
        }

        if(count > 20) {
            count = 0;
            if(yCoord > 0) {
                //Comparator...
                world.notifyBlockChange(xCoord, yCoord, zCoord, getBlockType());
            }
        }
        count++;
    }
}
 
Example 2
Source File: TrackInstanceBase.java    From NEI-Integration with MIT License 6 votes vote down vote up
protected boolean testPowered(World world, int i, int j, int k, TrackSpec spec, boolean dir, int dist, int maxDist, int orientation) {
    // System.out.println("Testing Power at <" + i + ", " + j + ", " + k + ">");
    Block blockToTest = world.getBlock(i, j, k);
    Block blockTrack = getBlock();
    if (blockToTest == blockTrack) {
        int meta = world.getBlockMetadata(i, j, k);
        TileEntity tile = world.getTileEntity(i, j, k);
        if (tile instanceof ITrackTile) {
            ITrackInstance track = ((ITrackTile) tile).getTrackInstance();
            if (!(track instanceof ITrackPowered) || track.getTrackSpec() != spec)
                return false;
            if (orientation == 1 && (meta == 0 || meta == 4 || meta == 5))
                return false;
            if (orientation == 0 && (meta == 1 || meta == 2 || meta == 3))
                return false;
            if (((ITrackPowered) track).isPowered())
                if (world.isBlockIndirectlyGettingPowered(i, j, k) || world.isBlockIndirectlyGettingPowered(i, j + 1, k))
                    return true;
                else
                    return isConnectedRailPowered(world, i, j, k, spec, meta, dir, dist + 1, maxDist);
        }
    }
    return false;
}
 
Example 3
Source File: BlockElevatorCaller.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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
 */
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block){
    int oldMeta = world.getBlockMetadata(x, y, z);
    boolean wasPowered = oldMeta / 8 > 0;
    boolean isPowered = world.isBlockIndirectlyGettingPowered(x, y, z);
    if(!wasPowered && isPowered) {
        world.setBlockMetadataWithNotify(x, y, z, oldMeta + 8, 3);
        TileEntity te = world.getTileEntity(x, y, z);
        if(te instanceof TileEntityElevatorCaller) {
            setSurroundingElevators(world, x, y, z, ((TileEntityElevatorCaller)te).thisFloor);
        }
    } else if(wasPowered && !isPowered) {
        world.setBlockMetadataWithNotify(x, y, z, oldMeta - 8, 3);
    }
}
 
Example 4
Source File: BlockPneumaticDoor.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block){
    boolean powered = world.isBlockIndirectlyGettingPowered(x, y, z);
    if(!powered) {
        int meta = world.getBlockMetadata(x, y, z);
        if(meta < 6) {
            powered = world.isBlockIndirectlyGettingPowered(x, y + 1, z);
        } else {
            powered = world.isBlockIndirectlyGettingPowered(x, y - 1, z);
        }
    }
    TileEntityPneumaticDoorBase doorBase = getDoorBase(world, x, y, z);
    if(!world.isRemote && doorBase != null && doorBase.getPressure(ForgeDirection.UNKNOWN) >= PneumaticValues.MIN_PRESSURE_PNEUMATIC_DOOR) {
        if(powered != doorBase.wasPowered) {
            doorBase.wasPowered = powered;
            doorBase.setOpening(powered);
        }
    }
}
 
Example 5
Source File: BlockMEDropper.java    From ExtraCells1 with MIT License 6 votes vote down vote up
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int neighbourID)
{
	if (((TileEntityMEDropper) world.getBlockTileEntity(x, y, z)).todispense != null)
	{
		ItemStack request = ((TileEntityMEDropper) world.getBlockTileEntity(x, y, z)).todispense;
		if (!world.isRemote)
		{
			if ((world.isBlockIndirectlyGettingPowered(x, y, z) || world.isBlockIndirectlyGettingPowered(x, y + 1, z)) && unpowered)
			{
				if (((TileEntityMEDropper) world.getBlockTileEntity(x, y, z)).getGrid() != null)
				{
					IMEInventoryHandler cellArray = ((TileEntityMEDropper) world.getBlockTileEntity(x, y, z)).getGrid().getCellArray();
					if (cellArray != null && cellArray.extractItems(Util.createItemStack(request)) != null)
					{
						dispense(world, x, y, z, ((TileEntityMEDropper) world.getBlockTileEntity(x, y, z)).getItem().copy());
						unpowered = false;
					}
				}
			} else
			{
				unpowered = true;
			}
		}
	}
}
 
Example 6
Source File: BlockTrap.java    From Artifacts with MIT License 6 votes vote down vote up
/**
 * 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
 */
@Override
public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, Block block)
{
    boolean flag = par1World.isBlockIndirectlyGettingPowered(par2, par3, par4) || par1World.isBlockIndirectlyGettingPowered(par2, par3 + 1, par4);
    int i1 = par1World.getBlockMetadata(par2, par3, par4);
    boolean flag1 = (i1 & 8) != 0;

    if (flag && !flag1)
    {
        par1World.scheduleBlockUpdate(par2, par3, par4, this.instance, this.tickRate(par1World));
        par1World.setBlockMetadataWithNotify(par2, par3, par4, i1 | 8, 4);
    }
    else if (!flag && flag1)
    {
        par1World.setBlockMetadataWithNotify(par2, par3, par4, i1 & -9, 4);
    }
    else if(flag1) {
    	//System.out.println("Stuck on");
    }
}
 
Example 7
Source File: BlockCarvableLamp.java    From Chisel-2 with GNU General Public License v2.0 5 votes vote down vote up
public void checkPower(World world, int x, int y, int z) {
	if (world.isRemote)
		return;

	boolean isGettingPower = world.isBlockIndirectlyGettingPowered(x, y, z);
	int meta = world.getBlockMetadata(x, y, z);

	if (powered && !isGettingPower) {
		world.setBlock(x, y, z, blockUnpowered, meta, 2);
	} else if (!powered && isGettingPower) {
		world.setBlock(x, y, z, blockPowered, meta, 2);
	}
}
 
Example 8
Source File: BlockMarbleLamp.java    From Chisel with GNU General Public License v2.0 5 votes vote down vote up
public void checkPower(World world, int x, int y, int z)
{
    if(world.isRemote) return;

    boolean isGettingPower = world.isBlockIndirectlyGettingPowered(x, y, z);
    int meta = world.getBlockMetadata(x, y, z);

    if(powered && !isGettingPower)
    {
        world.setBlock(x, y, z, blockUnpowered, meta, 2);
    } else if(!powered && isGettingPower)
    {
        world.setBlock(x, y, z, blockPowered, meta, 2);
    }
}
 
Example 9
Source File: PneumaticCraftUtils.java    From PneumaticCraft with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Returns the redstone level at the given coordinate. Useful when triggering on analog levels. When for example a redstone torch is attached, normally getBlockPowerInput() would return 0.
 * @param world
 * @param x
 * @param y
 * @param z
 * @return
 */
public static int getRedstoneLevel(World world, int x, int y, int z){
    int analogLevel = world.getBlockPowerInput(x, y, z);
    if(analogLevel == 0) {
        if(world.isBlockIndirectlyGettingPowered(x, y, z)) return 15;
    }
    return analogLevel;
}