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

The following examples show how to use net.minecraft.world.World#getBiomeGenForCoords() . 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: ItemSoilKit.java    From GardenCollection with MIT License 6 votes vote down vote up
@Override
public boolean onItemUse (ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    if (player.inventory.getFirstEmptyStack() == -1 && player.inventory.getCurrentItem().stackSize > 1)
        return false;

    BiomeGenBase biome = world.getBiomeGenForCoords(x, z);
    int temperature = (int)(Math.min(1, Math.max(0, biome.temperature)) * 255) & 255;
    int rainfall = (int)(Math.min(1, Math.max(0, biome.rainfall)) * 255) & 255;

    ItemStack usedKit = new ItemStack(ModItems.usedSoilTestKit, 1, rainfall << 8 | temperature);

    world.playSoundAtEntity(player, "step.grass", 1.0f, 1.0f);

    if (player.inventory.getCurrentItem().stackSize == 1)
        player.inventory.setInventorySlotContents(player.inventory.currentItem, usedKit);
    else {
        stack.stackSize--;
        player.inventory.setInventorySlotContents(player.inventory.getFirstEmptyStack(), usedKit);
    }

    return true;
}
 
Example 2
Source File: CustomSpawner.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a list of creatures of the specified type (mob/aquatic/animal)
 * that can spawn at the given XYZ location, based on biomes.
 */
public List getPossibleCustomCreatures(World worldObj, EnumCreatureType enumcreaturetype, int pX, int pY, int pZ)
{
    BiomeGenBase biomegenbase = worldObj.getBiomeGenForCoords(pX, pZ);
    if (biomegenbase == null)
    {
        //System.out.println("null biome");
        return null;
    }
    else
    {
        return getCustomBiomeSpawnList(getCustomSpawnableList(enumcreaturetype), biomegenbase);
    }
}
 
Example 3
Source File: BlockSurgeryTable.java    From Cyberware with MIT License 4 votes vote down vote up
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
{
	if (worldIn.isRemote)
	{
		return true;
	}
	else
	{
		if (state.getValue(PART) != BlockBed.EnumPartType.HEAD)
		{
			pos = pos.offset((EnumFacing)state.getValue(FACING));
			state = worldIn.getBlockState(pos);

			if (state.getBlock() != this)
			{
				return true;
			}
		}

		if (worldIn.provider.canRespawnHere() && worldIn.getBiomeGenForCoords(pos) != Biomes.HELL)
		{
			if (((Boolean)state.getValue(OCCUPIED)).booleanValue())
			{
				EntityPlayer entityplayer = this.getPlayerInBed(worldIn, pos);

				if (entityplayer != null)
				{
					playerIn.addChatComponentMessage(new TextComponentTranslation("tile.bed.occupied", new Object[0]));
					return true;
				}

				state = state.withProperty(OCCUPIED, Boolean.valueOf(false));
				worldIn.setBlockState(pos, state, 4);
			}

			EntityPlayer.SleepResult entityplayer$sleepresult = playerIn.trySleep(pos);

			if (entityplayer$sleepresult == EntityPlayer.SleepResult.OK)
			{
				state = state.withProperty(OCCUPIED, Boolean.valueOf(true));
				worldIn.setBlockState(pos, state, 4);
				return true;
			}
			else
			{
				if (entityplayer$sleepresult == EntityPlayer.SleepResult.NOT_POSSIBLE_NOW)
				{
					playerIn.addChatComponentMessage(new TextComponentTranslation("tile.bed.noSleep", new Object[0]));
				}
				else if (entityplayer$sleepresult == EntityPlayer.SleepResult.NOT_SAFE)
				{
					playerIn.addChatComponentMessage(new TextComponentTranslation("tile.bed.notSafe", new Object[0]));
				}

				return true;
			}
		}
		else
		{
			worldIn.setBlockToAir(pos);
			BlockPos blockpos = pos.offset(((EnumFacing)state.getValue(FACING)).getOpposite());

			if (worldIn.getBlockState(blockpos).getBlock() == this)
			{
				worldIn.setBlockToAir(blockpos);
			}

			worldIn.newExplosion((Entity)null, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, 5.0F, true, true);
			return true;
		}
	}
}
 
Example 4
Source File: NH_QuarryPopulator.java    From NewHorizonsCoreMod with GNU General Public License v3.0 4 votes vote down vote up
private boolean canGen(World world, Random rand, int x, int z) {
    BiomeGenBase biome = world.getBiomeGenForCoords(x, z);
    return BiomeDictionary.isBiomeOfType(biome, BiomeDictionary.Type.FOREST) && BiomeDictionary.isBiomeOfType(biome, BiomeDictionary.Type.SNOWY) && rand.nextDouble() <= 0.03D;
}
 
Example 5
Source File: OilGeneratorFix.java    From NewHorizonsCoreMod with GNU General Public License v3.0 4 votes vote down vote up
private boolean shouldSpawnOil( World pWorld, Random pRand, int pX, int pZ, Vec3 pPos )
{
  // Limited to Whitelisted Dimensions
  if( !MainRegistry.CoreConfig.OilFixConfig.OilDimensionWhitelist.contains( pWorld.provider.dimensionId ) )
  {
    if( YAMCore.isDebug() ) {
        _mLog.info(String.format("Not generating OilDeposit; Dimension is not Whitelisted %d", pWorld.provider.dimensionId));
    }
    return false;
  }

  BiomeGenBase biomegenbase = pWorld.getBiomeGenForCoords( pX + 8, pZ + 8 );

  // Skip blacklisted DimensionIDs
  if( MainRegistry.CoreConfig.OilFixConfig.OilBiomeIDBlackList.contains( biomegenbase.biomeID ) )
  {
    if( YAMCore.isDebug() ) {
        _mLog.info(String.format("Not generating OilDeposit; BiomeID %d is Blacklisted", biomegenbase.biomeID));
    }
    return false;
  }

  pRand.setSeed( pWorld.getSeed() );
  long i1 = pRand.nextInt() / 2L * 2L + 1L;
  long j1 = pRand.nextInt() / 2L * 2L + 1L;
  pRand.setSeed( pX * i1 + pZ * j1 ^ pWorld.getSeed() );

  double randMod = Math.min( 0.2D, 0.0001D * MainRegistry.CoreConfig.OilFixConfig.OilSphereChance );

  if( biomegenbase.rootHeight >= 0.45F )
  {
    randMod /= 2.0D;
  }
  if( biomegenbase.rootHeight < -0.5F )
  {
    randMod *= 1.8D;
  }

  if( MainRegistry.CoreConfig.OilFixConfig.OilBoostBiomes.contains( biomegenbase.biomeID ) ) {
      randMod *= MainRegistry.CoreConfig.OilFixConfig.OilBiomeBoostFactor;
  }

  boolean flag1 = pRand.nextDouble() <= randMod;
  boolean flag2 = pRand.nextDouble() <= randMod;

  if( flag1 || flag2)
  {
    pPos.yCoord = 17 + pRand.nextInt( 10 ) + pRand.nextInt( 5 );
    pPos.xCoord = pX + pRand.nextInt( 16 );
    pPos.zCoord = pZ + pRand.nextInt( 16 );
    return true;
  }
  return false;
}
 
Example 6
Source File: AllPurposeDebugCommand.java    From NewHorizonsCoreMod with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void processCommand( ICommandSender pCmdSender, String[] pArgs )
{
  try
  {
    if( pArgs.length == 0 )
    {
      moarArgs( pCmdSender );
      return;
    }
    else if("ci".equalsIgnoreCase(pArgs[0]))
    {
      EntityPlayer tEP = (EntityPlayer) pCmdSender;
      World tWorldObj = tEP.worldObj;
      int x = (int) tEP.posX;
      int z = (int) tEP.posZ;
      BiomeGenBase tBiomeInfo = tWorldObj.getBiomeGenForCoords( x, z );

      PlayerChatHelper.SendInfo( pCmdSender, "POS: x/z %d / %d", x, z );
      PlayerChatHelper.SendInfo( pCmdSender, "DimID: %d", tWorldObj.provider.dimensionId );
      PlayerChatHelper.SendInfo( pCmdSender, "BiomeID / Name: %d / %s", tBiomeInfo.biomeID, tBiomeInfo.biomeName );
    }
    else if("reloadconfig".equalsIgnoreCase(pArgs[0]))
    {
      MainRegistry.CoreConfig.LoadConfig();
      PlayerChatHelper.SendInfo( pCmdSender, "Config reloaded" );
    }
    else if("test".equalsIgnoreCase(pArgs[0]))
    {
      if( pArgs.length == 2 )
      {
        PlayerChatHelper.SendInfo( pCmdSender, "LOC: %d %d %d", (int) ( (EntityPlayer) pCmdSender ).posX, (int) ( (EntityPlayer) pCmdSender ).posY, (int) ( (EntityPlayer) pCmdSender ).posZ );

        Vec3 calculatedPos = PlayerHelper.addDistanceByPlayerDirection( (EntityPlayer) pCmdSender, Integer.parseInt( pArgs[1] ) );

        PlayerChatHelper.SendInfo( pCmdSender, "Calculated Block: %d %d %d", (int) calculatedPos.xCoord, (int) calculatedPos.yCoord, (int) calculatedPos.zCoord );
        pCmdSender.getEntityWorld().setBlock( (int) calculatedPos.xCoord, (int) calculatedPos.yCoord, (int) calculatedPos.zCoord, Blocks.bedrock );
      }
      else {
          moarArgs(pCmdSender);
      }
    }
    else if("oilstruct".equalsIgnoreCase(pArgs[0]))
    {
      IModFix tModFix = ModFixesMaster.getModFixInstance( OilGeneratorFix.ModFixName );
      if( tModFix == null )
      {
        PlayerChatHelper.SendError( pCmdSender, "Required ModFix is not loaded" );
        return;
      }

      OilGeneratorFix tOilGenFix = (OilGeneratorFix) tModFix;

      if( pArgs.length == 5 )
      {
        String[] tBlock = pArgs[1].split( ":" );

        Vec3 tSourcePos = Vec3.createVectorHelper( ( (EntityPlayer) pCmdSender ).posX, (double) Integer.parseInt( pArgs[2] ), ( (EntityPlayer) pCmdSender ).posZ );
        // Offset Structure-gen by 50 Blocks from players current location
        Vec3 tOilStructPos = PlayerHelper.addDistanceByVecAndYaw( tSourcePos, ( (EntityPlayer) pCmdSender ).rotationYaw, 50 );

        int tStructRadius = Integer.parseInt( pArgs[3] );
        int tStructGroundLevel = Integer.parseInt( pArgs[4] );

        Block tTargetBlock = GameRegistry.findBlock( tBlock[0], tBlock[1] );
        if( tTargetBlock != null )
        {
          PlayerChatHelper.SendInfo( pCmdSender, "Creating oilStruct at location %d / %d / %d, radius [%d], virtual groundLevel [%d] with block [%s]", (int) tOilStructPos.xCoord, (int) tOilStructPos.yCoord, (int) tOilStructPos.zCoord, tStructRadius, tStructGroundLevel, pArgs[1] );
          tOilGenFix.buildOilStructure( ( (EntityPlayer) pCmdSender ).worldObj, new Random(), (int) tOilStructPos.xCoord, (int) tOilStructPos.yCoord, (int) tOilStructPos.zCoord, tStructRadius, tStructGroundLevel, tTargetBlock, false );
        }
        else {
            PlayerChatHelper.SendError(pCmdSender, "Unknown block [%s]", pArgs[1]);
        }
      }
      else
      {
        moarArgs( pCmdSender );
        return;
      }
    }
  }
  catch( Exception e )
  {
    e.printStackTrace();
    PlayerChatHelper.SendError( pCmdSender, "Unknown error occoured [%s]", e.getMessage() );
  }
}
 
Example 7
Source File: WorldOverlayRenderer.java    From NotEnoughItems with MIT License 4 votes vote down vote up
private static void renderMobSpawnOverlay(Entity entity) {
    if (mobOverlay == 0)
        return;

    GlStateManager.disableTexture2D();
    GlStateManager.disableLighting();
    glLineWidth(1.5F);
    glBegin(GL_LINES);

    GlStateManager.color(1, 0, 0);

    World world = entity.worldObj;
    int x1 = (int) entity.posX;
    int z1 = (int) entity.posZ;
    int y1 = (int) MathHelper.clip(entity.posY, 16, world.getHeight() - 16);

    for (int x = x1 - 16; x <= x1 + 16; x++)
        for (int z = z1 - 16; z <= z1 + 16; z++) {
            BlockPos pos = new BlockPos(x, y1, z);
            Chunk chunk = world.getChunkFromBlockCoords(pos);
            BiomeGenBase biome = world.getBiomeGenForCoords(pos);
            if (biome.getSpawnableList(EnumCreatureType.MONSTER).isEmpty() || biome.getSpawningChance() <= 0)
                continue;

            for (int y = y1 - 16; y < y1 + 16; y++) {
                int spawnMode = getSpawnMode(chunk, x, y, z);
                if (spawnMode == 0)
                    continue;

                if (spawnMode == 1)
                    GlStateManager.color(1, 1, 0);
                else
                    GlStateManager.color(1, 0, 0);

                glVertex3d(x, y + 0.004, z);
                glVertex3d(x + 1, y + 0.004, z + 1);
                glVertex3d(x + 1, y + 0.004, z);
                glVertex3d(x, y + 0.004, z + 1);
            }
        }

    glEnd();
    GlStateManager.enableLighting();
    GlStateManager.enableTexture2D();
}