mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-18 11:19:28 +00:00
1 parent
4fdbaff7ad
commit
edacde02e7
63 files changed
+1395
-1199
No files matched your search
@@ -9,6 +9,7 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -78,13 +79,11 @@ public interface IFruitProvider {
|
||||
|
||||
/**
|
||||
* Tries to spawn a fruit block at the potential position when the tree generates.
|
||||
* Spawning a fruit has a random chance of success based on {@link ITreeGenome#getSappiness()}
|
||||
*
|
||||
* @param genome
|
||||
* @param world
|
||||
* @param pos
|
||||
* @return true if a fruit block was spawned, false otherwise.
|
||||
*/
|
||||
boolean trySpawnFruitBlock(ITreeGenome genome, World world, BlockPos pos);
|
||||
boolean trySpawnFruitBlock(ITreeGenome genome, World world, Random rand, BlockPos pos);
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
void registerSprites();
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.arboriculture;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -18,9 +20,10 @@ public interface IGrowthProvider {
|
||||
* @param pos Coordinates to attempt growth at.
|
||||
* @param expectedGirth Trunk size of the tree to generate.
|
||||
* @param expectedHeight Height of the tree to generate.
|
||||
* @return true if the tree can grow at the given coordinates, false otherwise.
|
||||
* @return position that the tree can grow, null otherwise.
|
||||
*/
|
||||
boolean canGrow(ITreeGenome genome, World world, BlockPos pos, int expectedGirth, int expectedHeight);
|
||||
@Nullable
|
||||
BlockPos canGrow(ITreeGenome genome, World world, BlockPos pos, int expectedGirth, int expectedHeight);
|
||||
|
||||
EnumGrowthConditions getGrowthConditions(ITreeGenome genome, World world, BlockPos pos);
|
||||
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.arboriculture;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface ILeafTickHandler {
|
||||
boolean onRandomLeafTick(ITree tree, World world, BlockPos pos, boolean isDestroyed);
|
||||
boolean onRandomLeafTick(ITree tree, World world, Random rand, BlockPos pos, boolean isDestroyed);
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
package forestry.api.arboriculture;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -62,10 +63,12 @@ public interface ITree extends IIndividual, ITreeGenData {
|
||||
boolean canStay(IBlockAccess world, BlockPos pos);
|
||||
|
||||
/**
|
||||
* @return Boolean indicating whether a sapling at the given position can grow into a tree.
|
||||
* @return Position that this tree can grow. May be different from pos if there are multiple saplings.
|
||||
* Returns null if a sapling at the given position can not grow into a tree.
|
||||
*/
|
||||
@Override
|
||||
boolean canGrow(World world, BlockPos pos, int expectedGirth, int expectedHeight);
|
||||
@Nullable
|
||||
BlockPos canGrow(World world, BlockPos pos, int expectedGirth, int expectedHeight);
|
||||
|
||||
/**
|
||||
* @return Integer denoting the maturity (block ticks) required for a sapling to attempt to grow into a tree.
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.world;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
@@ -19,7 +22,12 @@ public interface ITreeGenData {
|
||||
|
||||
float getHeightModifier();
|
||||
|
||||
boolean canGrow(World world, BlockPos pos, int expectedGirth, int expectedHeight);
|
||||
/**
|
||||
* @return Position that this tree can grow. May be different from pos if there are multiple saplings.
|
||||
* Returns null if a sapling at the given position can not grow into a tree.
|
||||
*/
|
||||
@Nullable
|
||||
BlockPos canGrow(World world, BlockPos pos, int expectedGirth, int expectedHeight);
|
||||
|
||||
boolean setLeaves(World world, GameProfile owner, BlockPos pos);
|
||||
|
||||
@@ -27,7 +35,7 @@ public interface ITreeGenData {
|
||||
|
||||
boolean allowsFruitBlocks();
|
||||
|
||||
boolean trySpawnFruitBlock(World world, BlockPos pos);
|
||||
boolean trySpawnFruitBlock(World world, Random rand, BlockPos pos);
|
||||
|
||||
ITreeGenome getGenome();
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -85,7 +86,7 @@ public class FruitProviderNone implements IFruitProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean trySpawnFruitBlock(ITreeGenome genome, World world, BlockPos pos) {
|
||||
public boolean trySpawnFruitBlock(ITreeGenome genome, World world, Random rand, BlockPos pos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -84,9 +85,9 @@ public class FruitProviderPod extends FruitProviderNone {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean trySpawnFruitBlock(ITreeGenome genome, World world, BlockPos pos) {
|
||||
public boolean trySpawnFruitBlock(ITreeGenome genome, World world, Random rand, BlockPos pos) {
|
||||
|
||||
if (world.rand.nextFloat() > genome.getSappiness()) {
|
||||
if (rand.nextFloat() > genome.getSappiness()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,14 +15,8 @@ import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDoor;
|
||||
import net.minecraft.block.BlockFenceGate;
|
||||
import net.minecraft.block.BlockLog;
|
||||
import net.minecraft.block.BlockSlab;
|
||||
import net.minecraft.block.BlockStairs;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import forestry.api.arboriculture.EnumWoodType;
|
||||
import forestry.api.arboriculture.IWoodAccess;
|
||||
|
||||
@@ -237,8 +237,8 @@ public class BlockForestryLeaves extends BlockLeaves implements ITileEntityProvi
|
||||
TileLeaves tileLeaves = TileUtil.getTile(world, pos, TileLeaves.class);
|
||||
|
||||
// check leaves tile because they might have decayed
|
||||
if (tileLeaves != null && !tileLeaves.isInvalid() && world.rand.nextFloat() <= 0.1) {
|
||||
tileLeaves.onBlockTick();
|
||||
if (tileLeaves != null && !tileLeaves.isInvalid() && rand.nextFloat() <= 0.1) {
|
||||
tileLeaves.onBlockTick(world, pos, state, rand);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
@@ -86,7 +86,7 @@ public class BlockFruitPod extends BlockCocoa implements IStateMapperRegister, I
|
||||
return;
|
||||
}
|
||||
|
||||
tile.onBlockTick();
|
||||
tile.onBlockTick(world, pos, state, rand);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -199,23 +199,26 @@ public class BlockSapling extends BlockTreeContainer implements IGrowable, IStat
|
||||
/* GROWNING */
|
||||
@Override
|
||||
public boolean canUseBonemeal(World world, Random rand, BlockPos pos, IBlockState state) {
|
||||
if (world.rand.nextFloat() >= 0.45F) {
|
||||
return false;
|
||||
}
|
||||
TileSapling saplingTile = getSaplingTile(world, pos);
|
||||
if (saplingTile != null) {
|
||||
return saplingTile.canAcceptBoneMeal();
|
||||
return saplingTile.canAcceptBoneMeal(rand);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canGrow(World world, BlockPos pos, IBlockState state, boolean isClient) {
|
||||
return world.rand.nextFloat() < 0.45F;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void grow(World world, Random rand, BlockPos pos, IBlockState state) {
|
||||
TileSapling saplingTile = getSaplingTile(world, pos);
|
||||
if (saplingTile != null) {
|
||||
saplingTile.tryGrow(true);
|
||||
saplingTile.tryGrow(rand, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,12 +15,12 @@ import java.util.Random;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumBlockRenderType;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.arboriculture.tiles.TileTreeContainer;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
|
||||
public abstract class BlockTreeContainer extends BlockContainer {
|
||||
|
||||
@@ -32,16 +32,16 @@ public abstract class BlockTreeContainer extends BlockContainer {
|
||||
@Override
|
||||
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
|
||||
|
||||
if (world.rand.nextFloat() > 0.1) {
|
||||
if (rand.nextFloat() > 0.1) {
|
||||
return;
|
||||
}
|
||||
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (!(tile instanceof TileTreeContainer)) {
|
||||
TileTreeContainer tile = TileUtil.getTile(world, pos, TileTreeContainer.class);
|
||||
if (tile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
((TileTreeContainer) tile).onBlockTick();
|
||||
tile.onBlockTick(world, pos, state, rand);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -51,7 +51,7 @@ public final class TreeGenHelper {
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
if (BlockUtil.canPlaceTree(blockState, world, pos)){
|
||||
if (gen instanceof WorldGenBase) {
|
||||
((WorldGenBase) gen).generate(world, pos, false);
|
||||
((WorldGenBase) gen).generate(world, world.rand, pos, true);
|
||||
} else {
|
||||
gen.generate(world, world.rand, pos);
|
||||
}
|
||||
|
||||
@@ -10,8 +10,11 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.genetics;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
@@ -22,21 +25,28 @@ import forestry.api.arboriculture.ITree;
|
||||
import forestry.api.arboriculture.ITreeGenome;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.arboriculture.tiles.TileSapling;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.core.utils.Translator;
|
||||
|
||||
public class GrowthProvider implements IGrowthProvider {
|
||||
|
||||
@Override
|
||||
public boolean canGrow(ITreeGenome genome, World world, BlockPos pos, int expectedGirth, int expectedHeight) {
|
||||
if (!hasRoom(world, pos, expectedGirth, expectedHeight)) {
|
||||
return false;
|
||||
@Nullable
|
||||
public BlockPos canGrow(ITreeGenome genome, World world, BlockPos pos, int expectedGirth, int expectedHeight) {
|
||||
BlockPos growthPos = hasSufficientSaplingsAroundSapling(genome, world, pos, expectedGirth);
|
||||
if (growthPos == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (getGrowthConditions(genome, world, pos) == EnumGrowthConditions.HOSTILE) {
|
||||
return false;
|
||||
if (!hasRoom(world, growthPos, expectedGirth, expectedHeight)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return hasSufficientSaplings(genome, world, pos, expectedGirth);
|
||||
if (getGrowthConditions(genome, world, growthPos) == EnumGrowthConditions.HOSTILE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return growthPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,15 +84,15 @@ public class GrowthProvider implements IGrowthProvider {
|
||||
}
|
||||
|
||||
protected static EnumGrowthConditions getConditionFromLight(World world, BlockPos pos) {
|
||||
int lightvalue = world.getLightFromNeighbors(pos.add(0, 1, 0));
|
||||
int lightValue = world.getLightFromNeighbors(pos.add(0, 1, 0));
|
||||
|
||||
if (lightvalue > 13) {
|
||||
if (lightValue > 13) {
|
||||
return EnumGrowthConditions.EXCELLENT;
|
||||
} else if (lightvalue > 11) {
|
||||
} else if (lightValue > 11) {
|
||||
return EnumGrowthConditions.GOOD;
|
||||
} else if (lightvalue > 8) {
|
||||
} else if (lightValue > 8) {
|
||||
return EnumGrowthConditions.NORMAL;
|
||||
} else if (lightvalue > 6) {
|
||||
} else if (lightValue > 6) {
|
||||
return EnumGrowthConditions.PALTRY;
|
||||
} else {
|
||||
return EnumGrowthConditions.HOSTILE;
|
||||
@@ -90,21 +100,15 @@ public class GrowthProvider implements IGrowthProvider {
|
||||
}
|
||||
|
||||
private static boolean hasRoom(World world, BlockPos pos, int expectedGirth, int expectedHeight) {
|
||||
|
||||
int offset = (expectedGirth - 1) / 2;
|
||||
// if(offset <= 0)
|
||||
// offset = 1;
|
||||
BlockPos start = new BlockPos(pos.getX() - offset, pos.getY() + 1, pos.getZ() + offset);
|
||||
Vec3i area = new Vec3i(-offset + expectedGirth, expectedHeight + 1, -offset + expectedGirth);
|
||||
|
||||
return checkArea(world, start, area);
|
||||
Vec3i area = new Vec3i(expectedGirth, expectedHeight + 1, expectedGirth);
|
||||
return checkArea(world, pos.up(), area);
|
||||
}
|
||||
|
||||
private static boolean checkArea(World world, BlockPos start, Vec3i area) {
|
||||
for (int x = start.getX(); x < start.getX() + area.getX(); x++) {
|
||||
for (int y = start.getY(); y < start.getY() + area.getY(); y++) {
|
||||
for (int z = start.getZ(); z < start.getZ() + area.getZ(); z++) {
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
for (int x = 0; x < area.getX(); x++) {
|
||||
for (int y = 0; y < area.getY(); y++) {
|
||||
for (int z = 0; z < area.getZ(); z++) {
|
||||
BlockPos pos = start.add(x, y, z);
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
if (!blockState.getBlock().isReplaceable(world, pos)) {
|
||||
return false;
|
||||
@@ -115,36 +119,62 @@ public class GrowthProvider implements IGrowthProvider {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean hasSufficientSaplings(ITreeGenome genome, World world, BlockPos pos, int expectedGirth) {
|
||||
/**
|
||||
* Checks an area for saplings.
|
||||
* If saplings need to be 2x2, 3x3, etc, it will check all configurations in which pos is included in that area.
|
||||
* Uses a knownSaplings cache to avoid checking the same saplings multiple times.
|
||||
*/
|
||||
@Nullable
|
||||
private static BlockPos hasSufficientSaplingsAroundSapling(ITreeGenome genome, World world, BlockPos saplingPos, int expectedGirth) {
|
||||
final int checkSize = (expectedGirth * 2) - 1;
|
||||
final int offset = expectedGirth - 1;
|
||||
final Map<BlockPos, Boolean> knownSaplings = new HashMap<>(checkSize * checkSize);
|
||||
|
||||
if (expectedGirth == 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int offset = (expectedGirth - 1) / 2;
|
||||
|
||||
for (int x = pos.getX() - offset; x < pos.getX() - offset + expectedGirth; x++) {
|
||||
for (int z = pos.getZ() - offset; z < pos.getZ() - offset + expectedGirth; z++) {
|
||||
|
||||
BlockPos newPos = new BlockPos(x, pos.getY(), z);
|
||||
|
||||
if (world.isAirBlock(newPos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TileEntity tile = world.getTileEntity(newPos);
|
||||
if (!(tile instanceof TileSapling)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ITree tree = ((TileSapling) tile).getTree();
|
||||
if (tree == null || !tree.getGenome().getPrimary().getUID().equals(genome.getPrimary().getUID())) {
|
||||
return false;
|
||||
for (int x = -offset; x <= 0; x++) {
|
||||
for (int z = -offset; z <= 0; z++) {
|
||||
BlockPos startPos = saplingPos.add(x, 0, z);
|
||||
if (checkForSaplings(genome, world, startPos, expectedGirth, knownSaplings)) {
|
||||
return startPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean checkForSaplings(ITreeGenome genome, World world, BlockPos startPos, int girth, Map<BlockPos, Boolean> knownSaplings) {
|
||||
for (int x = 0; x < girth; x++) {
|
||||
for (int z = 0; z < girth; z++) {
|
||||
BlockPos checkPos = startPos.add(x, 0, z);
|
||||
Boolean knownSapling = knownSaplings.get(checkPos);
|
||||
if (knownSapling == null) {
|
||||
knownSapling = isSapling(genome, world, checkPos);
|
||||
knownSaplings.put(checkPos, knownSapling);
|
||||
}
|
||||
|
||||
if (!knownSapling) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isSapling(ITreeGenome genome, World world, BlockPos pos) {
|
||||
if (!world.isBlockLoaded(pos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (world.isAirBlock(pos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TileSapling sapling = TileUtil.getTile(world, pos, TileSapling.class);
|
||||
if (sapling == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ITree tree = sapling.getTree();
|
||||
return tree != null && tree.getGenome().getPrimary().getUID().equals(genome.getPrimary().getUID());
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -184,7 +185,8 @@ public class Tree extends Individual implements ITree, IPlantable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canGrow(World world, BlockPos pos, int expectedGirth, int expectedHeight) {
|
||||
@Nullable
|
||||
public BlockPos canGrow(World world, BlockPos pos, int expectedGirth, int expectedHeight) {
|
||||
IGrowthProvider growthProvider = genome.getGrowthProvider();
|
||||
return growthProvider.canGrow(genome, world, pos, expectedGirth, expectedHeight);
|
||||
}
|
||||
@@ -237,14 +239,14 @@ public class Tree extends Individual implements ITree, IPlantable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean trySpawnFruitBlock(World world, BlockPos pos) {
|
||||
public boolean trySpawnFruitBlock(World world, Random rand, BlockPos pos) {
|
||||
IFruitProvider provider = getGenome().getFruitProvider();
|
||||
Collection<IFruitFamily> suitable = genome.getPrimary().getSuitableFruit();
|
||||
if (!suitable.contains(provider.getFamily())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return provider.trySpawnFruitBlock(getGenome(), world, pos);
|
||||
return provider.trySpawnFruitBlock(getGenome(), world, rand, pos);
|
||||
}
|
||||
|
||||
/* INFORMATION */
|
||||
|
||||
@@ -1009,7 +1009,6 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe
|
||||
|
||||
protected abstract void registerMutations();
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
@Override
|
||||
public boolean setLogBlock(ITreeGenome genome, World world, BlockPos pos, EnumFacing facing) {
|
||||
IBlockState logBlock;
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.BlockCocoa;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -84,8 +85,8 @@ public class TileFruitPod extends TileEntity implements IFruitBearer, IStreamabl
|
||||
}
|
||||
|
||||
/* UPDATING */
|
||||
public void onBlockTick() {
|
||||
if (canMature() && worldObj.rand.nextFloat() <= sappiness) {
|
||||
public void onBlockTick(World world, BlockPos pos, IBlockState state, Random rand) {
|
||||
if (canMature() && rand.nextFloat() <= sappiness) {
|
||||
addRipeness(0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,15 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.EnumPlantType;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
@@ -112,7 +115,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockTick() {
|
||||
public void onBlockTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
|
||||
ITree tree = getTree();
|
||||
if (tree == null) {
|
||||
return;
|
||||
@@ -122,7 +125,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
|
||||
|
||||
boolean isDestroyed = isDestroyed(tree, damage);
|
||||
for (ILeafTickHandler tickHandler : genome.getPrimary().getRoot().getLeafTickHandlers()) {
|
||||
if (tickHandler.onRandomLeafTick(tree, worldObj, getPos(), isDestroyed)) {
|
||||
if (tickHandler.onRandomLeafTick(tree, worldObj, rand, getPos(), isDestroyed)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -140,7 +143,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
|
||||
float sappinessModifier = treekeepingMode.getSappinessModifier(genome, 1f);
|
||||
float sappiness = genome.getSappiness() * sappinessModifier;
|
||||
|
||||
if (worldObj.rand.nextFloat() < sappiness) {
|
||||
if (rand.nextFloat() < sappiness) {
|
||||
ripeningTime++;
|
||||
sendNetworkUpdateRipening();
|
||||
}
|
||||
|
||||
@@ -10,7 +10,11 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.tiles;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.gen.feature.WorldGenerator;
|
||||
|
||||
@@ -41,10 +45,9 @@ public class TileSapling extends TileTreeContainer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockTick() {
|
||||
|
||||
public void onBlockTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
|
||||
timesTicked++;
|
||||
tryGrow(false);
|
||||
tryGrow(rand, false);
|
||||
}
|
||||
|
||||
private static int getRequiredMaturity(World world, ITree tree) {
|
||||
@@ -53,7 +56,7 @@ public class TileSapling extends TileTreeContainer {
|
||||
return Math.round(tree.getRequiredMaturity() * maturationModifier);
|
||||
}
|
||||
|
||||
public boolean canAcceptBoneMeal() {
|
||||
public boolean canAcceptBoneMeal(Random rand) {
|
||||
ITree tree = getTree();
|
||||
|
||||
if (tree == null) {
|
||||
@@ -68,14 +71,14 @@ public class TileSapling extends TileTreeContainer {
|
||||
WorldGenerator generator = tree.getTreeGenerator(worldObj, getPos(), true);
|
||||
if (generator instanceof WorldGenArboriculture) {
|
||||
WorldGenArboriculture arboricultureGenerator = (WorldGenArboriculture) generator;
|
||||
arboricultureGenerator.preGenerate(worldObj, getPos());
|
||||
return arboricultureGenerator.canGrow(worldObj, getPos());
|
||||
arboricultureGenerator.preGenerate(worldObj, rand, getPos());
|
||||
return arboricultureGenerator.getValidGrowthPos(worldObj, getPos()) != null;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void tryGrow(boolean bonemealed) {
|
||||
public void tryGrow(Random random, boolean bonemealed) {
|
||||
|
||||
ITree tree = getTree();
|
||||
|
||||
@@ -94,9 +97,9 @@ public class TileSapling extends TileTreeContainer {
|
||||
WorldGenerator generator = tree.getTreeGenerator(worldObj, getPos(), bonemealed);
|
||||
final boolean generated;
|
||||
if (generator instanceof WorldGenBase) {
|
||||
generated = ((WorldGenBase) generator).generate(worldObj, getPos(), bonemealed);
|
||||
generated = ((WorldGenBase) generator).generate(worldObj, random, getPos(), false);
|
||||
} else {
|
||||
generated = generator.generate(worldObj, worldObj.rand, getPos());
|
||||
generated = generator.generate(worldObj, random, getPos());
|
||||
}
|
||||
|
||||
if (generated) {
|
||||
|
||||
@@ -12,6 +12,7 @@ package forestry.arboriculture.tiles;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -143,7 +144,7 @@ public abstract class TileTreeContainer extends TileEntity implements IStreamabl
|
||||
/**
|
||||
* Leaves and saplings will implement their logic here.
|
||||
*/
|
||||
public abstract void onBlockTick();
|
||||
public abstract void onBlockTick(World worldIn, BlockPos pos, IBlockState state, Random rand);
|
||||
|
||||
/**
|
||||
* Called from Chunk.setBlockIDWithMetadata, determines if this tile entity should be re-created when the ID, or Metadata changes.
|
||||
|
||||
@@ -14,10 +14,8 @@ import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
|
||||
public interface ITreeBlockType {
|
||||
void setDirection(EnumFacing facing);
|
||||
|
||||
boolean setBlock(World world, ITreeGenData tree, BlockPos pos);
|
||||
boolean setBlock(World world, BlockPos pos);
|
||||
}
|
||||
@@ -10,22 +10,17 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.config.Constants;
|
||||
|
||||
public class TreeBlockType implements ITreeBlockType {
|
||||
|
||||
private final Block block;
|
||||
private final int meta;
|
||||
private final IBlockState blockState;
|
||||
|
||||
public TreeBlockType(Block block, int meta) {
|
||||
this.block = block;
|
||||
this.meta = meta;
|
||||
public TreeBlockType(IBlockState blockState) {
|
||||
this.blockState = blockState;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -34,15 +29,11 @@ public class TreeBlockType implements ITreeBlockType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(World world, ITreeGenData tree, BlockPos pos) {
|
||||
return world.setBlockState(pos, block.getStateFromMeta(meta), Constants.FLAG_BLOCK_SYNCH);
|
||||
public boolean setBlock(World world, BlockPos pos) {
|
||||
return world.setBlockState(pos, blockState);
|
||||
}
|
||||
|
||||
public int getMeta() {
|
||||
return this.meta;
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
return this.block;
|
||||
public IBlockState getBlockState() {
|
||||
return blockState;
|
||||
}
|
||||
}
|
||||
@@ -19,10 +19,11 @@ import com.mojang.authlib.GameProfile;
|
||||
import forestry.api.world.ITreeGenData;
|
||||
|
||||
public class TreeBlockTypeLeaf implements ITreeBlockType {
|
||||
|
||||
private final ITreeGenData tree;
|
||||
private final GameProfile owner;
|
||||
|
||||
public TreeBlockTypeLeaf(GameProfile owner) {
|
||||
public TreeBlockTypeLeaf(ITreeGenData tree, GameProfile owner) {
|
||||
this.tree = tree;
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@@ -32,7 +33,7 @@ public class TreeBlockTypeLeaf implements ITreeBlockType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(World world, ITreeGenData tree, BlockPos pos) {
|
||||
public boolean setBlock(World world, BlockPos pos) {
|
||||
return tree.setLeaves(world, owner, pos);
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,11 @@ import net.minecraft.world.World;
|
||||
import forestry.api.world.ITreeGenData;
|
||||
|
||||
public class TreeBlockTypeLog implements ITreeBlockType {
|
||||
private final ITreeGenData tree;
|
||||
private EnumFacing facing = EnumFacing.UP;
|
||||
|
||||
public TreeBlockTypeLog() {
|
||||
|
||||
public TreeBlockTypeLog(ITreeGenData tree) {
|
||||
this.tree = tree;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -29,7 +30,7 @@ public class TreeBlockTypeLog implements ITreeBlockType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(World world, ITreeGenData tree, BlockPos pos) {
|
||||
public boolean setBlock(World world, BlockPos pos) {
|
||||
return tree.setLogBlock(world, pos, facing);
|
||||
}
|
||||
}
|
||||
@@ -10,13 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenAcacia extends WorldGenTree {
|
||||
|
||||
@@ -24,19 +27,20 @@ public class WorldGenAcacia extends WorldGenTree {
|
||||
super(tree, 5, 2);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
Direction leanDirection = Direction.getRandom(world.rand);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.Direction leanDirection = WorldGenHelper.Direction.getRandom(rand);
|
||||
float leanAmount = height / 4.0f;
|
||||
|
||||
List<BlockPos> treeTops = generateTreeTrunk(world, height, girth, 0, leanDirection.facing, leanAmount);
|
||||
if (height > 5 && world.rand.nextBoolean()) {
|
||||
Direction branchDirection = Direction.getRandomOther(world.rand, leanDirection);
|
||||
List<BlockPos> treeTops2 = generateTreeTrunk(world, Math.round(height * 0.66f), girth, 0, branchDirection.facing, leanAmount);
|
||||
Set<BlockPos> treeTops = WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, leanDirection.facing, leanAmount);
|
||||
if (height > 5 && rand.nextBoolean()) {
|
||||
WorldGenHelper.Direction branchDirection = WorldGenHelper.Direction.getRandomOther(rand, leanDirection);
|
||||
Set<BlockPos> treeTops2 = WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, Math.round(height * 0.66f), girth, 0, 0, branchDirection.facing, leanAmount);
|
||||
treeTops.addAll(treeTops2);
|
||||
}
|
||||
|
||||
List<BlockPos> branchLocations = new ArrayList<>();
|
||||
Set<BlockPos> branchEnds = new HashSet<>(treeTops);
|
||||
|
||||
for (BlockPos treeTop : treeTops) {
|
||||
int xOffset = treeTop.getX();
|
||||
@@ -45,24 +49,27 @@ public class WorldGenAcacia extends WorldGenTree {
|
||||
float canopyMultiplier = (1.5f * height - yOffset + 2) / 4.0f;
|
||||
int canopyThickness = Math.max(1, Math.round(yOffset / 10.0f));
|
||||
|
||||
generateAdjustedCylinder(world, yOffset--, xOffset, zOffset, canopyMultiplier, 1, leaf, EnumReplaceMode.AIR);
|
||||
yOffset--;
|
||||
|
||||
float canopyWidth = world.rand.nextBoolean() ? 3.0f : 2.5f;
|
||||
List<BlockPos> branches = generateBranches(world, yOffset - canopyThickness, xOffset, zOffset, 0.0f, 0.1f, Math.round(canopyMultiplier * canopyWidth - 4), 2);
|
||||
branchLocations.addAll(branches);
|
||||
float canopyWidth = rand.nextBoolean() ? 3.0f : 2.5f;
|
||||
int radius = Math.round(canopyMultiplier * canopyWidth - 4);
|
||||
BlockPos pos = startPos.add(xOffset, yOffset - canopyThickness, zOffset);
|
||||
branchEnds.addAll(WorldGenHelper.generateBranches(world, rand, wood, pos, girth, 0.0f, 0.1f, radius, 2, 1.0f));
|
||||
}
|
||||
|
||||
for (BlockPos branchLocation : branchLocations) {
|
||||
int leafSpawn = branchLocation.getY();
|
||||
int canopyThickness = Math.max(1, Math.round(leafSpawn / 10.0f));
|
||||
float canopyMultiplier = (1.5f * height - leafSpawn + 2) / 4.0f;
|
||||
float canopyWidth = world.rand.nextBoolean() ? 1.0f : 1.5f;
|
||||
generateAdjustedCylinder(world, leafSpawn - canopyThickness + 1, branchLocation.getX(), branchLocation.getZ(), canopyMultiplier * canopyWidth, canopyThickness, leaf, EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
return branchEnds;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
for (BlockPos branchEnd : branchEnds) {
|
||||
int leafSpawn = branchEnd.getY();
|
||||
int canopyThickness = Math.max(1, Math.round(leafSpawn / 10.0f));
|
||||
float canopyMultiplier = (1.5f * height - leafSpawn + 2) / 4.0f;
|
||||
float canopyWidth = rand.nextBoolean() ? 2.0f : 4.5f;
|
||||
BlockPos center = new BlockPos(branchEnd.getX(), leafSpawn - canopyThickness + 1, branchEnd.getZ());
|
||||
float radius = Math.max(1, canopyMultiplier * canopyWidth + girth);
|
||||
WorldGenHelper.generateCylinderFromPos(world, leaf, center, radius, canopyThickness, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,20 +10,18 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraftforge.event.terraingen.TerrainGen;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.arboriculture.tiles.TileTreeContainer;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
@@ -31,54 +29,37 @@ import forestry.core.worldgen.WorldGenBase;
|
||||
|
||||
public abstract class WorldGenArboriculture extends WorldGenBase {
|
||||
|
||||
enum Direction {
|
||||
NORTH(EnumFacing.NORTH),
|
||||
SOUTH(EnumFacing.SOUTH),
|
||||
WEST(EnumFacing.WEST),
|
||||
EAST(EnumFacing.EAST);
|
||||
|
||||
public final EnumFacing facing;
|
||||
|
||||
Direction(EnumFacing forgeDirection) {
|
||||
this.facing = forgeDirection;
|
||||
}
|
||||
|
||||
public static Direction getRandom(Random random) {
|
||||
return values()[random.nextInt(values().length)];
|
||||
}
|
||||
|
||||
public static Direction getRandomOther(Random random, Direction direction) {
|
||||
EnumSet<Direction> directions = EnumSet.allOf(Direction.class);
|
||||
directions.remove(direction);
|
||||
int size = directions.size();
|
||||
return directions.toArray(new Direction[size])[random.nextInt(size)];
|
||||
}
|
||||
}
|
||||
|
||||
private static final ITreeBlockType vineNorth = new TreeBlockType(Blocks.VINE, 1);
|
||||
private static final ITreeBlockType vineSouth = new TreeBlockType(Blocks.VINE, 4);
|
||||
private static final ITreeBlockType vineWest = new TreeBlockType(Blocks.VINE, 8);
|
||||
private static final ITreeBlockType vineEast = new TreeBlockType(Blocks.VINE, 2);
|
||||
private static final int minPodHeight = 3;
|
||||
protected static final int minPodHeight = 3;
|
||||
|
||||
protected final ITreeGenData tree;
|
||||
private BlockPos startPos;
|
||||
|
||||
protected TreeBlockTypeLeaf leaf;
|
||||
protected ITreeBlockType wood;
|
||||
|
||||
protected WorldGenArboriculture(ITreeGenData tree) {
|
||||
this.tree = tree;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(World world, BlockPos pos, boolean forced) {
|
||||
this.leaf = getLeaf(getOwner(world, pos));
|
||||
this.wood = getWood();
|
||||
public boolean generate(World world, Random rand, BlockPos pos, boolean forced) {
|
||||
if (!TerrainGen.saplingGrowTree(world, rand, pos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
preGenerate(world, pos);
|
||||
if (forced || canGrow(world, pos)) {
|
||||
generate(world);
|
||||
GameProfile owner = getOwner(world, pos);
|
||||
TreeBlockTypeLeaf leaf = new TreeBlockTypeLeaf(tree, owner);
|
||||
TreeBlockTypeLog wood = new TreeBlockTypeLog(tree);
|
||||
|
||||
preGenerate(world, rand, pos);
|
||||
|
||||
BlockPos genPos;
|
||||
if (forced) {
|
||||
genPos = pos;
|
||||
} else {
|
||||
genPos = getValidGrowthPos(world, pos);
|
||||
}
|
||||
|
||||
if (genPos != null) {
|
||||
Set<BlockPos> branchEnds = generateTrunk(world, rand, wood, genPos);
|
||||
generateLeaves(world, rand, leaf, branchEnds, genPos);
|
||||
generateExtras(world, rand, genPos);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -93,261 +74,25 @@ public abstract class WorldGenArboriculture extends WorldGenBase {
|
||||
return tile.getOwner();
|
||||
}
|
||||
|
||||
public void preGenerate(World world, BlockPos startPos) {
|
||||
this.startPos = startPos;
|
||||
public void preGenerate(World world, Random rand, BlockPos startPos) {
|
||||
|
||||
}
|
||||
|
||||
protected abstract void generate(World world);
|
||||
/**
|
||||
* Generate the tree's trunk. Returns a list of positions of branch ends for leaves to generate at.
|
||||
*/
|
||||
@Nonnull
|
||||
protected abstract Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos);
|
||||
|
||||
public abstract boolean canGrow(World world, BlockPos pos);
|
||||
protected abstract void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos);
|
||||
|
||||
protected abstract TreeBlockTypeLeaf getLeaf(GameProfile owner);
|
||||
protected abstract void generateExtras(World world, Random rand, BlockPos startPos);
|
||||
|
||||
protected abstract ITreeBlockType getWood();
|
||||
|
||||
protected List<BlockPos> generateTreeTrunk(World world, int height, int girth) {
|
||||
return generateTreeTrunk(world, height, girth, 0);
|
||||
}
|
||||
|
||||
protected List<BlockPos> generateTreeTrunk(World world, int height, int girth, float vinesChance) {
|
||||
return generateTreeTrunk(world, height, girth, vinesChance, null, 0);
|
||||
}
|
||||
|
||||
protected List<BlockPos> generateTreeTrunk(World world, int height, int girth, float vinesChance, EnumFacing leanDirection, float leanAmount) {
|
||||
return generateTreeTrunk(world, height, girth, 0, vinesChance, leanDirection, leanAmount);
|
||||
}
|
||||
|
||||
/** Returns a list of trunk top coordinates */
|
||||
protected List<BlockPos> generateTreeTrunk(World world, int height, int girth, int yStart, float vinesChance, EnumFacing leanDirection, float leanAmount) {
|
||||
List<BlockPos> treeTops = new ArrayList<>();
|
||||
|
||||
final int leanStartY = (int) Math.floor(height * 0.33f);
|
||||
int prevXOffset = 0;
|
||||
int prevZOffset = 0;
|
||||
|
||||
int offsetX = 0;
|
||||
int offsetZ = 0;
|
||||
|
||||
if (leanDirection != null) {
|
||||
offsetX = leanDirection.getFrontOffsetX();
|
||||
offsetZ = leanDirection.getFrontOffsetZ();
|
||||
}
|
||||
|
||||
int offset = (girth - 1) / 2;
|
||||
for (int x = 0; x < girth; x++) {
|
||||
for (int z = 0; z < girth; z++) {
|
||||
for (int y = yStart; y < height; y++) {
|
||||
float lean;
|
||||
if (y < leanStartY) {
|
||||
lean = 0;
|
||||
} else {
|
||||
lean = leanAmount * (y - leanStartY) / (height - leanStartY);
|
||||
}
|
||||
int xOffset = (int) Math.floor(offsetX * lean - offset);
|
||||
int zOffset = (int) Math.floor(offsetZ * lean - offset);
|
||||
|
||||
if (xOffset != prevXOffset || zOffset != prevZOffset) {
|
||||
prevXOffset = xOffset;
|
||||
prevZOffset = zOffset;
|
||||
if (y > 0) {
|
||||
wood.setDirection(leanDirection);
|
||||
addWood(world, new BlockPos(x + xOffset, y - 1, z + zOffset), EnumReplaceMode.ALL);
|
||||
wood.setDirection(EnumFacing.UP);
|
||||
}
|
||||
}
|
||||
|
||||
addWood(world, new BlockPos(x + xOffset, y, z + zOffset), EnumReplaceMode.ALL);
|
||||
addVines(world, new BlockPos(x + xOffset, y, z + zOffset), vinesChance);
|
||||
|
||||
if (y + 1 == height) {
|
||||
treeTops.add(new BlockPos(x + xOffset, y, z + zOffset));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return treeTops;
|
||||
}
|
||||
@Nullable
|
||||
public abstract BlockPos getValidGrowthPos(World world, BlockPos pos);
|
||||
|
||||
public boolean hasPods() {
|
||||
return tree.allowsFruitBlocks();
|
||||
}
|
||||
|
||||
protected void generatePods(World world, int height, int girth) {
|
||||
for (int y = minPodHeight; y < height; y++) {
|
||||
for (int x = 0; x < girth; x++) {
|
||||
for (int z = 0; z < girth; z++) {
|
||||
|
||||
if (x > 0 && x < girth && z > 0 && z < girth) {
|
||||
continue;
|
||||
}
|
||||
|
||||
trySpawnFruitBlock(world, new BlockPos(x + 1, y, z));
|
||||
trySpawnFruitBlock(world, new BlockPos(x - 1, y, z));
|
||||
trySpawnFruitBlock(world, new BlockPos(x, y, z + 1));
|
||||
trySpawnFruitBlock(world, new BlockPos(x, y, z - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void trySpawnFruitBlock(World world, BlockPos pos) {
|
||||
pos = pos.add(startPos);
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
Block block = blockState.getBlock();
|
||||
if (block.isReplaceable(world, pos) && !block.isLeaves(blockState, world, pos)) {
|
||||
tree.trySpawnFruitBlock(world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
protected void generateSupportStems(World world, int height, int girth, float chance, float maxHeight) {
|
||||
|
||||
int offset = (int) Math.ceil(girth / 2.0f);
|
||||
int max = (int) Math.floor(girth / 2.0f) + offset;
|
||||
if (girth % 2 == 0) {
|
||||
max++;
|
||||
}
|
||||
|
||||
for (int x = -offset; x < max; x++) {
|
||||
for (int z = -offset; z < max; z++) {
|
||||
|
||||
if (x == -offset && z == -offset) {
|
||||
continue;
|
||||
}
|
||||
if (x == max && z == max) {
|
||||
continue;
|
||||
}
|
||||
if (x == -offset && z == max) {
|
||||
continue;
|
||||
}
|
||||
if (x == max && z == -offset) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int stemHeight = world.rand.nextInt(Math.round(height * maxHeight));
|
||||
if (world.rand.nextFloat() < chance) {
|
||||
for (int i = 0; i < stemHeight; i++) {
|
||||
addWood(world, new BlockPos(x, i, z), EnumReplaceMode.SOFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected List<BlockPos> generateBranches(World world, final int startY, int xOffset, int zOffset, float spreadY, float spreadXZ, int radius, int count) {
|
||||
return generateBranches(world, startY, xOffset, zOffset, spreadY, spreadXZ, radius, count, 1.0f);
|
||||
}
|
||||
|
||||
protected List<BlockPos> generateBranches(World world, final int startY, final int xOffset, final int zOffset, final float spreadY, final float spreadXZ, int radius, final int count, final float chance) {
|
||||
List<BlockPos> branchEnds = new ArrayList<>();
|
||||
if (radius < 1) {
|
||||
radius = 1;
|
||||
}
|
||||
|
||||
for (Direction cardinalDirection : Direction.values()) {
|
||||
EnumFacing branchDirection = cardinalDirection.facing;
|
||||
wood.setDirection(branchDirection);
|
||||
|
||||
int offsetX = 0;
|
||||
int offsetZ = 0;
|
||||
|
||||
if (branchDirection != null) {
|
||||
offsetX = branchDirection.getFrontOffsetX();
|
||||
offsetZ = branchDirection.getFrontOffsetZ();
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (world.rand.nextFloat() > chance) {
|
||||
continue;
|
||||
}
|
||||
int y = startY;
|
||||
int x = xOffset;
|
||||
int z = zOffset;
|
||||
|
||||
for (int r = 0; r < radius; r++) {
|
||||
if (world.rand.nextFloat() < spreadY) {
|
||||
// make branches only spread up, not down
|
||||
y++;
|
||||
} else {
|
||||
if (world.rand.nextFloat() < spreadXZ) {
|
||||
if (offsetX == 0) {
|
||||
if (world.rand.nextBoolean()) {
|
||||
x++;
|
||||
} else {
|
||||
x--;
|
||||
}
|
||||
wood.setDirection(EnumFacing.EAST);
|
||||
} else if (offsetZ == 0) {
|
||||
if (world.rand.nextBoolean()) {
|
||||
z++;
|
||||
} else {
|
||||
z--;
|
||||
}
|
||||
wood.setDirection(EnumFacing.SOUTH);
|
||||
}
|
||||
} else {
|
||||
x += offsetX;
|
||||
z += offsetZ;
|
||||
wood.setDirection(branchDirection);
|
||||
}
|
||||
}
|
||||
if (addWood(world, new BlockPos(x, y, z), EnumReplaceMode.SOFT)) {
|
||||
branchEnds.add(new BlockPos(x, y, z));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return branchEnds;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean addBlock(World world, BlockPos pos, ITreeBlockType type, EnumReplaceMode replaceMode) {
|
||||
pos = pos.add(startPos);
|
||||
if (!world.isBlockLoaded(pos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
if (replaceMode.canReplace(blockState, world, pos)) {
|
||||
type.setBlock(world, tree, pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected final boolean addWood(World world, BlockPos pos, EnumReplaceMode replace) {
|
||||
return addBlock(world, pos, wood, replace);
|
||||
}
|
||||
|
||||
protected final boolean addLeaf(World world, BlockPos pos, EnumReplaceMode replace) {
|
||||
return addBlock(world, pos, leaf, replace);
|
||||
}
|
||||
|
||||
protected final boolean addVine(World world, BlockPos pos, ITreeBlockType vine) {
|
||||
return addBlock(world, pos, vine, EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
protected final void addVines(World world, BlockPos pos, float chance) {
|
||||
if (chance <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (world.rand.nextFloat() < chance) {
|
||||
addVine(world, pos.add(-1, 0, 0), vineWest);
|
||||
}
|
||||
if (world.rand.nextFloat() < chance) {
|
||||
addVine(world, pos.add(1, 0, 0), vineEast);
|
||||
}
|
||||
if (world.rand.nextFloat() < chance) {
|
||||
addVine(world, pos.add(0, 0, -1), vineNorth);
|
||||
}
|
||||
if (world.rand.nextFloat() < chance) {
|
||||
addVine(world, pos.add(0, 0, 1), vineSouth);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,10 +10,17 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenBalsa extends WorldGenTree {
|
||||
|
||||
@@ -21,30 +28,31 @@ public class WorldGenBalsa extends WorldGenTree {
|
||||
super(tree, 6, 6);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth);
|
||||
|
||||
int leafSpawn = height;
|
||||
float leafRadius = (girth - 1.0f) / 2.0f;
|
||||
|
||||
addLeaf(world, new BlockPos(0, leafSpawn--, 0), EnumReplaceMode.AIR);
|
||||
generateAdjustedCylinder(world, leafSpawn--, leafRadius, 1, leaf);
|
||||
|
||||
if (height > 10) {
|
||||
generateAdjustedCylinder(world, leafSpawn--, leafRadius, 1, leaf);
|
||||
}
|
||||
|
||||
leafSpawn--;
|
||||
|
||||
while (leafSpawn > 6) {
|
||||
generateAdjustedCylinder(world, leafSpawn, leafRadius, 1, leaf);
|
||||
leafSpawn--;
|
||||
}
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
BlockPos.MutableBlockPos leafCenter = new BlockPos.MutableBlockPos(startPos.add(0, height, 0));
|
||||
float leafRadius = (girth - 1.0f) / 2.0f;
|
||||
|
||||
WorldGenHelper.addBlock(world, leafCenter, leaf, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
leafCenter.offsetMutable(EnumFacing.DOWN);
|
||||
WorldGenHelper.generateCylinderFromPos(world, leaf, leafCenter, leafRadius + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
leafCenter.offsetMutable(EnumFacing.DOWN);
|
||||
|
||||
if (height > 10) {
|
||||
WorldGenHelper.generateCylinderFromPos(world, leaf, leafCenter, leafRadius + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
leafCenter.offsetMutable(EnumFacing.DOWN);
|
||||
}
|
||||
|
||||
while (leafCenter.getY() > 6) {
|
||||
WorldGenHelper.generateCylinderFromPos(world, leaf, leafCenter, leafRadius + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
leafCenter.offsetMutable(EnumFacing.DOWN);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,15 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenBaobab extends WorldGenTree {
|
||||
|
||||
@@ -23,63 +26,63 @@ public class WorldGenBaobab extends WorldGenTree {
|
||||
super(tree, 6, 6);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height - 1, girth);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height - 1, girth, 0, 0, null, 0);
|
||||
|
||||
List<BlockPos> branchCoords = generateBranches(world, height, 0, 0, 0, 0.5f, 4, 6);
|
||||
for (BlockPos branchEnd : branchCoords) {
|
||||
generateAdjustedCylinder(world, branchEnd, 0.0f, 2, leaf, EnumReplaceMode.AIR);
|
||||
if (rand.nextFloat() < 0.3f) {
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, wood, startPos.add(0, height - 1, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
} else if (rand.nextBoolean()) {
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, wood, startPos.add(0, height - 1, girth / 2), girth, girth - 1, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
}
|
||||
|
||||
if (world.rand.nextFloat() < 0.3f) {
|
||||
generateCylinder(world, new Vector(0, height - 1, 0), girth, 1, wood, EnumReplaceMode.SOFT);
|
||||
} else if (world.rand.nextBoolean()) {
|
||||
generateCylinder(world, new Vector(0, height - 1, 0), girth - 1, 1, wood, EnumReplaceMode.SOFT);
|
||||
return WorldGenHelper.generateBranches(world, rand, wood, startPos.add(0, height - 2, 0), girth, 0, 0.5f, 4, 6, 1.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
for (BlockPos branchEnd : branchEnds) {
|
||||
WorldGenHelper.generateCylinderFromPos(world, leaf, branchEnd, girth, 2, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
int leafSpawn = height + 1;
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 2f, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1.5f, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1f, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 2f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 1.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn, 0), girth, 1f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
// Add tree top
|
||||
for (int times = 0; times < height / 2; times++) {
|
||||
int h = height - 1 + world.rand.nextInt(4);
|
||||
if (world.rand.nextBoolean() && h < height / 2) {
|
||||
h = height / 2 + world.rand.nextInt(height / 2);
|
||||
int h = height - 1 + rand.nextInt(4);
|
||||
if (rand.nextBoolean() && h < height / 2) {
|
||||
h = height / 2 + rand.nextInt(height / 2);
|
||||
}
|
||||
|
||||
int x_off = -girth + world.rand.nextInt(2 * girth);
|
||||
int y_off = -girth + world.rand.nextInt(2 * girth);
|
||||
int x_off = -girth + rand.nextInt(2 * girth);
|
||||
int y_off = -girth + rand.nextInt(2 * girth);
|
||||
|
||||
Vector center = new Vector(x_off, h, y_off);
|
||||
BlockPos center = new BlockPos(x_off, h, y_off);
|
||||
int radius = 1;
|
||||
if (girth > 1) {
|
||||
radius += world.rand.nextInt(girth - 1);
|
||||
radius += rand.nextInt(girth - 1);
|
||||
}
|
||||
generateSphere(world, center, radius, leaf, EnumReplaceMode.AIR);
|
||||
WorldGenHelper.generateSphere(world, center, radius, leaf, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
// Add some smaller twigs below for flavour
|
||||
for (int times = 0; times < height / 4; times++) {
|
||||
int delim = modifyByHeight(world, 6, 0, height);
|
||||
int h = delim + (delim < height ? world.rand.nextInt(height - delim) : 0);
|
||||
if (world.rand.nextBoolean() && h < height / 2) {
|
||||
h = height / 2 + world.rand.nextInt(height / 2);
|
||||
int h = delim + (delim < height ? rand.nextInt(height - delim) : 0);
|
||||
if (rand.nextBoolean() && h < height / 2) {
|
||||
h = height / 2 + rand.nextInt(height / 2);
|
||||
}
|
||||
int x_off = -1 + world.rand.nextInt(3);
|
||||
int y_off = -1 + world.rand.nextInt(3);
|
||||
int x_off = -1 + rand.nextInt(3);
|
||||
int y_off = -1 + rand.nextInt(3);
|
||||
|
||||
Vector center = new Vector(x_off, h, y_off);
|
||||
int radius = 1 + world.rand.nextInt(2);
|
||||
generateSphere(world, center, radius, leaf, EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
BlockPos center = new BlockPos(x_off, h, y_off);
|
||||
int radius = 1 + rand.nextInt(2);
|
||||
WorldGenHelper.generateSphere(world, center, radius, leaf, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,12 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenCherry extends WorldGenTree {
|
||||
|
||||
@@ -23,28 +27,31 @@ public class WorldGenCherry extends WorldGenTree {
|
||||
super(tree, 4, 4);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
|
||||
int leafSpawn = height + 1;
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf);
|
||||
Set<BlockPos> branchCoords = new HashSet<>();
|
||||
|
||||
int branchHeight = height - 1;
|
||||
int branchWidth = height / 2;
|
||||
while (leafSpawn > 2) {
|
||||
int leafRadius = Math.min(4, branchWidth);
|
||||
List<BlockPos> branchCoords = generateBranches(world, leafSpawn, 0, 0, 0.2f, 0.5f, branchWidth, 1);
|
||||
for (BlockPos branchEnd : branchCoords) {
|
||||
generateAdjustedCircle(world, branchEnd, leafRadius, 3, 2, leaf, 1.0f, EnumReplaceMode.AIR);
|
||||
}
|
||||
leafSpawn -= 2;
|
||||
while (branchHeight > 2) {
|
||||
branchCoords.addAll(WorldGenHelper.generateBranches(world, rand, wood, startPos.add(0, branchHeight, 0), girth, 0.2f, 0.5f, branchWidth, 1, 1.0f));
|
||||
branchHeight -= 2;
|
||||
branchWidth++;
|
||||
}
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
return branchCoords;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
int leafSpawn = height + 1;
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn, 0), girth, (float) 1 + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
for (BlockPos branchEnd : branchEnds) {
|
||||
WorldGenHelper.generateCircle(world, rand, branchEnd, 4, 3, 2, leaf, 1.0f, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,15 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenChestnut extends WorldGenTree {
|
||||
|
||||
@@ -23,34 +26,39 @@ public class WorldGenChestnut extends WorldGenTree {
|
||||
super(tree, 7, 3);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
|
||||
int leafSpawn = height + 1;
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf);
|
||||
|
||||
while (leafSpawn > 4) {
|
||||
generateAdjustedCylinder(world, leafSpawn--, 2f, 1, leaf);
|
||||
}
|
||||
if (world.rand.nextBoolean()) {
|
||||
generateAdjustedCylinder(world, leafSpawn--, 2f, 1, leaf);
|
||||
int branchHeight = 4;
|
||||
if (rand.nextBoolean()) {
|
||||
branchHeight--;
|
||||
}
|
||||
|
||||
int branchRadius = height / 2;
|
||||
|
||||
List<BlockPos> branchCoords = generateBranches(world, leafSpawn, 0, 0, 0.5f, 0.5f, branchRadius, 2);
|
||||
for (BlockPos branchEnd : branchCoords) {
|
||||
generateAdjustedCylinder(world, branchEnd, 1.0f, 2, leaf, EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn, 1.5f, 1, leaf);
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
return WorldGenHelper.generateBranches(world, rand, wood, startPos.add(0, branchHeight, 0), girth, 0.5f, 0.5f, branchRadius, 2, 1.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
int leafSpawn = height + 1;
|
||||
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 0.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
while (leafSpawn > 4) {
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 2f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
}
|
||||
if (rand.nextBoolean()) {
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 2f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
}
|
||||
|
||||
for (BlockPos branchEnd : branchEnds) {
|
||||
WorldGenHelper.generateCylinderFromPos(world, leaf, branchEnd, 1.0f + girth, 2, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn, 0), girth, 1.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
}
|
||||
}
|
||||
@@ -10,57 +10,55 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenCocobolo extends WorldGenTree {
|
||||
|
||||
public WorldGenCocobolo(ITreeGenData tree) {
|
||||
super(tree, 8, 8);
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
List<BlockPos> treeTops = generateTreeTrunk(world, height, girth);
|
||||
|
||||
int leafSpawn = height;
|
||||
|
||||
for (BlockPos treeTop : treeTops) {
|
||||
addLeaf(world, treeTop.add(0, 1, 0), EnumReplaceMode.AIR);
|
||||
}
|
||||
leafSpawn--;
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf);
|
||||
|
||||
if (height > 10) {
|
||||
generateAdjustedCylinder(world, leafSpawn--, 2, 1, leaf);
|
||||
}
|
||||
generateAdjustedCylinder(world, leafSpawn, 0, 1, leaf);
|
||||
|
||||
leafSpawn--;
|
||||
|
||||
while (leafSpawn > 4) {
|
||||
int offset = 1;
|
||||
if (leafSpawn % 2 == 0) {
|
||||
if (world.rand.nextBoolean()) {
|
||||
offset = -1;
|
||||
}
|
||||
generateAdjustedCylinder(world, leafSpawn, offset, offset, 2, 1, leaf, EnumReplaceMode.AIR);
|
||||
} else {
|
||||
if (world.rand.nextBoolean()) {
|
||||
offset = -1;
|
||||
}
|
||||
generateAdjustedCylinder(world, leafSpawn, offset, offset, 0, 1, leaf, EnumReplaceMode.AIR);
|
||||
}
|
||||
leafSpawn--;
|
||||
}
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
return WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
int leafSpawn = height;
|
||||
|
||||
for (BlockPos treeTop : branchEnds) {
|
||||
WorldGenHelper.addBlock(world, treeTop.add(0, 1, 0), leaf, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
leafSpawn--;
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 1 + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
if (height > 10) {
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 2 + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
}
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
leafSpawn--;
|
||||
|
||||
while (leafSpawn > 4) {
|
||||
int offset = 1;
|
||||
if (rand.nextBoolean()) {
|
||||
offset = -1;
|
||||
}
|
||||
|
||||
float radius = (leafSpawn % 2 == 0) ? 2 + girth : girth;
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(offset, leafSpawn, offset), girth, radius, 1, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
|
||||
leafSpawn--;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenDate extends WorldGenTree {
|
||||
|
||||
@@ -20,21 +27,21 @@ public class WorldGenDate extends WorldGenTree {
|
||||
super(tree, 6, 2);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
int leafSpawn = height + 1;
|
||||
|
||||
float radiusMultiplier = height / 6f;
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, radiusMultiplier * 2f, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, radiusMultiplier * 0.5f, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn, 0, 1, leaf);
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, radiusMultiplier * 2f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, radiusMultiplier * 0.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,10 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenEbony extends WorldGenTree {
|
||||
|
||||
@@ -21,22 +27,22 @@ public class WorldGenEbony extends WorldGenTree {
|
||||
super(tree, 10, 4);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
int offset = (girth - 1) / 2;
|
||||
int trunksgenerated = 0;
|
||||
int trunksGenerated = 0;
|
||||
|
||||
for (int x = -offset; x < -offset + girth; x++) {
|
||||
for (int z = -offset; z < -offset + girth; z++) {
|
||||
if (world.rand.nextFloat() < 0.6f) {
|
||||
for (int i = 0; i < height; i++) {
|
||||
addWood(world, new BlockPos(x, i, z), EnumReplaceMode.ALL);
|
||||
if (i > height / 2 && world.rand.nextFloat() < 0.1f * (10 / height)) {
|
||||
if (rand.nextFloat() < 0.6f) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
WorldGenHelper.addBlock(world, startPos.add(x, y, z), wood, WorldGenHelper.EnumReplaceMode.ALL);
|
||||
if (y > height / 2 && rand.nextFloat() < 0.1f * (10 / height)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
trunksgenerated++;
|
||||
trunksGenerated++;
|
||||
} else {
|
||||
for (int i = 0; i < 1; i++) {
|
||||
world.setBlockToAir(new BlockPos(x, i, z));
|
||||
@@ -46,28 +52,27 @@ public class WorldGenEbony extends WorldGenTree {
|
||||
}
|
||||
|
||||
// Generate backup trunk, if we failed to generate any.
|
||||
if (trunksgenerated <= 0) {
|
||||
generateTreeTrunk(world, height, 1, 0.6f);
|
||||
if (trunksGenerated <= 0) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, 1, 0, 0.6f, null, 0);
|
||||
}
|
||||
|
||||
// Add tree top
|
||||
for (int times = 0; times < 2 * height; times++) {
|
||||
int h = 2 * girth + world.rand.nextInt(height - girth);
|
||||
if (world.rand.nextBoolean() && h < height / 2) {
|
||||
h = height / 2 + world.rand.nextInt(height / 2);
|
||||
}
|
||||
|
||||
int x_off = -girth + world.rand.nextInt(2 * girth);
|
||||
int y_off = -girth + world.rand.nextInt(2 * girth);
|
||||
|
||||
Vector center = new Vector(x_off, h, y_off);
|
||||
int radius = 1 + world.rand.nextInt(girth);
|
||||
generateSphere(world, center, radius, leaf, EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
for (int times = 0; times < 2 * height; times++) {
|
||||
int h = 2 * girth + rand.nextInt(height - girth);
|
||||
if (rand.nextBoolean() && h < height / 2) {
|
||||
h = height / 2 + rand.nextInt(height / 2);
|
||||
}
|
||||
|
||||
int x_off = -girth + rand.nextInt(2 * girth);
|
||||
int y_off = -girth + rand.nextInt(2 * girth);
|
||||
|
||||
BlockPos center = new BlockPos(x_off, h, y_off);
|
||||
int radius = 1 + rand.nextInt(girth);
|
||||
WorldGenHelper.generateSphere(world, center, radius, leaf, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenGreenheart extends WorldGenTree {
|
||||
|
||||
@@ -20,39 +27,38 @@ public class WorldGenGreenheart extends WorldGenTree {
|
||||
super(tree, 10, 8);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
|
||||
generateTreeTrunk(world, height, girth, 0.4f);
|
||||
generateSupportStems(world, height, girth, 0.5f, 0.2f);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0.4f, null, 0);
|
||||
WorldGenHelper.generateSupportStems(wood, world, rand, startPos, height, girth, 0.5f, 0.2f);
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
int leafSpawn = height + 1;
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 0.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1.5f, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 1.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
while (leafSpawn > height - 4) {
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1.9f, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 1.9f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
}
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1.5f, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 1.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn, 0), girth, 0.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
// Add some smaller twigs below for flavour
|
||||
for (int times = 0; times < height / 4; times++) {
|
||||
int h = 10 + world.rand.nextInt(height - 10);
|
||||
if (world.rand.nextBoolean() && h < height / 2) {
|
||||
h = height / 2 + world.rand.nextInt(height / 2);
|
||||
int h = 10 + rand.nextInt(height - 10);
|
||||
if (rand.nextBoolean() && h < height / 2) {
|
||||
h = height / 2 + rand.nextInt(height / 2);
|
||||
}
|
||||
int x_off = -1 + world.rand.nextInt(3);
|
||||
int y_off = -1 + world.rand.nextInt(3);
|
||||
generateSphere(world, new Vector(x_off, h, y_off), 1 + world.rand.nextInt(1), leaf, EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
int x_off = -1 + rand.nextInt(3);
|
||||
int y_off = -1 + rand.nextInt(3);
|
||||
WorldGenHelper.generateSphere(world, new BlockPos(x_off, h, y_off), 1 + rand.nextInt(1), leaf, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,13 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenIpe extends WorldGenTree {
|
||||
|
||||
@@ -24,31 +27,34 @@ public class WorldGenIpe extends WorldGenTree {
|
||||
super(tree, 6, 4);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
|
||||
int trunkSpawn = height - 2;
|
||||
float adjustedGirth = girth * .65f;
|
||||
|
||||
Set<BlockPos> branchCoords = new HashSet<>();
|
||||
while (trunkSpawn > 2) {
|
||||
int radius = Math.round(adjustedGirth * (height - trunkSpawn) / 1.5f);
|
||||
branchCoords.addAll(WorldGenHelper.generateBranches(world, rand, wood, startPos.add(0, trunkSpawn, 0), girth, 0.25f, 0.25f, radius, 2, 1.0f));
|
||||
trunkSpawn -= 2;
|
||||
}
|
||||
return branchCoords;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
int leafSpawn = height + 1;
|
||||
float adjustedGirth = girth * .65f;
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0.2f * adjustedGirth, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0.2f * adjustedGirth, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 0.2f * adjustedGirth + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn, 0), girth, 0.2f * adjustedGirth + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
List<BlockPos> branchCoords = new ArrayList<>();
|
||||
while (leafSpawn > 2) {
|
||||
int radius = Math.round(adjustedGirth * (height - leafSpawn) / 1.5f);
|
||||
branchCoords.addAll(generateBranches(world, leafSpawn, 0, 0, 0.25f, 0.25f, radius, 2));
|
||||
leafSpawn -= 2;
|
||||
}
|
||||
|
||||
for (BlockPos branchEnd : branchCoords) {
|
||||
generateAdjustedCylinder(world, branchEnd, 2.0f, 2, leaf, EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
for (BlockPos branchEnd : branchEnds) {
|
||||
WorldGenHelper.generateCylinderFromPos(world, leaf, branchEnd, 2.0f + girth, 2, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,13 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
/**
|
||||
* This is a dummy and needs to be replaced with something proper.
|
||||
@@ -27,41 +30,48 @@ public class WorldGenJungle extends WorldGenTreeVanilla {
|
||||
super(tree);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
int height = this.height;
|
||||
float vinesChance = 0.0f;
|
||||
if (girth >= 2) {
|
||||
height *= 1.5f;
|
||||
vinesChance = 0.8f;
|
||||
}
|
||||
|
||||
generateTreeTrunk(world, height, girth, vinesChance);
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, vinesChance, null, 0);
|
||||
|
||||
Set<BlockPos> branchCoords = new HashSet<>();
|
||||
if (height > 10) {
|
||||
List<BlockPos> branchCoords = new ArrayList<>();
|
||||
int branchSpawn = 6;
|
||||
while (branchSpawn < height - 2) {
|
||||
branchCoords.addAll(generateBranches(world, branchSpawn, 0, 0, 0.5f, 0f, 2, 1, 0.25f));
|
||||
branchSpawn += world.rand.nextInt(4);
|
||||
branchCoords.addAll(WorldGenHelper.generateBranches(world, rand, wood, startPos.add(0, branchSpawn, 0), girth, 0.5f, 0f, 2, 1, 0.25f));
|
||||
branchSpawn += rand.nextInt(4);
|
||||
}
|
||||
}
|
||||
|
||||
for (BlockPos branchEnd : branchCoords) {
|
||||
generateAdjustedCylinder(world, branchEnd, 0f, 1, leaf, EnumReplaceMode.AIR);
|
||||
}
|
||||
return branchCoords;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
int height = this.height;
|
||||
if (girth >= 2) {
|
||||
height *= 1.5f;
|
||||
}
|
||||
|
||||
for (BlockPos branchEnd : branchEnds) {
|
||||
WorldGenHelper.generateCylinderFromPos(world, leaf, branchEnd, girth, 1, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
int leafSpawn = height + 1;
|
||||
float canopyRadiusMultiplier = height / 7.0f;
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0.5f * canopyRadiusMultiplier, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 0.5f * canopyRadiusMultiplier + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1.9f * canopyRadiusMultiplier, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn, 1.9f * canopyRadiusMultiplier, 1, leaf);
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 1.9f * canopyRadiusMultiplier + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn, 0), girth, 1.9f * canopyRadiusMultiplier + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,13 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenKapok extends WorldGenTree {
|
||||
|
||||
@@ -24,44 +27,45 @@ public class WorldGenKapok extends WorldGenTree {
|
||||
super(tree, 10, 8);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
|
||||
generateTreeTrunk(world, height, girth, 0.6f);
|
||||
generateSupportStems(world, height, girth, 0.8f, 0.4f);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0.6f, null, 0);
|
||||
WorldGenHelper.generateSupportStems(wood, world, rand, startPos, height, girth, 0.8f, 0.4f);
|
||||
|
||||
Set<BlockPos> branchCoords = new HashSet<>();
|
||||
int leafSpawn = height + 1;
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf);
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1.9f, 1, leaf);
|
||||
|
||||
List<BlockPos> branchCoords = new ArrayList<>();
|
||||
while (leafSpawn > height - 4) {
|
||||
int radius = Math.round(girth * (height - leafSpawn) / 1.5f) + 6;
|
||||
branchCoords.addAll(generateBranches(world, leafSpawn, 0, 0, 0.3f, 0.25f, radius, 6));
|
||||
branchCoords.addAll(WorldGenHelper.generateBranches(world, rand, wood, startPos.add(0, leafSpawn, 0), girth, 0.3f, 0.25f, radius, 6, 1.0f));
|
||||
leafSpawn -= 2;
|
||||
}
|
||||
|
||||
for (BlockPos branchEnd : branchCoords) {
|
||||
generateAdjustedCylinder(world, branchEnd.getY() + 1, branchEnd.getX(), branchEnd.getZ(), 2.0f, 2, leaf, EnumReplaceMode.AIR);
|
||||
return branchCoords;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
int leafSpawn = height + 1;
|
||||
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 0.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn, 0), girth, 1.9f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
for (BlockPos branchEnd : branchEnds) {
|
||||
WorldGenHelper.generateCylinderFromPos(world, leaf, branchEnd.up(), 2.0f + girth, 2, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
// Add some smaller twigs below for flavour
|
||||
for (int times = 0; times < height / 4; times++) {
|
||||
int h = 10 + world.rand.nextInt(Math.max(1, height - 10));
|
||||
if (world.rand.nextBoolean() && h < height / 2) {
|
||||
h = height / 2 + world.rand.nextInt(height / 2);
|
||||
int h = 10 + rand.nextInt(Math.max(1, height - 10));
|
||||
if (rand.nextBoolean() && h < height / 2) {
|
||||
h = height / 2 + rand.nextInt(height / 2);
|
||||
}
|
||||
int x_off = -1 + world.rand.nextInt(3);
|
||||
int y_off = -1 + world.rand.nextInt(3);
|
||||
generateSphere(world, new Vector(x_off, h, y_off), 1 + world.rand.nextInt(1), leaf, EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
int x_off = -1 + rand.nextInt(3);
|
||||
int y_off = -1 + rand.nextInt(3);
|
||||
WorldGenHelper.generateSphere(world, new BlockPos(x_off, h, y_off), 1 + rand.nextInt(1), leaf, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,9 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenLarch extends WorldGenTree {
|
||||
|
||||
@@ -20,25 +27,25 @@ public class WorldGenLarch extends WorldGenTree {
|
||||
super(tree, 6, 5);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
int leafSpawn = height + 1;
|
||||
|
||||
float sizeMultiplier = Math.max(height / 8, 1.0f);
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, sizeMultiplier, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, sizeMultiplier + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
while (leafSpawn > 2) {
|
||||
generateAdjustedCylinder(world, leafSpawn--, 2 * sizeMultiplier, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, sizeMultiplier, 1, leaf);
|
||||
}
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 2 * sizeMultiplier + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, sizeMultiplier + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,9 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenLemon extends WorldGenTree {
|
||||
|
||||
@@ -20,21 +27,21 @@ public class WorldGenLemon extends WorldGenTree {
|
||||
super(tree, 6, 3);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
int yCenter = height - girth;
|
||||
yCenter = yCenter > 2 ? yCenter : 3;
|
||||
int radius = Math.round((2 + world.rand.nextInt(girth)) * (height / 4.0f));
|
||||
int radius = Math.round((2 + rand.nextInt(girth)) * (height / 4.0f));
|
||||
if (radius > 4) {
|
||||
radius = 4;
|
||||
}
|
||||
generateSphere(world, getCenteredAt(yCenter, 0, 0), radius, leaf, EnumReplaceMode.AIR);
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
WorldGenHelper.generateSphereFromTreeStartPos(world, startPos.add(0, yCenter, 0), girth, radius, leaf, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,13 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenMahoe extends WorldGenTree {
|
||||
|
||||
@@ -24,25 +27,27 @@ public class WorldGenMahoe extends WorldGenTree {
|
||||
super(tree, 6, 3);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
Set<BlockPos> branchCoords = new HashSet<>();
|
||||
|
||||
branchCoords.addAll(WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0));
|
||||
|
||||
List<BlockPos> branchCoords = new ArrayList<>();
|
||||
for (int yBranch = 2; yBranch < height - 1; yBranch++) {
|
||||
branchCoords.addAll(generateBranches(world, yBranch, 0, 0, 0.15f, 0.25f, Math.round((height - yBranch) * 0.75f), 1, 0.25f));
|
||||
branchCoords.addAll(WorldGenHelper.generateBranches(world, rand, wood, startPos.add(0, yBranch, 0), girth, 0.15f, 0.25f, Math.round((height - yBranch) * 0.75f), 1, 0.25f));
|
||||
}
|
||||
for (BlockPos branchEnd : branchCoords) {
|
||||
generateAdjustedCylinder(world, branchEnd, 2, 2, leaf, EnumReplaceMode.AIR);
|
||||
return branchCoords;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
for (BlockPos branchEnd : branchEnds) {
|
||||
WorldGenHelper.generateCylinderFromPos(world, leaf, branchEnd, 2 + girth, 2, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
int yCenter = height - girth;
|
||||
yCenter = yCenter > 3 ? yCenter : 4;
|
||||
generateSphere(world, getCenteredAt(yCenter, 0, 0), 3 + world.rand.nextInt(girth), leaf, EnumReplaceMode.AIR);
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
WorldGenHelper.generateSphereFromTreeStartPos(world, new BlockPos(0, yCenter, 0), girth, 3 + rand.nextInt(girth), leaf, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,13 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenMahogany extends WorldGenTree {
|
||||
|
||||
@@ -24,33 +27,34 @@ public class WorldGenMahogany extends WorldGenTree {
|
||||
super(tree, 12, 6);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth, 0.6f);
|
||||
generateSupportStems(world, height, girth, 0.4f, 0.4f);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0.6f, null, 0);
|
||||
WorldGenHelper.generateSupportStems(wood, world, rand, startPos, height, girth, 0.4f, 0.4f);
|
||||
|
||||
List<BlockPos> branchCoords = new ArrayList<>();
|
||||
Set<BlockPos> branchEnds = new HashSet<>();
|
||||
for (int yBranch = height - 4; yBranch < height - 2; yBranch++) {
|
||||
branchCoords.addAll(generateBranches(world, yBranch, 0, 0, 0.15f, 0.25f, Math.round((height - yBranch) * 0.5f), 1, 0.25f));
|
||||
branchEnds.addAll(WorldGenHelper.generateBranches(world, rand, wood, startPos.add(0, yBranch, 0), girth, 0.15f, 0.25f, Math.round((height - yBranch) * 0.5f), 1, 0.25f));
|
||||
}
|
||||
for (BlockPos branchEnd : branchCoords) {
|
||||
generateAdjustedCylinder(world, branchEnd, 2, 2, leaf, EnumReplaceMode.AIR);
|
||||
return branchEnds;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
for (BlockPos branchEnd : branchEnds) {
|
||||
WorldGenHelper.generateCylinderFromPos(world, leaf, branchEnd, 2 + girth, 2, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
int leafSpawn = height + 1;
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1.5f, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 2f, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 1.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 2f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 3f, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 3f, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 2f, 1, leaf);
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 3f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 3f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn, 0), girth, 2f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,13 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenMaple extends WorldGenTree {
|
||||
|
||||
@@ -24,34 +27,35 @@ public class WorldGenMaple extends WorldGenTree {
|
||||
super(tree, 7, 5);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
|
||||
List<BlockPos> branchCoords = new ArrayList<>();
|
||||
Set<BlockPos> branchCoords = new HashSet<>();
|
||||
for (int yBranch = 2; yBranch < height - 2; yBranch++) {
|
||||
branchCoords.addAll(generateBranches(world, yBranch, 0, 0, 0.15f, 0.25f, Math.round((height - yBranch) * 0.25f), 1, 0.25f));
|
||||
branchCoords.addAll(WorldGenHelper.generateBranches(world, rand, wood, startPos.add(0, yBranch, 0), girth, 0.15f, 0.25f, Math.round((height - yBranch) * 0.25f), 1, 0.25f));
|
||||
}
|
||||
for (BlockPos branchEnd : branchCoords) {
|
||||
generateAdjustedCylinder(world, branchEnd, 2, 2, leaf, EnumReplaceMode.AIR);
|
||||
return branchCoords;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
for (BlockPos branchEnd : branchEnds) {
|
||||
WorldGenHelper.generateCylinderFromPos(world, leaf, branchEnd, 2 + girth, 2, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
int leafSpawn = height + 1;
|
||||
float diameterchange = (float) 1 / height;
|
||||
int leafSpawned = 2;
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, (float) 1 + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
while (leafSpawn > 1) {
|
||||
generateAdjustedCylinder(world, leafSpawn--, 3 * diameterchange * leafSpawned, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 2 * diameterchange * leafSpawned, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 3 * diameterchange * leafSpawned + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 2 * diameterchange * leafSpawned + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
leafSpawned += 2;
|
||||
}
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,13 +10,17 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenPadauk extends WorldGenTree {
|
||||
|
||||
@@ -24,55 +28,67 @@ public class WorldGenPadauk extends WorldGenTree {
|
||||
super(tree, 6, 6);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
|
||||
int leafSpawn = height + 1;
|
||||
int branchSpawn = height - 2;
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1.5f, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 3f, 1, leaf);
|
||||
|
||||
int count = 0;
|
||||
int max = 3;
|
||||
int min = 1;
|
||||
int canopyHeight = world.rand.nextInt(max - min + 1) + min;
|
||||
|
||||
while (leafSpawn > 3 && count < canopyHeight) {
|
||||
generateAdjustedCylinder(world, leafSpawn--, 4.5f, 1, leaf);
|
||||
int canopyHeight = rand.nextInt(max - min + 1) + min;
|
||||
|
||||
while (branchSpawn > 3 && count < canopyHeight) {
|
||||
count++;
|
||||
//Random Trunk Branches
|
||||
for (int i = 0; i < girth * 4; i++) {
|
||||
if (world.rand.nextBoolean()) {
|
||||
|
||||
if (rand.nextBoolean()) {
|
||||
|
||||
int[] offset = {-1, 1};
|
||||
int offsetValue = offset[new Random().nextInt(offset.length)];
|
||||
int maxBranchLength = 3;
|
||||
int branchLength = new Random().nextInt(maxBranchLength + 1);
|
||||
EnumFacing[] direction = {EnumFacing.NORTH, EnumFacing.EAST};
|
||||
EnumFacing directionValue = direction[new Random().nextInt(direction.length)];
|
||||
int branchSpawn = leafSpawn;
|
||||
int branchSpawnY = branchSpawn;
|
||||
|
||||
for (int j = 1; j < branchLength + 1; j++) {
|
||||
if (j == branchLength && world.rand.nextBoolean()) { //Just adding a bit of variation to the ends for character
|
||||
branchSpawn += 1;
|
||||
if (j == branchLength && rand.nextBoolean()) { //Just adding a bit of variation to the ends for character
|
||||
branchSpawnY += 1;
|
||||
}
|
||||
|
||||
wood.setDirection(directionValue);
|
||||
if (directionValue == EnumFacing.NORTH) {
|
||||
addWood(world, new BlockPos(0, branchSpawn, j * offsetValue), EnumReplaceMode.ALL);
|
||||
WorldGenHelper.addBlock(world, startPos.add(0, branchSpawnY, j * offsetValue), wood, WorldGenHelper.EnumReplaceMode.ALL);
|
||||
} else if (directionValue == EnumFacing.EAST) {
|
||||
addWood(world, new BlockPos(j * offsetValue, branchSpawn, 0), EnumReplaceMode.ALL);
|
||||
WorldGenHelper.addBlock(world, startPos.add(j * offsetValue, branchSpawnY, 0), wood, WorldGenHelper.EnumReplaceMode.ALL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
int leafSpawn = height + 1;
|
||||
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 1.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 3f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
int count = 0;
|
||||
int max = 3;
|
||||
int min = 1;
|
||||
int canopyHeight = rand.nextInt(max - min + 1) + min;
|
||||
|
||||
while (leafSpawn > 3 && count < canopyHeight) {
|
||||
int yCenter = leafSpawn--;
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, yCenter, 0), girth, 4.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,15 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenPapaya extends WorldGenTree {
|
||||
|
||||
@@ -23,22 +26,21 @@ public class WorldGenPapaya extends WorldGenTree {
|
||||
super(tree, 7, 2);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
return WorldGenHelper.generateBranches(world, rand, wood, startPos.add(0, height, 0), girth, 0.15f, 0.25f, height / 4, 1, 0.25f);
|
||||
}
|
||||
|
||||
List<BlockPos> branchCoords = generateBranches(world, height, 0, 0, 0.15f, 0.25f, height / 4, 1, 0.25f);
|
||||
for (BlockPos branchEnd : branchCoords) {
|
||||
generateAdjustedCylinder(world, branchEnd, 1, 1, leaf, EnumReplaceMode.AIR);
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
for (BlockPos branchEnd : branchEnds) {
|
||||
WorldGenHelper.generateCylinderFromPos(world, leaf, branchEnd, 1 + girth, 1, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
int yCenter = height - girth;
|
||||
yCenter = yCenter > 3 ? yCenter : 4;
|
||||
generateSphere(world, getCenteredAt(yCenter, 0, 0), Math.round((2 + world.rand.nextInt(girth)) * (height / 8.0f)), leaf, EnumReplaceMode.AIR);
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
WorldGenHelper.generateSphereFromTreeStartPos(world, startPos.add(0, yCenter, 0), girth, Math.round((2 + rand.nextInt(girth)) * (height / 8.0f)), leaf, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,13 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenPine extends WorldGenTree {
|
||||
|
||||
@@ -24,34 +27,35 @@ public class WorldGenPine extends WorldGenTree {
|
||||
super(tree, 6, 4);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
|
||||
List<BlockPos> branchCoords = new ArrayList<>();
|
||||
Set<BlockPos> branchEnds = new HashSet<>();
|
||||
for (int yBranch = 2; yBranch < height - 2; yBranch++) {
|
||||
branchCoords.addAll(generateBranches(world, yBranch, 0, 0, 0.05f, 0.1f, Math.round((height - yBranch) * 0.25f), 1, 0.25f));
|
||||
branchEnds.addAll(WorldGenHelper.generateBranches(world, rand, wood, startPos.add(0, yBranch, 0), girth, 0.05f, 0.1f, Math.round((height - yBranch) * 0.25f), 1, 0.25f));
|
||||
}
|
||||
for (BlockPos branchEnd : branchCoords) {
|
||||
generateAdjustedCylinder(world, branchEnd, 2, 1, leaf, EnumReplaceMode.AIR);
|
||||
return branchEnds;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
for (BlockPos branchEnd : branchEnds) {
|
||||
WorldGenHelper.generateCylinderFromPos(world, leaf, branchEnd, 2 + girth, 1, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
int leafSpawn = height + 1;
|
||||
float diameterchange = 1.25f / height;
|
||||
int leafSpawned = 2;
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, (float) 1 + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
while (leafSpawn > 1) {
|
||||
generateAdjustedCylinder(world, leafSpawn--, 3 * diameterchange * leafSpawned, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 2 * diameterchange * leafSpawned, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 3 * diameterchange * leafSpawned + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 2 * diameterchange * leafSpawned + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
leafSpawned += 2;
|
||||
}
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,9 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenPlum extends WorldGenTree {
|
||||
|
||||
@@ -20,23 +27,22 @@ public class WorldGenPlum extends WorldGenTree {
|
||||
super(tree, 6, 3);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
int yCenter = height - girth;
|
||||
yCenter = yCenter > 2 ? yCenter : 3;
|
||||
|
||||
Vector center = getCenteredAt(yCenter, 0, 0);
|
||||
int radius = Math.round((2 + world.rand.nextInt(girth)) * (height / 4.0f));
|
||||
int radius = Math.round((2 + rand.nextInt(girth)) * (height / 4.0f));
|
||||
if (radius > 4) {
|
||||
radius = 4;
|
||||
}
|
||||
generateSphere(world, center, radius, leaf, EnumReplaceMode.AIR);
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
WorldGenHelper.generateSphereFromTreeStartPos(world, startPos.add(0, yCenter, 0), girth, radius, leaf, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,9 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenPoplar extends WorldGenTree {
|
||||
|
||||
@@ -20,20 +27,20 @@ public class WorldGenPoplar extends WorldGenTree {
|
||||
super(tree, 8, 3);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
int leafSpawn = height + 1;
|
||||
float leafRadius = (girth - 1.0f) / 2.0f;
|
||||
|
||||
while (leafSpawn > girth - 1) {
|
||||
generateAdjustedCylinder(world, leafSpawn--, leafRadius, 1, leaf);
|
||||
}
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, leafRadius + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,13 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenSequoia extends WorldGenTree {
|
||||
|
||||
@@ -28,40 +31,42 @@ public class WorldGenSequoia extends WorldGenTree {
|
||||
super(tree, baseHeight, heightVariation);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth);
|
||||
generateSupportStems(world, height, girth, 0.4f, 0.4f);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
WorldGenHelper.generateSupportStems(wood, world, rand, startPos, height, girth, 0.4f, 0.4f);
|
||||
|
||||
int topHeight = height / 3 + world.rand.nextInt(height / 6);
|
||||
int topHeight = height / 3 + rand.nextInt(height / 6);
|
||||
|
||||
List<BlockPos> branchCoords = new ArrayList<>();
|
||||
Set<BlockPos> branchCoords = new HashSet<>();
|
||||
for (int yBranch = topHeight; yBranch < height; yBranch++) {
|
||||
int branchLength = Math.round(height - yBranch) / 2;
|
||||
if (branchLength > 4) {
|
||||
branchLength = 4;
|
||||
}
|
||||
branchCoords.addAll(generateBranches(world, yBranch, 0, 0, 0.05f, 0.25f, branchLength, 1, 0.5f));
|
||||
branchCoords.addAll(WorldGenHelper.generateBranches(world, rand, wood, startPos.add(0, yBranch, 0), girth, 0.05f, 0.25f, branchLength, 1, 0.5f));
|
||||
}
|
||||
for (BlockPos branchEnd : branchCoords) {
|
||||
generateAdjustedCylinder(world, branchEnd, 1.0f, 1, leaf, EnumReplaceMode.AIR);
|
||||
return branchCoords;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
for (BlockPos branchEnd : branchEnds) {
|
||||
WorldGenHelper.generateCylinderFromPos(world, leaf, branchEnd, 1.0f + girth, 1, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
int leafSpawn = height + 2;
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 1 + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 1 + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
int topHeight = height / 3 + rand.nextInt(height / 6);
|
||||
while (leafSpawn > topHeight) {
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 1 + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
}
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn, 0, 1, leaf);
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,12 +10,15 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenSilverLime extends WorldGenTree {
|
||||
|
||||
@@ -23,26 +26,27 @@ public class WorldGenSilverLime extends WorldGenTree {
|
||||
super(tree, 6, 4);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth);
|
||||
List<BlockPos> branchCoords = generateBranches(world, 3 + world.rand.nextInt(1), 0, 0, 0.25f, 0.10f, Math.round(height * 0.25f), 2, 0.5f);
|
||||
for (BlockPos branchEnd : branchCoords) {
|
||||
generateAdjustedCylinder(world, branchEnd, 0, 1, leaf, EnumReplaceMode.AIR);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
BlockPos pos = startPos.add(0, 3 + rand.nextInt(1), 0);
|
||||
return WorldGenHelper.generateBranches(world, rand, wood, pos, girth, 0.25f, 0.10f, Math.round(height * 0.25f), 2, 0.5f);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
for (BlockPos branchEnd : branchEnds) {
|
||||
WorldGenHelper.generateCylinderFromPos(world, leaf, branchEnd, girth, 1, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
int leafSpawn = height + 1;
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
float radius = 1;
|
||||
while (leafSpawn > 1) {
|
||||
generateAdjustedCylinder(world, leafSpawn--, radius, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, radius + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
radius += 0.25;
|
||||
}
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,12 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenSpruce extends WorldGenTree {
|
||||
|
||||
@@ -23,30 +27,36 @@ public class WorldGenSpruce extends WorldGenTree {
|
||||
super(tree, 5, 3);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
|
||||
int leafSpawn = height + 1;
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf);
|
||||
Set<BlockPos> branchEnds = new HashSet<>();
|
||||
|
||||
int branchSpawn = height - 1;
|
||||
int branchWidth = height / 4;
|
||||
while (leafSpawn > 2) {
|
||||
int leafRadius = Math.min(4, branchWidth);
|
||||
List<BlockPos> branchCoords = generateBranches(world, leafSpawn, 0, 0, 0.2f, 0.5f, branchWidth, 1);
|
||||
for (BlockPos branchEnd : branchCoords) {
|
||||
generateAdjustedCircle(world, branchEnd, leafRadius, 3, 2, leaf, 1.0f, EnumReplaceMode.SOFT);
|
||||
}
|
||||
generateAdjustedCylinder(world, leafSpawn--, 2, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1, 1, leaf);
|
||||
while (branchSpawn > 2) {
|
||||
branchEnds.addAll(WorldGenHelper.generateBranches(world, rand, wood, startPos.add(0, branchSpawn, 0), girth, 0.2f, 0.5f, branchWidth, 1, 1.0f));
|
||||
branchSpawn -= 2;
|
||||
branchWidth++;
|
||||
}
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
return branchEnds;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
int leafSpawn = height + 1;
|
||||
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, (float) 1 + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
int leafRadius = 4;
|
||||
for (BlockPos branchEnd : branchEnds) {
|
||||
WorldGenHelper.generateCircle(world, rand, branchEnd, leafRadius, 3, 2, leaf, 1.0f, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
}
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, (float) 2 + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn, 0), girth, (float) 1 + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,15 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenTeak extends WorldGenTree {
|
||||
|
||||
@@ -23,36 +26,38 @@ public class WorldGenTeak extends WorldGenTree {
|
||||
super(tree, 6, 3);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
|
||||
int branchWidth = height / 3;
|
||||
|
||||
return WorldGenHelper.generateBranches(world, rand, wood, startPos.add(0, height - 3, 0), girth, 0.2f, 0.5f, branchWidth, 1, 1.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
float leafMultiplier = height / 6.0f;
|
||||
if (leafMultiplier > 2) {
|
||||
leafMultiplier = 2;
|
||||
}
|
||||
int branchWidth = height / 3;
|
||||
List<BlockPos> branchCoords = generateBranches(world, height - 3, 0, 0, 0.2f, 0.5f, branchWidth, 1);
|
||||
for (BlockPos branchEnd : branchCoords) {
|
||||
generateAdjustedCircle(world, branchEnd, 2, Math.round(3 * leafMultiplier), 2, leaf, 1.0f, EnumReplaceMode.AIR);
|
||||
|
||||
for (BlockPos branchEnd : branchEnds) {
|
||||
WorldGenHelper.generateCircle(world, rand, branchEnd, 2, Math.round(3 * leafMultiplier), 2, leaf, 1.0f, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
int leafSpawn = height + 1;
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0.5f * leafMultiplier, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 0.5f * leafMultiplier + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1.9f * leafMultiplier, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1.9f * leafMultiplier, 1, leaf);
|
||||
if (world.rand.nextBoolean()) {
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1.9f * leafMultiplier, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 1.9f * leafMultiplier + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 1.9f * leafMultiplier + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
if (rand.nextBoolean()) {
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 1.9f * leafMultiplier + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
}
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn, 0.5f * leafMultiplier, 1, leaf);
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn, 0), girth, 0.5f * leafMultiplier + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,14 +10,19 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.arboriculture.ITreeModifier;
|
||||
import forestry.api.arboriculture.TreeManager;
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public abstract class WorldGenTree extends WorldGenArboriculture {
|
||||
private static final int minHeight = 4;
|
||||
@@ -35,70 +40,39 @@ public abstract class WorldGenTree extends WorldGenArboriculture {
|
||||
this.heightVariation = heightVariation;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
int leafSpawn = height + 1;
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf, EnumReplaceMode.AIR);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf, EnumReplaceMode.AIR);
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1.9f, 1, leaf, EnumReplaceMode.AIR);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1.9f, 1, leaf, EnumReplaceMode.AIR);
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
int leafHeight = height + 1;
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafHeight--, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafHeight--, 0), girth, 0.5f + girth, 1, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafHeight--, 0), girth, 1.9f + girth, 1, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafHeight, 0), girth, 1.9f + girth, 1, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateExtras(World world, Random rand, BlockPos startPos) {
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
WorldGenHelper.generatePods(tree, world, rand, startPos, height, minPodHeight, girth, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
protected Vector getCenteredAt(int yCenter, int xOffset, int zOffset) {
|
||||
float cent = girth % 2 == 0 ? 0.5f : 0f;
|
||||
return new Vector(cent + xOffset, yCenter, cent + zOffset);
|
||||
}
|
||||
|
||||
protected Vector getCenteredAt(BlockPos centerPos) {
|
||||
float cent = girth % 2 == 0 ? 0.5f : 0f;
|
||||
return new Vector(cent + centerPos.getX(), centerPos.getY(), cent + centerPos.getZ());
|
||||
}
|
||||
|
||||
protected void generateAdjustedCylinder(World world, int yCenter, float radius, int height, ITreeBlockType block) {
|
||||
generateAdjustedCylinder(world, yCenter, 0, 0, radius, height, block, EnumReplaceMode.SOFT);
|
||||
}
|
||||
|
||||
protected void generateAdjustedCylinder(World world, int yCenter, float radius, int height, ITreeBlockType block, EnumReplaceMode replace) {
|
||||
generateAdjustedCylinder(world, yCenter, 0, 0, radius, height, block, replace);
|
||||
}
|
||||
|
||||
protected void generateAdjustedCylinder(World world, int yCenter, int xOffset, int zOffset, float radius, int height, ITreeBlockType block, EnumReplaceMode replace) {
|
||||
Vector center = getCenteredAt(yCenter, xOffset, zOffset);
|
||||
generateCylinder(world, center, radius + girth, height, block, replace);
|
||||
}
|
||||
|
||||
protected void generateAdjustedCylinder(World world, BlockPos centerPos, float radius, int height, ITreeBlockType block, EnumReplaceMode replace) {
|
||||
Vector center = getCenteredAt(centerPos);
|
||||
generateCylinder(world, center, radius + girth, height, block, replace);
|
||||
}
|
||||
|
||||
protected void generateAdjustedCircle(World world, int yCenter, int xOffset, int zOffset, float radius, int width, int height, ITreeBlockType block, float chance, EnumReplaceMode replace) {
|
||||
Vector center = getCenteredAt(yCenter, xOffset, zOffset);
|
||||
generateCircle(world, center, radius, width, height, block, chance, replace);
|
||||
}
|
||||
|
||||
protected void generateAdjustedCircle(World world, BlockPos centerPos, float radius, int width, int height, ITreeBlockType block, float chance, EnumReplaceMode replace) {
|
||||
Vector center = getCenteredAt(centerPos);
|
||||
generateCircle(world, center, radius, width, height, block, chance, replace);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canGrow(World world, BlockPos pos) {
|
||||
@Nullable
|
||||
public BlockPos getValidGrowthPos(World world, BlockPos pos) {
|
||||
return tree.canGrow(world, pos, girth, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void preGenerate(World world, BlockPos startPos) {
|
||||
super.preGenerate(world, startPos);
|
||||
height = determineHeight(world, baseHeight, heightVariation);
|
||||
public final void preGenerate(World world, Random rand, BlockPos startPos) {
|
||||
super.preGenerate(world, rand, startPos);
|
||||
height = determineHeight(world, rand, baseHeight, heightVariation);
|
||||
girth = tree.getGirth(world, startPos);
|
||||
}
|
||||
|
||||
@@ -108,21 +82,10 @@ public abstract class WorldGenTree extends WorldGenArboriculture {
|
||||
return determined < min ? min : determined > max ? max : determined;
|
||||
}
|
||||
|
||||
private int determineHeight(World world, int required, int variation) {
|
||||
private int determineHeight(World world, Random rand, int required, int variation) {
|
||||
ITreeModifier treeModifier = TreeManager.treeRoot.getTreekeepingMode(world);
|
||||
int baseHeight = required + world.rand.nextInt(variation);
|
||||
int baseHeight = required + rand.nextInt(variation);
|
||||
int height = Math.round(baseHeight * tree.getHeightModifier() * treeModifier.getHeightModifier(tree.getGenome(), 1f));
|
||||
return height < minHeight ? minHeight : height > maxHeight ? maxHeight : height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeBlockTypeLeaf getLeaf(GameProfile owner) {
|
||||
return new TreeBlockTypeLeaf(owner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITreeBlockType getWood() {
|
||||
return new TreeBlockTypeLog();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,12 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenWalnut extends WorldGenTree {
|
||||
|
||||
@@ -23,32 +27,42 @@ public class WorldGenWalnut extends WorldGenTree {
|
||||
super(tree, 7, 3);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
|
||||
Set<BlockPos> branchEnds = new HashSet<>();
|
||||
|
||||
int branchHeight = height - 3;
|
||||
float branchSize = 2;
|
||||
while (branchHeight >= 3) {
|
||||
branchEnds.addAll(WorldGenHelper.generateBranches(world, rand, wood, startPos.add(0, branchHeight, 0), girth, 0.2f, 0.2f, (int) branchSize, 1, 0.5f));
|
||||
branchHeight--;
|
||||
branchSize += 0.25f;
|
||||
}
|
||||
|
||||
return branchEnds;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
int leafSpawn = height + 1;
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 0.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1.5f, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 2f, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 1.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 2f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
float branchSize = 2;
|
||||
while (leafSpawn >= 3) {
|
||||
int leafRadius = Math.min(4, (int) branchSize);
|
||||
List<BlockPos> branchCoords = generateBranches(world, leafSpawn, 0, 0, 0.2f, 0.2f, (int) branchSize, 1, 0.5f);
|
||||
for (BlockPos branchEnd : branchCoords) {
|
||||
generateAdjustedCircle(world, branchEnd, leafRadius, 2, 2, leaf, 1.0f, EnumReplaceMode.SOFT);
|
||||
for (BlockPos branchEnd : branchEnds) {
|
||||
WorldGenHelper.generateCircle(world, rand, branchEnd, leafRadius, 2, 2, leaf, 1.0f, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
}
|
||||
leafSpawn--;
|
||||
branchSize += 0.25f;
|
||||
}
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,12 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenWenge extends WorldGenTree {
|
||||
|
||||
@@ -23,33 +27,41 @@ public class WorldGenWenge extends WorldGenTree {
|
||||
super(tree, 6, 2);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
|
||||
int leafSpawn = height + 1;
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf);
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1.5f, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 2f, 1, leaf);
|
||||
Set<BlockPos> branchEnds = new HashSet<>();
|
||||
|
||||
float branchSize = 3;
|
||||
while (leafSpawn > 1) {
|
||||
generateAdjustedCylinder(world, leafSpawn--, 3f, 1, leaf);
|
||||
|
||||
List<BlockPos> branchCoords = generateBranches(world, leafSpawn, 0, 0, 0.2f, 0.2f, (int) branchSize, 2, 0.75f);
|
||||
for (BlockPos branchEnd : branchCoords) {
|
||||
generateAdjustedCircle(world, branchEnd, 3, 3, 2, leaf, 1.0f, EnumReplaceMode.SOFT);
|
||||
}
|
||||
leafSpawn--;
|
||||
int branchHeight = height + 1;
|
||||
while (branchHeight > 1) {
|
||||
branchEnds.addAll(WorldGenHelper.generateBranches(world, rand, wood, startPos.add(0, branchHeight, 0), girth, 0.2f, 0.2f, (int) branchSize, 2, 0.75f));
|
||||
branchHeight--;
|
||||
branchSize += 0.5f;
|
||||
}
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
return branchEnds;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
int leafSpawn = height + 1;
|
||||
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 0.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 1.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 2f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
while (leafSpawn > 1) {
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 3f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
leafSpawn--;
|
||||
}
|
||||
|
||||
for (BlockPos branchEnd : branchEnds) {
|
||||
WorldGenHelper.generateCircle(world, rand, branchEnd, 3, 3, 2, leaf, 1.0f, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenWillow extends WorldGenTree {
|
||||
|
||||
@@ -20,33 +27,40 @@ public class WorldGenWillow extends WorldGenTree {
|
||||
super(tree, 5, 2);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
generateTreeTrunk(world, height, girth, 0.8f);
|
||||
generateSupportStems(world, height, girth, 0.2f, 0.2f);
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0.8f, null, 0);
|
||||
WorldGenHelper.generateSupportStems(wood, world, rand, startPos, height, girth, 0.2f, 0.2f);
|
||||
|
||||
int leafSpawn = height + 1;
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1.5f, 1, leaf);
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 2.5f, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 3f, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 3f, 1, leaf);
|
||||
int leafSpawn = height - 4;
|
||||
while (leafSpawn > 2) {
|
||||
// support branches for tall willows, keeps the leaves from decaying immediately
|
||||
if ((leafSpawn - 3) % 6 == 0) {
|
||||
generateBranches(world, leafSpawn, 0, 0, 0, 0, 2, 1);
|
||||
WorldGenHelper.generateBranches(world, rand, wood, startPos.add(0, leafSpawn, 0), girth, 0, 0, 2, 1, 1.0f);
|
||||
}
|
||||
generateCircle(world, new Vector(0f, leafSpawn--, 0f), 4f, 2, 1, leaf, EnumReplaceMode.AIR);
|
||||
leafSpawn--;
|
||||
}
|
||||
generateCircle(world, new Vector(0f, leafSpawn--, 0f), 4f, 1, 1, leaf, EnumReplaceMode.AIR);
|
||||
generateCircle(world, new Vector(0f, leafSpawn--, 0f), 4f, 1, 1, leaf, EnumReplaceMode.AIR);
|
||||
generateCircle(world, new Vector(0f, leafSpawn, 0f), 4f, 1, 1, leaf, 0.4f, EnumReplaceMode.AIR);
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
}
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
int leafSpawn = height + 1;
|
||||
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 1.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 2.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 3f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 3f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
while (leafSpawn > 2) {
|
||||
WorldGenHelper.generateCircleFromTreeStartPos(world, rand, startPos.add(0, leafSpawn--, 0), girth, 4f, 2, 1, leaf, 1.0f, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
WorldGenHelper.generateCircleFromTreeStartPos(world, rand, startPos.add(0, leafSpawn--, 0), girth, 4f, 1, 1, leaf, 1.0f, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
WorldGenHelper.generateCircleFromTreeStartPos(world, rand, startPos.add(0, leafSpawn--, 0), girth, 4f, 1, 1, leaf, 1.0f, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
WorldGenHelper.generateCircleFromTreeStartPos(world, rand, startPos.add(0, leafSpawn, 0), girth, 4f, 1, 1, leaf, 0.4f, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
}
|
||||
@@ -10,55 +10,58 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.worldgen;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.core.worldgen.WorldGenHelper;
|
||||
|
||||
public class WorldGenZebrawood extends WorldGenTree {
|
||||
|
||||
public WorldGenZebrawood(ITreeGenData tree) {
|
||||
super(tree, 8, 8);
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public void generate(World world) {
|
||||
public Set<BlockPos> generateTrunk(World world, Random rand, TreeBlockTypeLog wood, BlockPos startPos) {
|
||||
WorldGenHelper.generateTreeTrunk(world, rand, wood, startPos, height, girth, 0, 0, null, 0);
|
||||
WorldGenHelper.generateSupportStems(wood, world, rand, startPos, height, girth, 0.8f, 0.3f);
|
||||
|
||||
generateTreeTrunk(world, height, girth);
|
||||
generateSupportStems(world, height, girth, 0.8f, 0.3f);
|
||||
return WorldGenHelper.generateBranches(world, rand, wood, startPos.add(0, height - 4, 0), girth, 0, 0.25f, 3, 2, 0.75f);
|
||||
}
|
||||
|
||||
List<BlockPos> branchCoords = generateBranches(world, height - 4, 0, 0, 0, 0.25f, 3, 2, 0.75f);
|
||||
for (BlockPos branchEnd : branchCoords) {
|
||||
generateAdjustedCylinder(world, branchEnd, 1.0f, 2, leaf, EnumReplaceMode.AIR);
|
||||
@Override
|
||||
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, Set<BlockPos> branchEnds, BlockPos startPos) {
|
||||
for (BlockPos branchEnd : branchEnds) {
|
||||
WorldGenHelper.generateCylinderFromPos(world, leaf, branchEnd, 1.0f + girth, 2, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
int leafSpawn = height + 1;
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0, 1, leaf);
|
||||
generateAdjustedCylinder(world, leafSpawn--, 0.5f, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 0.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
generateAdjustedCylinder(world, leafSpawn--, 1.9f, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 1.9f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
while (leafSpawn > height - 4) {
|
||||
generateAdjustedCylinder(world, leafSpawn--, 2.5f, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 2.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
}
|
||||
generateAdjustedCylinder(world, leafSpawn, 1.9f, 1, leaf);
|
||||
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn, 0), girth, 1.9f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
|
||||
|
||||
// Add some smaller twigs below for flavour
|
||||
for (int times = 0; times < height / 4; times++) {
|
||||
int h = 10 + world.rand.nextInt(Math.max(1, height - 10));
|
||||
if (world.rand.nextBoolean() && h < height / 2) {
|
||||
h = height / 2 + world.rand.nextInt(height / 2);
|
||||
int h = 10 + rand.nextInt(Math.max(1, height - 10));
|
||||
if (rand.nextBoolean() && h < height / 2) {
|
||||
h = height / 2 + rand.nextInt(height / 2);
|
||||
}
|
||||
int x_off = -1 + world.rand.nextInt(3);
|
||||
int y_off = -1 + world.rand.nextInt(3);
|
||||
generateSphere(world, new Vector(x_off, h, y_off), 1 + world.rand.nextInt(1), leaf, EnumReplaceMode.AIR);
|
||||
}
|
||||
|
||||
if (hasPods()) {
|
||||
generatePods(world, height, girth);
|
||||
int x_off = -1 + rand.nextInt(3);
|
||||
int y_off = -1 + rand.nextInt(3);
|
||||
WorldGenHelper.generateSphere(world, startPos.add(x_off, h, y_off), 1 + rand.nextInt(1), leaf, WorldGenHelper.EnumReplaceMode.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IForestryPacketClient;
|
||||
import forestry.core.network.IStreamableGui;
|
||||
import forestry.core.network.PacketIdClient;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class PacketGuiUpdateEntity extends PacketEntityUpdate implements IForestryPacketClient {
|
||||
private IStreamableGui streamableGui;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -47,7 +48,8 @@ public abstract class TileUtil {
|
||||
|
||||
}
|
||||
|
||||
public static <T extends TileEntity> T getTile(IBlockAccess world, BlockPos pos, Class<T> tileClass) {
|
||||
@Nullable
|
||||
public static <T extends TileEntity> T getTile(@Nonnull IBlockAccess world, @Nonnull BlockPos pos, @Nonnull Class<T> tileClass) {
|
||||
if(pos == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ package forestry.core.utils;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
|
||||
@@ -38,4 +39,18 @@ public final class VectUtil {
|
||||
public static BlockPos scale(Vec3i vect, float factor) {
|
||||
return new BlockPos(vect.getX() * factor, vect.getY() * factor, vect.getZ() * factor);
|
||||
}
|
||||
|
||||
public static EnumFacing direction(Vec3i a, Vec3i b) {
|
||||
int x = Math.abs(a.getX() - b.getX());
|
||||
int y = Math.abs(a.getY() - b.getY());
|
||||
int z = Math.abs(a.getZ() - b.getZ());
|
||||
int max = Math.max(x, Math.max(y, z));
|
||||
if (max == x) {
|
||||
return EnumFacing.EAST;
|
||||
} else if (max == z) {
|
||||
return EnumFacing.SOUTH;
|
||||
} else {
|
||||
return EnumFacing.UP;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,6 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.village.MerchantRecipe;
|
||||
import net.minecraft.village.MerchantRecipeList;
|
||||
|
||||
import forestry.apiculture.PluginApiculture;
|
||||
|
||||
public class VillagerTradeLists {
|
||||
/**
|
||||
* Copy of {@link net.minecraft.entity.passive.EntityVillager.ItemAndEmeraldToItem}
|
||||
|
||||
@@ -12,148 +12,19 @@ package forestry.core.worldgen;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.gen.feature.WorldGenerator;
|
||||
|
||||
import forestry.arboriculture.worldgen.ITreeBlockType;
|
||||
|
||||
public abstract class WorldGenBase extends WorldGenerator {
|
||||
|
||||
protected enum EnumReplaceMode {
|
||||
AIR {
|
||||
@Override
|
||||
public boolean canReplace(IBlockState blockState, World world, BlockPos pos) {
|
||||
return world.isAirBlock(pos);
|
||||
}
|
||||
},
|
||||
ALL {
|
||||
@Override
|
||||
public boolean canReplace(IBlockState blockState, World world, BlockPos pos) {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
SOFT {
|
||||
@Override
|
||||
public boolean canReplace(IBlockState blockState, World world, BlockPos pos) {
|
||||
return blockState.getBlock().isReplaceable(world, pos);
|
||||
}
|
||||
};
|
||||
|
||||
public abstract boolean canReplace(IBlockState blockState, World world, BlockPos pos);
|
||||
}
|
||||
|
||||
public static class Vector {
|
||||
|
||||
public Vector(float f, float h, float g) {
|
||||
this.x = f;
|
||||
this.y = h;
|
||||
this.z = g;
|
||||
}
|
||||
|
||||
public final float x;
|
||||
public final float y;
|
||||
public final float z;
|
||||
|
||||
public static double distance(Vector a, Vector b) {
|
||||
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2) + Math.pow(a.z - b.z, 2));
|
||||
}
|
||||
|
||||
public static EnumFacing direction(Vector a, Vector b) {
|
||||
int x = (int) Math.abs(a.x - b.x);
|
||||
int y = (int) Math.abs(a.y - b.y);
|
||||
int z = (int) Math.abs(a.z - b.z);
|
||||
int max = Math.max(x, Math.max(y, z));
|
||||
if (max == x) {
|
||||
return EnumFacing.EAST;
|
||||
} else if (max == z) {
|
||||
return EnumFacing.SOUTH;
|
||||
} else {
|
||||
return EnumFacing.UP;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean generate(World world, Random random, BlockPos pos) {
|
||||
return generate(world, pos, false);
|
||||
return generate(world, random, pos, false);
|
||||
}
|
||||
|
||||
public boolean generate(World world, BlockPos pos, boolean forced) {
|
||||
public boolean generate(World world, Random random, BlockPos pos, boolean forced) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected abstract boolean addBlock(World world, BlockPos pos, ITreeBlockType type, EnumReplaceMode replace);
|
||||
|
||||
protected final void generateCuboid(World world, Vector start, Vector area, ITreeBlockType block, EnumReplaceMode replace) {
|
||||
for (int x = (int) start.x; x < (int) start.x + area.x; x++) {
|
||||
for (int y = (int) start.y; y < (int) start.y + area.y; y++) {
|
||||
for (int z = (int) start.z; z < (int) start.z + area.z; z++) {
|
||||
addBlock(world, new BlockPos(x, y, z), block, replace);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Center is the bottom middle of the cylinder
|
||||
*/
|
||||
protected final void generateCylinder(World world, Vector center, float radius, int height, ITreeBlockType block, EnumReplaceMode replace) {
|
||||
Vector start = new Vector(center.x - radius, center.y, center.z - radius);
|
||||
Vector area = new Vector(radius * 2 + 1, height, radius * 2 + 1);
|
||||
for (int x = (int) start.x; x < (int) start.x + area.x; x++) {
|
||||
for (int y = (int) start.y; y < (int) start.y + area.y; y++) {
|
||||
for (int z = (int) start.z; z < (int) start.z + area.z; z++) {
|
||||
Vector position = new Vector(x, y, z);
|
||||
Vector treeCenter = new Vector(center.x, y, center.z);
|
||||
if (Vector.distance(position, treeCenter) <= radius + 0.01) {
|
||||
EnumFacing direction = Vector.direction(position, treeCenter);
|
||||
block.setDirection(direction);
|
||||
addBlock(world, new BlockPos(x, y, z), block, replace);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected final void generateCircle(World world, Vector center, float radius, int width, int height, ITreeBlockType block, EnumReplaceMode replace) {
|
||||
generateCircle(world, center, radius, width, height, block, 1.0f, replace);
|
||||
}
|
||||
|
||||
protected final void generateCircle(World world, Vector center, float radius, int width, int height, ITreeBlockType block, float chance, EnumReplaceMode replace) {
|
||||
Vector start = new Vector(center.x - radius, center.y, center.z - radius);
|
||||
Vector area = new Vector(radius * 2 + 1, height, radius * 2 + 1);
|
||||
|
||||
for (int x = (int) start.x; x < (int) start.x + area.x; x++) {
|
||||
for (int y = (int) start.y; y < (int) start.y + area.y; y++) {
|
||||
for (int z = (int) start.z; z < (int) start.z + area.z; z++) {
|
||||
|
||||
if (world.rand.nextFloat() > chance) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double distance = Vector.distance(new Vector(x, y, z), new Vector(center.x, y, center.z));
|
||||
if (radius - width - 0.01 < distance && distance <= radius + 0.01) {
|
||||
addBlock(world, new BlockPos(x, y, z), block, replace);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected final void generateSphere(World world, Vector center, int radius, ITreeBlockType block, EnumReplaceMode replace) {
|
||||
Vector start = new Vector(center.x - radius, center.y - radius, center.z - radius);
|
||||
Vector area = new Vector(radius * 2 + 1, radius * 2 + 1, radius * 2 + 1);
|
||||
for (int x = (int) start.x; x < (int) start.x + area.x; x++) {
|
||||
for (int y = (int) start.y; y < (int) start.y + area.y; y++) {
|
||||
for (int z = (int) start.z; z < (int) start.z + area.z; z++) {
|
||||
if (Vector.distance(new Vector(x, y, z), new Vector(center.x, center.y, center.z)) <= radius + 0.01) {
|
||||
addBlock(world, new BlockPos(x, y, z), block, replace);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,359 @@
|
||||
package forestry.core.worldgen;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.BlockVine;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.world.ITreeGenData;
|
||||
import forestry.arboriculture.worldgen.ITreeBlockType;
|
||||
import forestry.arboriculture.worldgen.TreeBlockType;
|
||||
import forestry.core.utils.VectUtil;
|
||||
|
||||
public class WorldGenHelper {
|
||||
|
||||
public static boolean addBlock(World world, BlockPos pos, ITreeBlockType type, EnumReplaceMode replaceMode) {
|
||||
if (!world.isBlockLoaded(pos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
if (replaceMode.canReplace(blockState, world, pos)) {
|
||||
type.setBlock(world, pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses startPos and girth of a tree to calculate the center
|
||||
*/
|
||||
public static void generateCylinderFromTreeStartPos(World world, ITreeBlockType block, BlockPos startPos, int girth, float radius, int height, EnumReplaceMode replace) {
|
||||
generateCylinderFromPos(world, block, startPos.add(girth / 2, 0, girth / 2), radius, height, replace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Center is the bottom middle of the cylinder
|
||||
*/
|
||||
public static void generateCylinderFromPos(World world, ITreeBlockType block, BlockPos center, float radius, int height, EnumReplaceMode replace) {
|
||||
BlockPos start = new BlockPos(center.getX() - radius, center.getY(), center.getZ() - radius);
|
||||
for (int x = 0; x < radius * 2 + 1; x++) {
|
||||
for (int y = height - 1; y >= 0; y--) { // generating top-down is faster for lighting calculations
|
||||
for (int z = 0; z < radius * 2 + 1; z++) {
|
||||
BlockPos position = start.add(x, y, z);
|
||||
Vec3i treeCenter = new Vec3i(center.getX(), position.getY(), center.getZ());
|
||||
if (position.distanceSq(treeCenter) <= radius * radius + 0.01) {
|
||||
EnumFacing direction = VectUtil.direction(position, treeCenter);
|
||||
block.setDirection(direction);
|
||||
addBlock(world, position, block, replace);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateCircleFromTreeStartPos(World world, Random rand, BlockPos startPos, int girth, float radius, int width, int height, ITreeBlockType block, float chance, EnumReplaceMode replace) {
|
||||
generateCircle(world, rand, startPos.add(girth / 2, 0, girth / 2), radius, width, height, block, chance, replace);
|
||||
}
|
||||
|
||||
public static void generateCircle(World world, Random rand, BlockPos center, float radius, int width, int height, ITreeBlockType block, float chance, EnumReplaceMode replace) {
|
||||
Vec3i start = new Vec3i(center.getX() - radius, center.getY(), center.getZ() - radius);
|
||||
Vec3i area = new Vec3i(radius * 2 + 1, height, radius * 2 + 1);
|
||||
|
||||
for (int x = start.getX(); x < start.getX() + area.getX(); x++) {
|
||||
for (int y = start.getY() + area.getY() - 1; y >= start.getY(); y--) { // generating top-down is faster for lighting calculations
|
||||
for (int z = start.getZ(); z < start.getZ() + area.getZ(); z++) {
|
||||
|
||||
if (rand.nextFloat() > chance) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double distance = new Vec3i(x, y, z).getDistance(center.getX(), y, center.getZ());
|
||||
if (radius - width - 0.01 < distance && distance <= radius + 0.01) {
|
||||
addBlock(world, new BlockPos(x, y, z), block, replace);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateSphereFromTreeStartPos(World world, BlockPos startPos, int girth, int radius, ITreeBlockType block, EnumReplaceMode replace) {
|
||||
generateSphere(world, startPos.add(girth / 2, 0, girth / 2), radius, block, replace);
|
||||
}
|
||||
|
||||
public static void generateSphere(World world, BlockPos center, int radius, ITreeBlockType block, EnumReplaceMode replace) {
|
||||
Vec3i start = new Vec3i(center.getX() - radius, center.getY() - radius, center.getZ() - radius);
|
||||
Vec3i area = new Vec3i(radius * 2 + 1, radius * 2 + 1, radius * 2 + 1);
|
||||
for (int x = start.getX(); x < start.getX() + area.getX(); x++) {
|
||||
for (int y = start.getY() + area.getY() - 1; y >= start.getY(); y--) { // generating top-down is faster for lighting calculations
|
||||
for (int z = start.getZ(); z < start.getZ() + area.getZ(); z++) {
|
||||
if (center.getDistance(x, y, z) <= radius + 0.01) {
|
||||
addBlock(world, new BlockPos(x, y, z), block, replace);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns a list of trunk top coordinates */
|
||||
public static Set<BlockPos> generateTreeTrunk(
|
||||
@Nonnull World world,
|
||||
Random rand,
|
||||
@Nonnull ITreeBlockType wood,
|
||||
@Nonnull BlockPos startPos,
|
||||
int height,
|
||||
int girth,
|
||||
int yStart,
|
||||
float vinesChance,
|
||||
@Nullable EnumFacing leanDirection,
|
||||
float leanScale
|
||||
) {
|
||||
Set<BlockPos> treeTops = new HashSet<>();
|
||||
|
||||
final int leanStartY = (int) Math.floor(height * 0.33f);
|
||||
int prevXOffset = 0;
|
||||
int prevZOffset = 0;
|
||||
|
||||
int leanX = 0;
|
||||
int leanZ = 0;
|
||||
|
||||
if (leanDirection != null) {
|
||||
leanX = leanDirection.getFrontOffsetX();
|
||||
leanZ = leanDirection.getFrontOffsetZ();
|
||||
}
|
||||
|
||||
for (int x = 0; x < girth; x++) {
|
||||
for (int z = 0; z < girth; z++) {
|
||||
for (int y = height - 1; y >= yStart; y--) { // generating top-down is faster for lighting calculations
|
||||
float lean;
|
||||
if (y < leanStartY) {
|
||||
lean = 0;
|
||||
} else {
|
||||
lean = leanScale * (y - leanStartY) / (height - leanStartY);
|
||||
}
|
||||
int xOffset = (int) Math.floor(leanX * lean);
|
||||
int zOffset = (int) Math.floor(leanZ * lean);
|
||||
|
||||
if (xOffset != prevXOffset || zOffset != prevZOffset) {
|
||||
prevXOffset = xOffset;
|
||||
prevZOffset = zOffset;
|
||||
if (y > 0) {
|
||||
wood.setDirection(leanDirection);
|
||||
addBlock(world, startPos.add(x + xOffset, y - 1, z + zOffset), wood, EnumReplaceMode.ALL);
|
||||
wood.setDirection(EnumFacing.UP);
|
||||
}
|
||||
}
|
||||
|
||||
BlockPos pos = startPos.add(x + xOffset, y, z + zOffset);
|
||||
addBlock(world, pos, wood, EnumReplaceMode.ALL);
|
||||
addVines(world, rand, pos, vinesChance);
|
||||
|
||||
if (y + 1 == height) {
|
||||
treeTops.add(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return treeTops;
|
||||
}
|
||||
|
||||
protected static void addVines(World world, Random rand, BlockPos pos, float chance) {
|
||||
if (chance <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (rand.nextFloat() < chance) {
|
||||
IBlockState blockState = Blocks.VINE.getDefaultState().withProperty(BlockVine.EAST, true);
|
||||
addBlock(world, pos.west(), new TreeBlockType(blockState), EnumReplaceMode.AIR);
|
||||
}
|
||||
if (rand.nextFloat() < chance) {
|
||||
IBlockState blockState = Blocks.VINE.getDefaultState().withProperty(BlockVine.WEST, true);
|
||||
addBlock(world, pos.east(), new TreeBlockType(blockState), EnumReplaceMode.AIR);
|
||||
}
|
||||
if (rand.nextFloat() < chance) {
|
||||
IBlockState blockState = Blocks.VINE.getDefaultState().withProperty(BlockVine.SOUTH, true);
|
||||
addBlock(world, pos.north(), new TreeBlockType(blockState), EnumReplaceMode.AIR);
|
||||
}
|
||||
if (rand.nextFloat() < chance) {
|
||||
IBlockState blockState = Blocks.VINE.getDefaultState().withProperty(BlockVine.NORTH, true);
|
||||
addBlock(world, pos.south(), new TreeBlockType(blockState), EnumReplaceMode.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
public static void generatePods(ITreeGenData tree, World world, Random rand, BlockPos startPos, int height, int minHeight, int girth, EnumReplaceMode replaceMode) {
|
||||
for (int y = height - 1; y >= minHeight; y--) { // generating top-down is faster for lighting calculations
|
||||
for (int x = 0; x < girth; x++) {
|
||||
for (int z = 0; z < girth; z++) {
|
||||
|
||||
if (x > 0 && x < girth && z > 0 && z < girth) {
|
||||
continue;
|
||||
}
|
||||
|
||||
trySpawnFruitBlock(tree, world, rand, startPos.add(x + 1, y, z), replaceMode);
|
||||
trySpawnFruitBlock(tree, world, rand, startPos.add(x - 1, y, z), replaceMode);
|
||||
trySpawnFruitBlock(tree, world, rand, startPos.add(x, y, z + 1), replaceMode);
|
||||
trySpawnFruitBlock(tree, world, rand, startPos.add(x, y, z - 1), replaceMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void trySpawnFruitBlock(ITreeGenData tree, World world, Random rand, BlockPos pos, EnumReplaceMode replaceMode) {
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
if (replaceMode.canReplace(blockState, world, pos)) {
|
||||
tree.trySpawnFruitBlock(world, rand, pos);
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateSupportStems(ITreeBlockType wood, World world, Random rand, BlockPos startPos, int height, int girth, float chance, float maxHeight) {
|
||||
|
||||
final int min = -1;
|
||||
final int max = girth;
|
||||
|
||||
for (int x = min; x <= max; x++) {
|
||||
for (int z = min; z <= max; z++) {
|
||||
|
||||
// skip the corners, support stems should touch the body of the trunk
|
||||
if ((x == min && z == min) || (x == max && z == max) || (x == min && z == max) || (x == max && z == min)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int stemHeight = rand.nextInt(Math.round(height * maxHeight));
|
||||
if (rand.nextFloat() < chance) {
|
||||
for (int y = 0; y < stemHeight; y++) {
|
||||
addBlock(world, startPos.add(x, y, z), wood, EnumReplaceMode.SOFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<BlockPos> generateBranches(final World world, final Random rand, final ITreeBlockType wood, final BlockPos startPos, final int girth, final float spreadY, final float spreadXZ, int radius, final int count, final float chance) {
|
||||
Set<BlockPos> branchEnds = new HashSet<>();
|
||||
if (radius < 1) {
|
||||
radius = 1;
|
||||
}
|
||||
|
||||
for (final EnumFacing branchDirection : EnumFacing.HORIZONTALS) {
|
||||
wood.setDirection(branchDirection);
|
||||
|
||||
BlockPos branchStart = startPos;
|
||||
|
||||
int offsetX = branchDirection.getFrontOffsetX();
|
||||
int offsetZ = branchDirection.getFrontOffsetZ();
|
||||
if (offsetX > 0) {
|
||||
branchStart = branchStart.add(girth - 1, 0, 0);
|
||||
}
|
||||
if (offsetZ > 0) {
|
||||
branchStart = branchStart.add(0, 0, girth - 1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (rand.nextFloat() > chance) {
|
||||
continue;
|
||||
}
|
||||
int y = 0;
|
||||
int x = 0;
|
||||
int z = 0;
|
||||
|
||||
for (int r = 0; r < radius; r++) {
|
||||
if (rand.nextFloat() < spreadY) {
|
||||
// make branches only spread up, not down
|
||||
y++;
|
||||
wood.setDirection(EnumFacing.UP);
|
||||
} else {
|
||||
if (rand.nextFloat() < spreadXZ) {
|
||||
if (branchDirection.getAxis() == EnumFacing.Axis.Z) {
|
||||
if (rand.nextBoolean()) {
|
||||
x++;
|
||||
} else {
|
||||
x--;
|
||||
}
|
||||
wood.setDirection(EnumFacing.EAST);
|
||||
} else if (branchDirection.getAxis() == EnumFacing.Axis.X) {
|
||||
if (rand.nextBoolean()) {
|
||||
z++;
|
||||
} else {
|
||||
z--;
|
||||
}
|
||||
wood.setDirection(EnumFacing.SOUTH);
|
||||
}
|
||||
} else {
|
||||
x += offsetX;
|
||||
z += offsetZ;
|
||||
wood.setDirection(branchDirection);
|
||||
}
|
||||
}
|
||||
|
||||
BlockPos pos = branchStart.add(x, y, z);
|
||||
if (addBlock(world, pos, wood, EnumReplaceMode.SOFT)) {
|
||||
branchEnds.add(pos);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return branchEnds;
|
||||
}
|
||||
|
||||
public enum EnumReplaceMode {
|
||||
AIR {
|
||||
@Override
|
||||
public boolean canReplace(IBlockState blockState, World world, BlockPos pos) {
|
||||
return world.isAirBlock(pos);
|
||||
}
|
||||
},
|
||||
ALL {
|
||||
@Override
|
||||
public boolean canReplace(IBlockState blockState, World world, BlockPos pos) {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
SOFT {
|
||||
@Override
|
||||
public boolean canReplace(IBlockState blockState, World world, BlockPos pos) {
|
||||
return blockState.getBlock().isReplaceable(world, pos);
|
||||
}
|
||||
};
|
||||
|
||||
public abstract boolean canReplace(IBlockState blockState, World world, BlockPos pos);
|
||||
}
|
||||
|
||||
public enum Direction {
|
||||
NORTH(EnumFacing.NORTH),
|
||||
SOUTH(EnumFacing.SOUTH),
|
||||
WEST(EnumFacing.WEST),
|
||||
EAST(EnumFacing.EAST);
|
||||
|
||||
public final EnumFacing facing;
|
||||
|
||||
Direction(EnumFacing forgeDirection) {
|
||||
this.facing = forgeDirection;
|
||||
}
|
||||
|
||||
public static Direction getRandom(Random random) {
|
||||
return values()[random.nextInt(values().length)];
|
||||
}
|
||||
|
||||
public static Direction getRandomOther(Random random, Direction direction) {
|
||||
EnumSet<Direction> directions = EnumSet.allOf(Direction.class);
|
||||
directions.remove(direction);
|
||||
int size = directions.size();
|
||||
return directions.toArray(new Direction[size])[random.nextInt(size)];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.lepidopterology;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -23,13 +25,13 @@ import forestry.lepidopterology.entities.EntityButterfly;
|
||||
public class ButterflySpawner implements ILeafTickHandler {
|
||||
|
||||
@Override
|
||||
public boolean onRandomLeafTick(ITree tree, World world, BlockPos pos, boolean isDestroyed) {
|
||||
public boolean onRandomLeafTick(ITree tree, World world, Random rand, BlockPos pos, boolean isDestroyed) {
|
||||
|
||||
if (world.rand.nextFloat() >= tree.getGenome().getSappiness() * tree.getGenome().getYield()) {
|
||||
if (rand.nextFloat() >= tree.getGenome().getSappiness() * tree.getGenome().getYield()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IButterfly spawn = ButterflyManager.butterflyRoot.getIndividualTemplates().get(world.rand.nextInt(ButterflyManager.butterflyRoot.getIndividualTemplates().size()));
|
||||
IButterfly spawn = ButterflyManager.butterflyRoot.getIndividualTemplates().get(rand.nextInt(ButterflyManager.butterflyRoot.getIndividualTemplates().size()));
|
||||
float rarity;
|
||||
if(PluginLepidopterology.spawnRaritys.containsKey(spawn.getGenome().getPrimary().getUID())){
|
||||
rarity = spawn.getGenome().getPrimary().getRarity();
|
||||
@@ -37,7 +39,7 @@ public class ButterflySpawner implements ILeafTickHandler {
|
||||
rarity = PluginLepidopterology.spawnRaritys.get(spawn.getGenome().getPrimary().getUID());
|
||||
}
|
||||
|
||||
if (world.rand.nextFloat() >= rarity * 0.5f) {
|
||||
if (rand.nextFloat() >= rarity * 0.5f) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user