Java Code Examples for net.minecraft.block.Block#blocksList()

The following examples show how to use net.minecraft.block.Block#blocksList() . 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: HayCrook.java    From Ex-Aliquo with MIT License 6 votes vote down vote up
@Override
public boolean onBlockStartBreak(ItemStack item, int X, int Y, int Z, EntityPlayer player)
{
	World world = player.worldObj;
	int blockID = world.getBlockId(X,Y,Z);
	int meta = world.getBlockMetadata(X, Y, Z);
	boolean validTarget = false;
	
	Block block = Block.blocksList[blockID];
	
	if (block.isBlockReplaceable(null, 0, 0, 0))
	{
		block.dropBlockAsItem(world, X, Y, Z, meta, 2);
	}
	
	return true;
}
 
Example 2
Source File: MoCTools.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
public static boolean NearMaterialWithDistance(Entity entity, Double double1, Material mat)
{
    AxisAlignedBB axisalignedbb = entity.boundingBox.expand(double1.doubleValue(), double1.doubleValue(), double1.doubleValue());
    int i = MathHelper.floor_double(axisalignedbb.minX);
    int j = MathHelper.floor_double(axisalignedbb.maxX + 1.0D);
    int k = MathHelper.floor_double(axisalignedbb.minY);
    int l = MathHelper.floor_double(axisalignedbb.maxY + 1.0D);
    int i1 = MathHelper.floor_double(axisalignedbb.minZ);
    int j1 = MathHelper.floor_double(axisalignedbb.maxZ + 1.0D);
    for (int k1 = i; k1 < j; k1++)
    {
        for (int l1 = k; l1 < l; l1++)
        {
            for (int i2 = i1; i2 < j1; i2++)
            {
                int j2 = entity.worldObj.getBlockId(k1, l1, i2);
                if ((j2 != 0) && (Block.blocksList[j2].blockMaterial == mat)) { return true; }
            }

        }

    }

    return false;
}
 
Example 3
Source File: MoCTools.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
public boolean isInsideOfMaterial(Material material, Entity entity)
{
    double d = entity.posY + (double) entity.getEyeHeight();
    int i = MathHelper.floor_double(entity.posX);
    int j = MathHelper.floor_float(MathHelper.floor_double(d));
    int k = MathHelper.floor_double(entity.posZ);
    int l = entity.worldObj.getBlockId(i, j, k);
    if (l != 0 && Block.blocksList[l].blockMaterial == material)
    {
        float f = BlockFluid.getFluidHeightPercent(entity.worldObj.getBlockMetadata(i, j, k)) - 0.1111111F;
        float f1 = (float) (j + 1) - f;
        return d < (double) f1;
    }
    else
    {
        return false;
    }
}
 
Example 4
Source File: MoCEntityAnimal.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
private boolean getCanSpawnHereMoCBiome() 
{
	//System.out.println("checking MoC biome spawn settings");
	if (this.worldObj.checkNoEntityCollision(this.boundingBox) && this.worldObj.getCollidingBoundingBoxes(this, this.boundingBox).isEmpty() && !this.worldObj.isAnyLiquid(this.boundingBox))
	{
		int var1 = MathHelper.floor_double(this.posX);
		int var2 = MathHelper.floor_double(this.boundingBox.minY);
		int var3 = MathHelper.floor_double(this.posZ);

		if (var2 < 50) { return false; }

		int var4 = this.worldObj.getBlockId(var1, var2 - 1, var3);
		Block block = Block.blocksList[var4];

		if (var4 == MoCreatures.mocDirt.blockID || var4 == MoCreatures.mocGrass.blockID || (block != null && block.isLeaves(worldObj, var1, var2 - 1, var3))) { return true; }
	}

	return false;
}
 
Example 5
Source File: MoCEntityAnimal.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
public boolean getCanSpawnHereJungle()
{

	//System.out.println("checking jungle!");
	if (this.worldObj.checkNoEntityCollision(this.boundingBox) && this.worldObj.getCollidingBoundingBoxes(this, this.boundingBox).isEmpty() && !this.worldObj.isAnyLiquid(this.boundingBox))
	{
		int var1 = MathHelper.floor_double(this.posX);
		int var2 = MathHelper.floor_double(this.boundingBox.minY);
		int var3 = MathHelper.floor_double(this.posZ);

		if (var2 < 63) { return false; }

		int var4 = this.worldObj.getBlockId(var1, var2 - 1, var3);
		Block block = Block.blocksList[var4];

		if (var4 == Block.grass.blockID || var4 == Block.leaves.blockID || (block != null && block.isLeaves(worldObj, var1, var2 - 1, var3))) { return true; }
	}

	return false;
}
 
Example 6
Source File: MoCEntityThrowableRock.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
public Block getMyBLock()
{

    //Block block = Block.blocksList[this.getType()];
    if (this.getType() != 0)
    {
        //Block mytempBlock =  Block.blocksList[this.getType()];
        //mytempBlock.
        return Block.blocksList[this.getType()];
    }
    //System.out.println("returning null");
    return Block.blocksList[1];
    //Block rBlock = Block.dirt; 
    //return rBlock;

    //Block var11 = Block.blocksList[this.getBlockId(var8, var9, var10)];

}
 
Example 7
Source File: MoCEntityBird.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
public int[] ReturnNearestMaterialCoord(Entity entity, Material material, Double double1)
{
    AxisAlignedBB axisalignedbb = entity.boundingBox.expand(double1.doubleValue(), double1.doubleValue(), double1.doubleValue());
    int i = MathHelper.floor_double(axisalignedbb.minX);
    int j = MathHelper.floor_double(axisalignedbb.maxX + 1.0D);
    int k = MathHelper.floor_double(axisalignedbb.minY);
    int l = MathHelper.floor_double(axisalignedbb.maxY + 1.0D);
    int i1 = MathHelper.floor_double(axisalignedbb.minZ);
    int j1 = MathHelper.floor_double(axisalignedbb.maxZ + 1.0D);
    for (int k1 = i; k1 < j; k1++)
    {
        for (int l1 = k; l1 < l; l1++)
        {
            for (int i2 = i1; i2 < j1; i2++)
            {
                int j2 = worldObj.getBlockId(k1, l1, i2);
                if ((j2 != 0) && (Block.blocksList[j2].blockMaterial == material)) { return (new int[] { k1, l1, i2 }); }
            }

        }

    }

    return (new int[] { -1, 0, 0 });
}
 
Example 8
Source File: MoCEntityElephant.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void fall(float f)
{
    int i = (int) Math.ceil(f - 3F);
    if ((i > 0))
    {
        i /= 3;
        if (i > 0)
        {
            attackEntityFrom(DamageSource.fall, i);
        }
        if ((riddenByEntity != null) && (i > 0))
        {
            riddenByEntity.attackEntityFrom(DamageSource.fall, i);
        }

        int j = worldObj.getBlockId(MathHelper.floor_double(posX), MathHelper.floor_double(posY - 0.20000000298023221D - prevRotationPitch), MathHelper.floor_double(posZ));
        if (j > 0)
        {
            StepSound stepsound = Block.blocksList[j].stepSound;
            worldObj.playSoundAtEntity(this, stepsound.getStepSound(), stepsound.getVolume() * 0.5F, stepsound.getPitch() * 0.75F);
        }
    }
}
 
Example 9
Source File: MoCEntityBigCat.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
public boolean NearSnowWithDistance(Entity entity, Double double1)
{
    AxisAlignedBB axisalignedbb = entity.boundingBox.expand(double1.doubleValue(), double1.doubleValue(), double1.doubleValue());
    int i = MathHelper.floor_double(axisalignedbb.minX);
    int j = MathHelper.floor_double(axisalignedbb.maxX + 1.0D);
    int k = MathHelper.floor_double(axisalignedbb.minY);
    int l = MathHelper.floor_double(axisalignedbb.maxY + 1.0D);
    int i1 = MathHelper.floor_double(axisalignedbb.minZ);
    int j1 = MathHelper.floor_double(axisalignedbb.maxZ + 1.0D);
    for (int k1 = i; k1 < j; k1++)
    {
        for (int l1 = k; l1 < l; l1++)
        {
            for (int i2 = i1; i2 < j1; i2++)
            {
                int j2 = worldObj.getBlockId(k1, l1, i2);
                if ((j2 != 0) && (Block.blocksList[j2].blockMaterial == Material.snow)) { return true; }
            }

        }

    }

    return false;
}
 
Example 10
Source File: WorldGenWyvernGrass.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)
{
    int var11;

    Block block = null;
    do 
    {
        block = Block.blocksList[par1World.getBlockId(par3,  par4, par5)];
        if (block != null && !block.isLeaves(par1World, par3, par4, par5))
        {
            break;
        }
        par4--;
    } while (par4 > 0);

    for (int var7 = 0; var7 < 128; ++var7)
    {
        int var8 = par3 + par2Random.nextInt(8) - par2Random.nextInt(8);
        int var9 = par4 + par2Random.nextInt(4) - par2Random.nextInt(4);
        int var10 = par5 + par2Random.nextInt(8) - par2Random.nextInt(8);

        if (par1World.isAirBlock(var8, var9, var10) && Block.blocksList[this.tallGrassID].canBlockStay(par1World, var8, var9, var10))
        {
            par1World.setBlock(var8, var9, var10, this.tallGrassID, this.tallGrassMetadata, 3);
        }
    }

    return true;
}
 
Example 11
Source File: MoCEntityBird.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
private int[] FindTreeTop(int i, int j, int k)
{
    int l = i - 5;
    int i1 = k - 5;
    int j1 = i + 5;
    int k1 = j + 7;
    int l1 = k + 5;
    for (int i2 = l; i2 < j1; i2++)
    {
        label0: for (int j2 = i1; j2 < l1; j2++)
        {
            int k2 = worldObj.getBlockId(i2, j, j2);
            if ((k2 == 0) || (Block.blocksList[k2].blockMaterial != Material.wood))
            {
                continue;
            }
            int l2 = j;
            do
            {
                if (l2 >= k1)
                {
                    continue label0;
                }
                int i3 = worldObj.getBlockId(i2, l2, j2);
                if (i3 == 0) { return (new int[] { i2, l2 + 2, j2 }); }
                l2++;
            } while (true);
        }

    }

    return (new int[] { 0, 0, 0 });
}
 
Example 12
Source File: MoCEntityHorse.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
private boolean nearMusicBox()
{
    // only works server side
    if (!MoCreatures.isServer()) { return false; }

    boolean flag = false;
    TileEntityRecordPlayer jukebox = MoCTools.nearJukeBoxRecord(this, 6D);
    if (jukebox != null && jukebox.func_96097_a() != null)
    {
        int i = jukebox.func_96097_a().itemID;

        int j = MoCreatures.recordshuffle.itemID;
        if (i == j)
        {
            flag = true;
            if (shuffleCounter > 1000)
            {
                shuffleCounter = 0;
                MoCServerPacketHandler.sendStopShuffle(this.entityId, this.worldObj.provider.dimensionId);
                BlockJukeBox blockjukebox = (BlockJukeBox) Block.blocksList[worldObj.getBlockId(jukebox.xCoord, jukebox.yCoord, jukebox.zCoord)];// Block.blocksList[j2].blockID;
                if (blockjukebox != null)
                {
                    blockjukebox.ejectRecord(worldObj, jukebox.xCoord, jukebox.yCoord, jukebox.zCoord);
                }
                flag = false;
            }
        }
        else
        {
            // System.out.println("Client playing r# " + i);
        }
    }
    return flag;
}
 
Example 13
Source File: MoCEntityHorse.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void fall(float f)
{
    if (isFlyer() || isFloater()) { return; }

    int i = (int) Math.ceil(f - 3F);
    if ((i > 0)) // && (type != 8))
    {
        if (getType() >= 10)
        {
            i /= 3;
        }
        if (i > 0)
        {
            attackEntityFrom(DamageSource.fall, i);
        }
        if ((riddenByEntity != null) && (i > 0))
        {
            riddenByEntity.attackEntityFrom(DamageSource.fall, i);
        }

        int j = worldObj.getBlockId(MathHelper.floor_double(posX), MathHelper.floor_double(posY - 0.20000000298023221D - prevRotationPitch), MathHelper.floor_double(posZ));
        if (j > 0)
        {
            StepSound stepsound = Block.blocksList[j].stepSound;
            worldObj.playSoundAtEntity(this, stepsound.getStepSound(), stepsound.getVolume() * 0.5F, stepsound.getPitch() * 0.75F);
        }
    }
}
 
Example 14
Source File: TileEntityLevelEmitterFluid.java    From ExtraCells1 with MIT License 5 votes vote down vote up
public void updateRedstoneStates()
{
	for (ForgeDirection currentSide : ForgeDirection.values())
	{
		Block neighbor = Block.blocksList[worldObj.getBlockId(xCoord + currentSide.offsetX, yCoord + currentSide.offsetY, zCoord + currentSide.offsetZ)];
		if (neighbor != null)
			neighbor.onNeighborBlockChange(worldObj, xCoord + currentSide.offsetX, yCoord + currentSide.offsetY, zCoord + currentSide.offsetZ, BlockEnum.FLUIDLEVELEMITTER.getBlockInstance().blockID);
	}
	PacketDispatcher.sendPacketToAllPlayers(getDescriptionPacket());
	worldObj.updateAllLightTypes(xCoord, yCoord, zCoord);
}
 
Example 15
Source File: ModelCertusTank.java    From ExtraCells1 with MIT License 5 votes vote down vote up
public void renderFluid(TileEntity tileEntity, double x, double y, double z, RenderBlocks renderer)
{
	Tessellator tessellator = Tessellator.instance;
	tessellator.setColorOpaque(255, 255, 255);
	if (tileEntity != null && ((TileEntityCertusTank) tileEntity).getTankInfo(ForgeDirection.UNKNOWN)[0].fluid != null)
	{
		Fluid storedFluid = ((TileEntityCertusTank) tileEntity).getRenderFluid();
		float scale = ((TileEntityCertusTank) tileEntity).getRenderScale();
		if (storedFluid != null && scale > 0)
		{
			GL11.glEnable(GL11.GL_BLEND);
			GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
			Block id = Block.blocksList[FluidRegistry.WATER.getBlockID()];
			Icon fluidIcon = storedFluid.getIcon();
			if (fluidIcon == null)
				fluidIcon = FluidRegistry.LAVA.getIcon();
			renderer.setRenderBounds(0.08F, 0.001F, 0.08F, 0.92, scale * 0.999F, 0.92F);
			tessellator.setNormal(0.0F, -1F, 0.0F);
			renderer.renderFaceYNeg(id, x, y, z, fluidIcon);
			tessellator.setNormal(0.0F, 1.0F, 0.0F);
			renderer.renderFaceYPos(id, x, y, z, fluidIcon);
			tessellator.setNormal(0.0F, 0.0F, -1F);
			renderer.renderFaceZNeg(id, x, y, z, fluidIcon);
			tessellator.setNormal(0.0F, 0.0F, 1.0F);
			renderer.renderFaceZPos(id, x, y, z, fluidIcon);
			tessellator.setNormal(-1F, 0.0F, 0.0F);
			renderer.renderFaceXNeg(id, x, y, z, fluidIcon);
			tessellator.setNormal(1.0F, 0.0F, 0.0F);
			renderer.renderFaceXPos(id, x, y, z, fluidIcon);
		}
	}
}
 
Example 16
Source File: MoCEntityMob.java    From mocreaturesdev with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void moveEntityWithHeading(float f, float f1)
{
    if (!isFlyer())
    {
        super.moveEntityWithHeading(f, f1);
        return;
    }

    if (handleWaterMovement())
    {
        double d = posY;
        moveFlying(f, f1, 0.02F);
        moveEntity(motionX, motionY, motionZ);
        motionX *= 0.80000001192092896D;
        motionY *= 0.80000001192092896D;
        motionZ *= 0.80000001192092896D;
    }
    else if (handleLavaMovement())
    {
        double d1 = posY;
        moveFlying(f, f1, 0.02F);
        moveEntity(motionX, motionY, motionZ);
        motionX *= 0.5D;
        motionY *= 0.5D;
        motionZ *= 0.5D;
    }
    else
    {
        float f2 = 0.91F;
        if (onGround)
        {
            f2 = 0.5460001F;
            int i = worldObj.getBlockId(MathHelper.floor_double(posX), MathHelper.floor_double(boundingBox.minY) - 1, MathHelper.floor_double(posZ));
            if (i > 0)
            {
                f2 = Block.blocksList[i].slipperiness * 0.91F;
            }
        }
        float f3 = 0.162771F / (f2 * f2 * f2);
        moveFlying(f, f1, onGround ? 0.1F * f3 : 0.02F);
        f2 = 0.91F;
        if (onGround)
        {
            f2 = 0.5460001F;
            int j = worldObj.getBlockId(MathHelper.floor_double(posX), MathHelper.floor_double(boundingBox.minY) - 1, MathHelper.floor_double(posZ));
            if (j > 0)
            {
                f2 = Block.blocksList[j].slipperiness * 0.91F;
            }
        }
        moveEntity(motionX, motionY, motionZ);
        motionX *= f2;
        motionY *= f2;
        motionZ *= f2;
        if (isCollidedHorizontally)
        {
            motionY = 0.20000000000000001D;
        }
        if (entityToAttack != null && entityToAttack.posY < this.posY && rand.nextInt(30) == 0)
        {
            motionY = -0.25D;
        }
    }
    this.prevLimbYaw = this.limbYaw;
    double d2 = posX - prevPosX;
    double d3 = posZ - prevPosZ;
    float f4 = MathHelper.sqrt_double((d2 * d2) + (d3 * d3)) * 4.0F;
    if (f4 > 1.0F)
    {
        f4 = 1.0F;
    }

    this.limbYaw += (f4 - this.limbYaw) * 0.4F;
    this.limbSwing += this.limbYaw;
}
 
Example 17
Source File: MoCConfiguration.java    From mocreaturesdev with GNU General Public License v3.0 4 votes vote down vote up
private MoCProperty getBlockInternal(String category, String key, int defaultID, String comment, int lower, int upper)
{
    MoCProperty prop = get(category, key, -1, comment);

    if (prop.getInt() != -1)
    {
        configMarkers[prop.getInt()] = true;
        return prop;
    }
    else
    {
        if (defaultID < lower)
        {
            FMLLog.warning(
                "Mod attempted to get a block ID with a default in the Terrain Generation section, " +
                "mod authors should make sure there defaults are above 256 unless explicitly needed " +
                "for terrain generation. Most ores do not need to be below 256.");
            FMLLog.warning("Config \"%s\" Category: \"%s\" Key: \"%s\" Default: %d", fileName, category, key, defaultID);
            defaultID = upper - 1;
        }

        if (Block.blocksList[defaultID] == null && !configMarkers[defaultID])
        {
            prop.value = Integer.toString(defaultID);
            configMarkers[defaultID] = true;
            return prop;
        }
        else
        {
            for (int j = upper - 1; j > 0; j--)
            {
                if (Block.blocksList[j] == null && !configMarkers[j])
                {
                    prop.value = Integer.toString(j);
                    configMarkers[j] = true;
                    return prop;
                }
            }

            throw new RuntimeException("No more block ids available for " + key);
        }
    }
}
 
Example 18
Source File: ItemBuilderHammer.java    From mocreaturesdev with GNU General Public License v3.0 4 votes vote down vote up
/**
* Called whenever this item is equipped and the right mouse button is
* pressed. Args: itemStack, world, entityPlayer
*/
  @Override
  public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer entityplayer)
  {
  	double coordY = entityplayer.posY + (double)entityplayer.getEyeHeight();
  	double coordZ = entityplayer.posZ;
  	double coordX = entityplayer.posX;
  	int wallBlockID = 0;
  	int newWallBlockID = 0;
  	
  	for (int x = 3; x < 128; x++)
  	{



  		double newPosY = coordY - Math.cos( (entityplayer.rotationPitch- 90F) / 57.29578F) * x;
  		double newPosX = coordX + Math.cos((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * x );
  		double newPosZ = coordZ + Math.sin((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * x );
  		newWallBlockID = entityplayer.worldObj.getBlockId( MathHelper.floor_double(newPosX),  MathHelper.floor_double(newPosY),  MathHelper.floor_double(newPosZ)); 
  		
  		if (newWallBlockID == 0)
  		{
  			wallBlockID = newWallBlockID;
  			continue;
   		}
 
  		if (newWallBlockID != 0 && wallBlockID == 0)
  		{

  			newPosY = coordY - Math.cos( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1);
  			newPosX = coordX + Math.cos((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1) );
  			newPosZ = coordZ + Math.sin((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1) );
  			if (entityplayer.worldObj.getBlockId(MathHelper.floor_double(newPosX), MathHelper.floor_double(newPosY), MathHelper.floor_double(newPosZ)) != 0)  
  			{
  				//System.out.println("busy spot!");
  				return par1ItemStack;
  			}
      		
  			int blockInfo[] = obtainBlockAndMetadataFromBelt(entityplayer, true);
  			if (blockInfo[0] != 0)
  			{
  				if (MoCreatures.isServer())
  				{
  					entityplayer.worldObj.setBlock(MathHelper.floor_double(newPosX),  MathHelper.floor_double(newPosY),  MathHelper.floor_double(newPosZ), blockInfo[0], blockInfo[1], 3);
  					Block block = Block.blocksList[blockInfo[0]];
  					entityplayer.worldObj.playSoundEffect((double)((float)newPosX + 0.5F), (double)((float)newPosY + 0.5F), (double)((float)newPosZ + 0.5F), block.stepSound.getPlaceSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
  				}
  				MoCreatures.proxy.hammerFX(entityplayer);
  				entityplayer.setItemInUse(par1ItemStack, 200);
  			}
  			return par1ItemStack;
  		}
  	}
  	return par1ItemStack;
  }
 
Example 19
Source File: ItemOgreHammer.java    From mocreaturesdev with GNU General Public License v3.0 4 votes vote down vote up
/**
* Called whenever this item is equipped and the right mouse button is
* pressed. Args: itemStack, world, entityPlayer
*/
  @Override
  public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer entityplayer)
  {
  	double coordY = entityplayer.posY + (double)entityplayer.getEyeHeight();
  	double coordZ = entityplayer.posZ;
  	double coordX = entityplayer.posX;
  	int wallBlockID = 0;
  	int newWallBlockID = 0;
  	
  	for (int x = 3; x < 128; x++)
  	{



  		double newPosY = coordY - Math.cos( (entityplayer.rotationPitch- 90F) / 57.29578F) * x;
  		double newPosX = coordX + Math.cos((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * x );
  		double newPosZ = coordZ + Math.sin((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * x );
  		newWallBlockID = entityplayer.worldObj.getBlockId( MathHelper.floor_double(newPosX),  MathHelper.floor_double(newPosY),  MathHelper.floor_double(newPosZ)); 
  		
  		if (newWallBlockID == 0)
  		{
  			wallBlockID = newWallBlockID;
  			continue;
   		}
 
  		if (newWallBlockID != 0 && wallBlockID == 0)
  		{

  			newPosY = coordY - Math.cos( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1);
  			newPosX = coordX + Math.cos((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1) );
  			newPosZ = coordZ + Math.sin((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1) );
  			if (entityplayer.worldObj.getBlockId(MathHelper.floor_double(newPosX), MathHelper.floor_double(newPosY), MathHelper.floor_double(newPosZ)) != 0)  
  			{
  				//System.out.println("busy spot!");
  				return par1ItemStack;
  			}
      		
  			int blockInfo[] = obtainBlockAndMetadataFromBelt(entityplayer, true);
  			if (blockInfo[0] != 0)
  			{
  				if (MoCreatures.isServer())
  				{
  					entityplayer.worldObj.setBlock(MathHelper.floor_double(newPosX),  MathHelper.floor_double(newPosY),  MathHelper.floor_double(newPosZ), blockInfo[0], blockInfo[1], 3);
  					Block block = Block.blocksList[blockInfo[0]];
  					entityplayer.worldObj.playSoundEffect((double)((float)newPosX + 0.5F), (double)((float)newPosY + 0.5F), (double)((float)newPosZ + 0.5F), block.stepSound.getPlaceSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
  				}
  				MoCreatures.proxy.hammerFX(entityplayer);
  				entityplayer.setItemInUse(par1ItemStack, 200);
  			}
  			return par1ItemStack;
  		}
  	}
  	return par1ItemStack;
  }
 
Example 20
Source File: MoCTools.java    From mocreaturesdev with GNU General Public License v3.0 4 votes vote down vote up
public static int[] ReturnNearestMaterialCoord(Entity entity, Material material, Double double1, Double yOff)
{
    double shortestDistance = -1D;
    double distance = 0D;
    int x = -9999;
    int y = -1;
    int z = -1;

    AxisAlignedBB axisalignedbb = entity.boundingBox.expand(double1.doubleValue(), yOff.doubleValue(), double1.doubleValue());
    int i = MathHelper.floor_double(axisalignedbb.minX);
    int j = MathHelper.floor_double(axisalignedbb.maxX + 1.0D);
    int k = MathHelper.floor_double(axisalignedbb.minY);
    int l = MathHelper.floor_double(axisalignedbb.maxY + 1.0D);
    int i1 = MathHelper.floor_double(axisalignedbb.minZ);
    int j1 = MathHelper.floor_double(axisalignedbb.maxZ + 1.0D);
    for (int k1 = i; k1 < j; k1++)
    {
        for (int l1 = k; l1 < l; l1++)
        {
            for (int i2 = i1; i2 < j1; i2++)
            {
                int j2 = entity.worldObj.getBlockId(k1, l1, i2);
                if ((j2 != 0) && (Block.blocksList[j2].blockMaterial == material))
                {

                    distance = getSqDistanceTo(entity, k1, l1, i2);
                    if (shortestDistance == -1D)
                    {
                        x = k1;
                        y = l1;
                        z = i2;
                        shortestDistance = distance;
                    }

                    if (distance < shortestDistance)
                    {

                        x = k1;
                        y = l1;
                        z = i2;
                        shortestDistance = distance;
                    }

                }
            }

        }

    }

    if (entity.posX > x)
    {
        x -= 2;
    }
    else
    {
        x += 2;
    }
    if (entity.posZ > z)
    {
        z -= 2;
    }
    else
    {
        z += 2;
    }
    return (new int[] { x, y, z });
}