@Override public boolean generate(World worldIn, Random rand, BlockPos position) { BlockBush flower = ModBlocks.cloud_flower; for (int i = 0; i < 64; ++i) { BlockPos blockpos = position.add(rand.nextInt(8) - rand.nextInt(8), rand.nextInt(4) - rand.nextInt(4), rand.nextInt(8) - rand.nextInt(8)); if (worldIn.isAirBlock(blockpos) && (!worldIn.provider.isNether() || blockpos.getY() < 255) && flower.canBlockStay(worldIn, blockpos, flower.getDefaultState())) { worldIn.setBlockState(blockpos, flower.getDefaultState(), 2); } } return true; } }
@Override public void updateTick(@Nullable World world, @Nullable BlockPos pos, @Nullable IBlockState state, @Nullable Random random) { super.updateTick(world, pos, state, random); boolean shouldGrow = random.nextFloat() < GROWTH_CHANCE_PER_UPDATETICK; if (shouldGrow && !hasTop(state)) deltaGrowth(world, pos, state, 1); }
@Override public boolean canPlaceBlockAt(World worldIn, BlockPos pos) { return super.canPlaceBlockAt(worldIn, pos) && this.canBlockStay(worldIn, pos, this.getDefaultState()); }
@Override public void onLivingUpdate() { if (getEntityWorld().isRemote) Erebus.PROXY.spawnCustomParticle("spores", getEntityWorld(), posX + (rand.nextDouble() - 0.5D) * width, posY + rand.nextDouble() * height - 0.25D, posZ + (rand.nextDouble() - 0.5D) * width, 1.0D + rand.nextDouble(), 1.0D + rand.nextDouble(), 1.0D + rand.nextDouble()); if (!getEntityWorld().isRemote) { if (rand.nextInt(200) == 0) { if (getEntityWorld().isAirBlock(getPosition()) && getEntityWorld().getBiome(getPosition()) == ModBiomes.FUNGAL_FOREST && Blocks.BROWN_MUSHROOM.canPlaceBlockAt(getEntityWorld(), getPosition())) { int mush = rand.nextInt(3); if (mush == 0) getEntityWorld().setBlockState(getPosition(), Blocks.BROWN_MUSHROOM.getDefaultState()); if (mush == 1) getEntityWorld().setBlockState(getPosition(), Blocks.RED_MUSHROOM.getDefaultState()); else getEntityWorld().setBlockState(getPosition(), BiomeDecoratorFungalForest.MUSHROOMS[rand.nextInt(BiomeDecoratorFungalForest.MUSHROOMS.length)].getDefaultState(), 3); } } } super.onLivingUpdate(); }
public static void generateMushrooms(World worldIn, BlockPos blockpos, BlockPos origin, int radius, Random rand) { if (worldIn.getBlockState(blockpos.down()).isSideSolid(worldIn, blockpos.down(), EnumFacing.UP)) { worldIn.setBlockState(blockpos, rand.nextBoolean() ? Blocks.BROWN_MUSHROOM.getDefaultState() : Blocks.RED_MUSHROOM.getDefaultState()); } }
@Override public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) { return super.canBlockStay(worldIn, pos, state); }
@Override public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack) { super.harvestBlock(world, player, pos, state, te, stack); }
@Override public void fillFloor(World world, BlockPos pos, IBlockState state) { if(UndergroundBiomes.glowceliumEnabled) { world.setBlockState(pos, UndergroundBiomes.glowcelium.getDefaultState()); if(mushroomChance > 0 && world.rand.nextInt(mushroomChance) == 0) world.setBlockState(pos.up(), UndergroundBiomes.glowshroom.getDefaultState()); } else { super.fillFloor(world, pos, state); if(mushroomChance > 0 && world.rand.nextInt(mushroomChance) == 0) world.setBlockState(pos.up(), (world.rand.nextBoolean() ? Blocks.BROWN_MUSHROOM : Blocks.RED_MUSHROOM).getDefaultState()); } }
@Override public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) { return type == 3 ? this.canSustainBush(worldIn.getBlockState(pos.down())) : super.canBlockStay(worldIn, pos, state); }
/** * Spawns the block's drops in the world. By the time this is called the Block has possibly been set to air via Block.removedByPlayer * * @param worldIn the world in * @param player the player * @param pos the pos * @param state the state * @param te the te * @param stack the stack */ @Override public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack) { if (!worldIn.isRemote && stack.getItem() == Items.SHEARS) { player.addStat(StatList.getBlockStats(this)); spawnAsEntity(worldIn, pos, new ItemStack(ModBlocks.cloud_grass)); } else { super.harvestBlock(worldIn, player, pos, state, te, stack); } }
@Override public void updateTick(@Nonnull World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockState state, Random rand) { if (!worldIn.isRemote) { super.updateTick(worldIn, pos, state, rand); if (worldIn.getLightFromNeighbors(pos.up()) >= 9 && rand.nextInt(7) == 0) { this.grow(worldIn, pos, state, rand); } } }
@Override public boolean generate(World worldIn, Random rand, BlockPos position) { for (IBlockState iblockstate = worldIn.getBlockState(position); (iblockstate.getBlock().isAir(iblockstate, worldIn, position) || iblockstate.getBlock().isLeaves(iblockstate, worldIn, position)) && position.getY() > 0; iblockstate = worldIn.getBlockState(position)) { position = position.down(); } for (int i = 0; i < 128; ++i) { BlockPos blockPos = position.add(rand.nextInt(8) - rand.nextInt(8), rand.nextInt(4) - rand.nextInt(4), rand.nextInt(8) - rand.nextInt(8)); if (worldIn.isAirBlock(blockPos) && grassBlock.canBlockStay(worldIn, blockPos, grassBlock.getDefaultState())) { worldIn.setBlockState(blockPos, grassBlock.getDefaultState(), 2); } } return true; } }
@SubscribeEvent public void onItemExpireEvent(ItemExpireEvent event) { if (saplingDespawnGrow) { EntityItem entityItem = event.getEntityItem(); BlockPos pos = entityItem.getPosition(); Entity entity = event.getEntity(); ItemStack is = entityItem.getItem(); World world = entity.getEntityWorld(); if (is.isEmpty()) { return; } // plant the sapling, replacing the air and on top of dirt/plantable if (Block.getBlockFromItem(is.getItem()) == Blocks.RED_MUSHROOM) world.setBlockState(entityItem.getPosition(), Blocks.RED_MUSHROOM.getDefaultState()); else if (Block.getBlockFromItem(is.getItem()) == Blocks.BROWN_MUSHROOM) world.setBlockState(entityItem.getPosition(), Blocks.BROWN_MUSHROOM.getDefaultState()); else if (UtilOreDictionary.doesMatchOreDict(is, "treeSapling")) { Block saplingBlock = Block.getBlockFromItem(is.getItem()); if (saplingBlock != Blocks.AIR && saplingBlock.canPlaceBlockAt(world, pos)) { world.setBlockState(pos, UtilItemStack.getStateFromMeta(Block.getBlockFromItem(is.getItem()), is.getItemDamage())); } } } }
@Override public boolean canBlockStay(World world, BlockPos pos, IBlockState state) { if (state.getBlock() != this) return super.canBlockStay(world, pos, state); if (hasTop(state)) return world.getBlockState(pos.up()).getBlock() == this; if (isTop(state)) return world.getBlockState(pos.down()).getBlock() == this; return super.canBlockStay(world, pos, state); }
@Override public boolean canPlaceBlockAt(World worldIn, BlockPos pos) { IBlockState state = worldIn.getBlockState(pos.down()); return super.canPlaceBlockAt(worldIn, pos) && state.getBlock() == Blocks.WATER; }
@Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (!worldIn.isRemote) { super.updateTick(worldIn, pos, state, rand); if (worldIn.getLightFromNeighbors(pos.up()) >= 9 && rand.nextInt(7) == 0) { grow(worldIn, rand, pos, state); } } }
blockPlant = (world.rand.nextBoolean() ? Blocks.RED_MUSHROOM : Blocks.BROWN_MUSHROOM); statePlant = blockPlant.getDefaultState(); if (blockPlant != null && blockPlant.canBlockStay(world, blockPosSurface, statePlant)) { world.setBlockState(blockPosSurface, statePlant);
flowerRegistry.registerPlantableFlower(Blocks.BROWN_MUSHROOM.getDefaultState(), 1.0, FlowerManager.FlowerTypeMushrooms); flowerRegistry.registerPlantableFlower(Blocks.RED_MUSHROOM.getDefaultState(), 1.0, FlowerManager.FlowerTypeMushrooms); flowerRegistry.registerPlantableFlower(Blocks.CACTUS.getDefaultState(), 1.0, FlowerManager.FlowerTypeCacti);
@Override public boolean canBlockStay(World world, BlockPos pos, IBlockState state) { IBlockState iblockstateDown = world.getBlockState(pos.down()); if (state.getBlock() != this) return iblockstateDown.getBlock() == Blocks.SAND ? true : iblockstateDown.getBlock() == ModBlocks.MUD ? true : super.canBlockStay(world, pos, state); //Forge: This function is called during world gen and placement, before this block is set, so if we are not 'here' then assume it's the pre-check. if (state.getValue(HALF) == BlockDoubleHeightPlant.EnumBlockHalf.UPPER) return world.getBlockState(pos.down()).getBlock() == this; else { IBlockState iblockstate = world.getBlockState(pos.up()); return iblockstate.getBlock() == this && iblockstateDown.getBlock() == Blocks.SAND ? true : iblockstate.getBlock() == this && iblockstateDown.getBlock() == ModBlocks.MUD ? true : iblockstate.getBlock() == this && super.canBlockStay(world, pos, iblockstate); } }
@Override public boolean canPlaceBlockAt(World worldIn, BlockPos pos) { return super.canPlaceBlockAt(worldIn, pos) || BotanyCore.getGardening().isSoil(worldIn.getBlockState(pos).getBlock()); }