Java Code Examples for net.minecraft.util.MathHelper#floor_double()

The following examples show how to use net.minecraft.util.MathHelper#floor_double() . 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: ItemShieldFocus.java    From Electro-Magic-Tools with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onPlayerStoppedUsingFocus(ItemStack itemstack, World world, EntityPlayer player, int count) {
    int x = MathHelper.floor_double(player.posX);
    int y = MathHelper.floor_double(player.posY);
    int z = MathHelper.floor_double(player.posZ);

    // Player Level
    if ((player.worldObj.getBlock(x + 1, y, z) == IC2BlockRegistry.shield) && (player.worldObj.getBlock(x - 1, y, z) == IC2BlockRegistry.shield) && (player.worldObj.getBlock(x, y, z + 1) == IC2BlockRegistry.shield) && (player.worldObj.getBlock(x, y, z - 1) == IC2BlockRegistry.shield)) {
        player.worldObj.setBlockToAir(x + 1, y, z);
        player.worldObj.setBlockToAir(x - 1, y, z);
        player.worldObj.setBlockToAir(x, y, z + 1);
        player.worldObj.setBlockToAir(x, y, z - 1);
    }

    // Above the player
    if ((player.worldObj.getBlock(x + 1, y + 1, z) == IC2BlockRegistry.shield) && (player.worldObj.getBlock(x - 1, y + 1, z) == IC2BlockRegistry.shield) && (player.worldObj.getBlock(x, y + 1, z + 1) == IC2BlockRegistry.shield) && (player.worldObj.getBlock(x, y + 1, z - 1) == IC2BlockRegistry.shield)) {
        player.worldObj.setBlockToAir(x + 1, y + 1, z);
        player.worldObj.setBlockToAir(x - 1, y + 1, z);
        player.worldObj.setBlockToAir(x, y + 1, z + 1);
        player.worldObj.setBlockToAir(x, y + 1, z - 1);
    }

    ItemStack milk = (new ItemStack(Items.milk_bucket));
    player.curePotionEffects(milk);
}
 
Example 2
Source File: Entity.java    From TickDynamic with MIT License 6 votes vote down vote up
@SideOnly(Side.CLIENT)
public int getBrightnessForRender(float p_70070_1_)
{
    int i = MathHelper.floor_double(this.posX);
    int j = MathHelper.floor_double(this.posZ);

    if (this.worldObj.blockExists(i, 0, j))
    {
        double d0 = (this.boundingBox.maxY - this.boundingBox.minY) * 0.66D;
        int k = MathHelper.floor_double(this.posY - (double)this.yOffset + d0);
        return this.worldObj.getLightBrightnessForSkyBlocks(i, k, j, 0);
    }
    else
    {
        return 0;
    }
}
 
Example 3
Source File: BlockSolderingStation.java    From ExtraCells1 with MIT License 6 votes vote down vote up
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemstack)
{
	int l = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;

	if (l == 0)
	{
		world.setBlockMetadataWithNotify(x, y, z, 2, 2);
	}

	if (l == 1)
	{
		world.setBlockMetadataWithNotify(x, y, z, 5, 2);
	}

	if (l == 2)
	{
		world.setBlockMetadataWithNotify(x, y, z, 3, 2);
	}

	if (l == 3)
	{
		world.setBlockMetadataWithNotify(x, y, z, 4, 2);
	}
}
 
Example 4
Source File: MoCEntityWWolf.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean checkSpawningBiome()
{
    if (MoCTools.isNearTorch(this)) { return false; }

    int i = MathHelper.floor_double(posX);
    int j = MathHelper.floor_double(boundingBox.minY);
    int k = MathHelper.floor_double(posZ);

    String s = MoCTools.BiomeName(worldObj, i, j, k);

    int l = rand.nextInt(10);

    if (s.equals("Taiga") || s.equals("Frozen Ocean") || s.equals("Frozen River") || s.equals("Ice Plains") || s.equals("Ice Mountains") || s.equals("TaigaHills"))
    {
        setType(3);
    }
    selectType();
    return true;
}
 
Example 5
Source File: MoCEntityHorse.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean checkSpawningBiome()
{
    int i = MathHelper.floor_double(posX);
    int j = MathHelper.floor_double(boundingBox.minY);
    int k = MathHelper.floor_double(posZ);

    String s = MoCTools.BiomeName(worldObj, i, j, k);

    if (s.equals("Plains"))
    {
        if (rand.nextInt(3) == 0)
        {
            setType(60);// zebra
        }
    }

    selectType();
    return true;
}
 
Example 6
Source File: MoCEntityAmbient.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 7
Source File: BlockQuantumLogic.java    From qcraft-mod with Apache License 2.0 5 votes vote down vote up
@Override
public void onBlockPlacedBy( World world, int x, int y, int z, EntityLivingBase player, ItemStack stack )
{
    int direction = ( ( MathHelper.floor_double( (double) ( player.rotationYaw * 4.0F / 360.0F ) + 0.5D ) & 3 ) + 2 ) % 4;
    int subType = stack.getItemDamage();
    setDirectionAndSubType( world, x, y, z, direction, subType );
}
 
Example 8
Source File: MoCEntityMob.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
protected void getPathOrWalkableBlock(Entity entity, float f)
{
    PathEntity pathentity = worldObj.getPathEntityToEntity(this, entity, 16F, true, false, false, true);
    if ((pathentity == null) && (f > 12F))
    {
        int i = MathHelper.floor_double(entity.posX) - 2;
        int j = MathHelper.floor_double(entity.posZ) - 2;
        int k = MathHelper.floor_double(entity.boundingBox.minY);
        for (int l = 0; l <= 4; l++)
        {
            for (int i1 = 0; i1 <= 4; i1++)
            {
                if (((l < 1) || (i1 < 1) || (l > 3) || (i1 > 3)) && worldObj.isBlockNormalCube(i + l, k - 1, j + i1) && !worldObj.isBlockNormalCube(i + l, k, j + i1) && !worldObj.isBlockNormalCube(i + l, k + 1, j + i1))
                {
                    setLocationAndAngles((i + l) + 0.5F, k, (j + i1) + 0.5F, rotationYaw, rotationPitch);
                    return;
                }
            }

        }

    }
    else
    {
        setPathToEntity(pathentity);
    }
}
 
Example 9
Source File: BlockEMT.java    From Electro-Magic-Tools with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemStack) {
    int facing = MathHelper.floor_double(entity.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
    TileEntityEMT tile = (TileEntityEMT) world.getTileEntity(x, y, z);
    if (facing == 0)
        tile.facing = 2;
    else if (facing == 1)
        tile.facing = 5;
    else if (facing == 2)
        tile.facing = 3;
    else if (facing == 3)
        tile.facing = 4;
}
 
Example 10
Source File: BlockStoneMachine.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase ent, ItemStack stack) {
    int metadata = world.getBlockMetadata(x, y, z);
    if (metadata == 2 || metadata == 4) {
        ((TileJarFillable) world.getTileEntity(x, y, z)).facing = MathHelper.floor_double(-ent.rotationYaw * 4.0F / 360.0F + 0.5D) & 0x3;
    }
}
 
Example 11
Source File: BlockCarvableStairs.java    From Chisel-2 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLiving, ItemStack par6ItemStack) {
	int meta = MathHelper.floor_double((par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

	// 0->2 2->3 3->0 1->1
	meta = meta == 0 ? 2 : meta == 2 ? 3 : meta == 3 ? 0 : 1;

	meta += par1World.getBlockMetadata(par2, par3, par4) % 8; // add upside-down-ness

	if (par6ItemStack.getItemDamage() >= 8) {
		meta += 8;
	}
	
	par1World.setBlockMetadataWithNotify(par2, par3, par4, meta, 2);
}
 
Example 12
Source File: HazardousItemsHandler.java    From NewHorizonsCoreMod with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Check if player actually swims in a fluid
 *
 * @param pPlayer
 */
private void CheckPlayerTouchesBlock( EntityPlayer pPlayer )
{
  if( _mRnd.nextInt( _mExecuteChance ) != 0 ) {
      return;
  }

  try
  {
    int blockX = MathHelper.floor_double( pPlayer.posX );
    int blockY = MathHelper.floor_double( pPlayer.boundingBox.minY );
    int blockZ = MathHelper.floor_double( pPlayer.posZ );
    Block pBlockContact = pPlayer.worldObj.getBlock( blockX, blockY, blockZ );
    Block pBlockUnderFeet = pPlayer.worldObj.getBlock( blockX, blockY - 1, blockZ );
    UniqueIdentifier tUidContact = GameRegistry.findUniqueIdentifierFor( pBlockContact );
    UniqueIdentifier tUidFeet = GameRegistry.findUniqueIdentifierFor( pBlockUnderFeet );

    // Skip air block and null results
    if( tUidContact != null && tUidContact.toString() != "minecraft:air" )
    {
      HazardousItems.HazardousFluid hf = _mHazardItemsCollection.FindHazardousFluidExact( tUidContact.toString() );
      if( hf != null && hf.getCheckContact() ) {
          DoHIEffects(hf, pPlayer);
      }
    }

    if( tUidFeet != null && tUidFeet.toString() != "minecraft:air" )
    {
      HazardousItems.HazardousItem hi = _mHazardItemsCollection.FindHazardousItemExact( tUidFeet.toString() );
      if( hi != null && hi.getCheckContact() ) {
          DoHIEffects(hi, pPlayer);
      }
    }
  }
  catch( Exception e )
  {
    _mLogger.error( "HazardousItemsHandler.CheckPlayerTouchesBlock.error", "Something bad happend while processing the onPlayerTick event" );
    e.printStackTrace();
  }
}
 
Example 13
Source File: BlockLightningPlant.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void executeFullGrownEffect(World world, int x, int y, int z, Random rand){
    if(!world.isRemote) {
        int j = MathHelper.floor_double(x) + rand.nextInt(20) - 10;
        int k = MathHelper.floor_double(z) + rand.nextInt(20) - 10;
        int l = world.getPrecipitationHeight(j, k);
        if(world.canLightningStrikeAt(j, l, k)) {
            EntityLightningBolt lightning = new EntityLightningBolt(world, j, l, k);
            world.addWeatherEffect(lightning);
            world.setBlockMetadataWithNotify(x, y, z, 11, 3);
        }
    }
}
 
Example 14
Source File: ComponentMusicPlayer.java    From Artifacts with MIT License 5 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world,	EntityPlayer player) {
	NBTTagCompound tag = itemStack.getTagCompound();
	String record = tag.getString("record");
	
	//Determine if the record should play.
	boolean shouldPlay = !tag.getBoolean("playing");
	
	int x = tag.getInteger("playingX");
	int y = tag.getInteger("playingY");
	int z = tag.getInteger("playingZ");
	
	if(shouldPlay) {
		x = MathHelper.floor_double(player.posX);
		y = MathHelper.floor_double(player.posY);
		z = MathHelper.floor_double(player.posZ);
	}
	
	//Send the packet to the server, to play the record (or stop playing).
	tag.setBoolean("playing", shouldPlay);
	
	PacketBuffer out = new PacketBuffer(Unpooled.buffer());
	out.writeInt(PacketHandlerServer.MUSIC_PLAYER);
	out.writeInt(x);
	out.writeInt(y);
	out.writeInt(z);
	out.writeBoolean(shouldPlay);
	out.writeInt(player.inventory.currentItem);
	if(shouldPlay) {
		out.writeInt(record.length());
		for(int i = 0; i < record.length(); i++) {
			out.writeChar(record.charAt(i));
		}
	}
	CToSMessage packet = new CToSMessage(out);
	DragonArtifacts.artifactNetworkWrapper.sendToServer(packet);
	
	tag.setInteger("onItemRightClickDelay", 10);
	return itemStack;
}
 
Example 15
Source File: BlockIC2Container.java    From Electro-Magic-Tools with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemStack) {
	int facing = MathHelper.floor_double(entity.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
	TileEntityEMT tile = (TileEntityEMT) world.getTileEntity(x, y, z);

	if (facing == 0)
		tile.facing = 2;
	else if (facing == 1)
		tile.facing = 5;
	else if (facing == 2)
		tile.facing = 3;
	else if (facing == 3)
		tile.facing = 4;
}
 
Example 16
Source File: BlockSnakestone.java    From Chisel with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack)
{
    int meta = world.getBlockMetadata(x, y, z);
    if(meta > 3) return;

    if(rotateHead(world, x, y, z) != -1)
        return;

    int rot = rotRemap[(MathHelper.floor_double(entity.rotationYaw * 4.0 / 360.0 + 0.5)) & 3];

    world.setBlockMetadataWithNotify(x, y, z, rot, 3);
}
 
Example 17
Source File: ItemShieldFocus.java    From Electro-Magic-Tools with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onUsingFocusTick(ItemStack itemstack, EntityPlayer player, int time) {
    player.motionX = 0.0D;
    player.motionY = 0.0D;
    player.motionZ = 0.0D;

    ItemWandCasting wand = (ItemWandCasting) itemstack.getItem();
    if (wand.consumeAllVis(itemstack, player, getVisCost(), true, true)) {
        int x = MathHelper.floor_double(player.posX);
        int y = MathHelper.floor_double(player.posY);
        int z = MathHelper.floor_double(player.posZ);

        // Player Level
        if (player.worldObj.isAirBlock(x + 1, y, z) && player.worldObj.isAirBlock(x - 1, y, z) && player.worldObj.isAirBlock(x, y, z + 1) && player.worldObj.isAirBlock(x, y, z - 1)) {
            player.worldObj.setBlock(x + 1, y, z, IC2BlockRegistry.shield);
            player.worldObj.setBlock(x - 1, y, z, IC2BlockRegistry.shield);
            player.worldObj.setBlock(x, y, z + 1, IC2BlockRegistry.shield);
            player.worldObj.setBlock(x, y, z - 1, IC2BlockRegistry.shield);
        }

        // Above the player
        if (player.worldObj.isAirBlock(x + 1, y + 1, z) && player.worldObj.isAirBlock(x - 1, y + 1, z) && player.worldObj.isAirBlock(x, y + 1, z + 1) && player.worldObj.isAirBlock(x, y + 1, z - 1)) {
            player.worldObj.setBlock(x + 1, y + 1, z, IC2BlockRegistry.shield);
            player.worldObj.setBlock(x - 1, y + 1, z, IC2BlockRegistry.shield);
            player.worldObj.setBlock(x, y + 1, z + 1, IC2BlockRegistry.shield);
            player.worldObj.setBlock(x, y + 1, z - 1, IC2BlockRegistry.shield);
        }
    }
}
 
Example 18
Source File: MoCEntityBird.java    From mocreaturesdev with GNU General Public License v3.0 4 votes vote down vote up
private boolean FlyToNextTree()
{
    int ai[] = ReturnNearestMaterialCoord(this, Material.leaves, Double.valueOf(20D));
    int ai1[] = FindTreeTop(ai[0], ai[1], ai[2]);
    if (ai1[1] != 0)
    {
        int i = ai1[0];
        int j = ai1[1];
        int k = ai1[2];
        faceLocation(i, j, k, 30F);
        if ((j - MathHelper.floor_double(posY)) > 2)
        {
            motionY += 0.14999999999999999D;
        }
        int l = 0;
        int i1 = 0;
        if (posX < i)
        {
            l = i - MathHelper.floor_double(posX);
            motionX += 0.050000000000000003D;
        }
        else
        {
            l = MathHelper.floor_double(posX) - i;
            motionX -= 0.050000000000000003D;
        }
        if (posZ < k)
        {
            i1 = k - MathHelper.floor_double(posZ);
            motionZ += 0.050000000000000003D;
        }
        else
        {
            i1 = MathHelper.floor_double(posX) - k;
            motionZ -= 0.050000000000000003D;
        }
        double d = l + i1;
        if (d < 3D) { return true; }
    }
    return false;
}
 
Example 19
Source File: EntityMinecartCommandBlockListener.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Return the position for this command sender.
 */
public ChunkCoordinates getPlayerCoordinates()
{
    return new ChunkCoordinates(MathHelper.floor_double(this.field_145768_a.posX), MathHelper.floor_double(this.field_145768_a.posY + 0.5D), MathHelper.floor_double(this.field_145768_a.posZ));
}
 
Example 20
Source File: MoCTools.java    From mocreaturesdev with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isNearBlockName(Entity entity, Double dist, String blockName)
{
    AxisAlignedBB axisalignedbb = entity.boundingBox.expand(dist, dist / 2D, dist);
    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);
                //int j2 = entity.worldObj.getBlockId(k1, l1, i2);

                /*if (j2 !=0) 
                {
                String nameToCheck = Block.blocksList[j2].getBlockName();
                if (nameToCheck.equals(blockName))
                {
                    return true;
                }
                //System.out.println(nameToCheck);
                }*/

                if (j2 != 0)// && (Block.blocksList[j2].getBlockName().equals(blockName)))
                {
                    String nameToCheck = "";
                    nameToCheck = Block.blocksList[j2].getUnlocalizedName();//.getBlockName();
                    if (nameToCheck != null && nameToCheck != "")
                    {
                        if (nameToCheck.equals(blockName)) { return true; }
                    }

                }

            }

        }

    }

    return false;
}