Skip to content

Commit

Permalink
Trees .2 Each tree should have a ITreeGenerator which will be called …
Browse files Browse the repository at this point in the history
…to generate the tree, either from a (set of) structure file(s), or from some other generation method. Also the generateTrees.py will do some basic nbt gruntwork on basic tree templates. Decided to ditch the TFC 2 stuff because it was too complex and large. Need to add ITreeGenerators for spruce type trees, willow, kapok, acacia.
  • Loading branch information
alcatrazEscapee committed Jul 16, 2018
1 parent 8690815 commit 09f4a1a
Show file tree
Hide file tree
Showing 73 changed files with 306 additions and 17 deletions.
62 changes: 62 additions & 0 deletions generateTrees.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import os
from nbtlib import nbt
from nbtlib.tag import *

os.chdir('src/main/resources/assets/tfc/structures/')

def tree(origin, wood, nameout):
f = nbt.load(origin + '.nbt')

for block in f.root['palette']:

if block['Name'] == 'minecraft:log':
block['Name'] = String('tfc:wood/log/' + wood)
prop = block['Properties']
block['Properties'] = Compound({
'small': String('false'),
'placed': String('true'),
'axis': prop['axis']
})

if block['Name'] == 'minecraft:leaves':
block['Name'] = String('tfc:wood/leaves/' + wood)
block['Properties'] = Compound({
'check_decay': String('true'),
'decayable': String('true')
})
if not os.path.exists(wood):
os.mkdir(wood)
f.save(wood + '/' + nameout + '.nbt')


WOOD_TYPES = {
'ash': 'normal',
'aspen': 'normal',
'birch': 'normal',
'chestnut': 'normal',
'douglas_fir': 'tall',
'hickory': 'normal',
'maple': 'normal',
'oak': 'normal',
'pine': 'normal',
'sequoia': 'normal',
'spruce': 'normal',
'sycamore': 'normal',
'white_cedar': 'tall',
'willow': 'normal',
'kapok': 'normal',
'acacia': 'normal',
'rosewood': 'normal',
'blackwood': 'tall',
'palm': 'normal'
}

for wood, key in WOOD_TYPES.items():
# normal
if key == 'normal':
tree('base/normal', wood, 'base')
tree('base/normal_overlay', wood, 'overlay')
# tall (douglas fir)
if key == 'tall':
tree('base/tall', wood, 'base')
tree('base/tall_overlay', wood, 'overlay')
4 changes: 2 additions & 2 deletions src/main/java/net/dries007/tfc/TerraFirmaCraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.dries007.tfc.client.ClientEvents;
import net.dries007.tfc.client.TFCGuiHandler;
import net.dries007.tfc.cmd.StripWorldCommand;
import net.dries007.tfc.cmd.TreeGenCommand;
import net.dries007.tfc.objects.CreativeTabsTFC;
import net.dries007.tfc.objects.entity.EntitiesTFC;
import net.dries007.tfc.objects.fluids.FluidsTFC;
Expand Down Expand Up @@ -130,9 +131,7 @@ public void init(FMLInitializationEvent event)
GameRegistry.registerWorldGenerator(new RarityBasedWorldGen(x -> x.waterFissureClusterRarity, new WorldGenSurfaceFissureCluster(false)), 1);
GameRegistry.registerWorldGenerator(new WorldGenOre(), 2);
//todo: add cave decorator
//todo: add forests
GameRegistry.registerWorldGenerator(new WorldGenTrees(), 4);
//todo: add loose rocks
GameRegistry.registerWorldGenerator(new WorldGenLooseRocks(), 5);
GameRegistry.registerWorldGenerator(new WorldGenSoilPits(), 6);
GameRegistry.registerWorldGenerator(new RarityBasedWorldGen(x -> x.largeRockRarity, new WorldGenLargeRocks()), 7);
Expand All @@ -154,6 +153,7 @@ public void onServerStarting(FMLServerStartingEvent event)
if (!isSignedBuild)
log.warn("You are not running an official build. Please do not use this and then report bugs or issues.");
event.registerServerCommand(new StripWorldCommand());
event.registerServerCommand(new TreeGenCommand());
}

@Mod.EventHandler
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/net/dries007/tfc/cmd/TreeGenCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*
*/

package net.dries007.tfc.cmd;

import javax.annotation.ParametersAreNonnullByDefault;

import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.gen.structure.template.TemplateManager;

import mcp.MethodsReturnNonnullByDefault;
import net.dries007.tfc.objects.Wood;
import net.dries007.tfc.objects.trees.ITreeGenerator;
import net.dries007.tfc.objects.trees.TreeGenNormal;
import net.dries007.tfc.objects.trees.TreeGenTall;

@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class TreeGenCommand extends CommandBase
{
private static ITreeGenerator gen1 = new TreeGenNormal();
private static ITreeGenerator gen2 = new TreeGenTall();

@Override
public String getName()
{
return "maketree";
}

@Override
public String getUsage(ICommandSender sender)
{
return "/maketree <type> [wood] -> Grows a tree of the type specified";
}

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
if (args.length != 1) throw new WrongUsageException("1 argument required.");
String type = args[0];

if (sender.getCommandSenderEntity() == null) return;

final World world = sender.getEntityWorld();
final BlockPos center = new BlockPos(sender.getCommandSenderEntity());
final TemplateManager manager = ((WorldServer) world).getStructureTemplateManager();

if (type.equals("normal"))
gen1.generateTree(manager, world, center, Wood.OAK, world.rand);
if (type.equals("tall"))
gen2.generateTree(manager, world, center, Wood.DOUGLAS_FIR, world.rand);

}
}
22 changes: 22 additions & 0 deletions src/main/java/net/dries007/tfc/objects/Wood.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

package net.dries007.tfc.objects;

import net.dries007.tfc.objects.trees.ITreeGenerator;
import net.dries007.tfc.objects.trees.TreeGenNormal;

public enum Wood
{
ACACIA(0, 12620, 7060, false, false), //Acacia Koa
Expand Down Expand Up @@ -36,6 +39,25 @@ public static Wood get(int i)
}
throw new IndexOutOfBoundsException("No wood found matching " + i);
}

private static ITreeGenerator genNormal = new TreeGenNormal();
private static ITreeGenerator genTall = new TreeGenTall();

public int getRadiusForGrowth() { return 2; } // todo: make this a property of each tree

public ITreeGenerator getTreeGenerator()
{
switch(this)
{
case DOUGLAS_FIR:
case WHITE_CEDAR:
case BLACKWOOD:
return genTall;
default:
return genNormal;
}
}

public final int bend;
public final int compression;
public final boolean isEverGreen, isSwapTree;
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/net/dries007/tfc/objects/trees/ITreeGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*
*/

package net.dries007.tfc.objects.trees;

import java.util.Random;

import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.structure.template.TemplateManager;

import net.dries007.tfc.objects.Wood;

public interface ITreeGenerator
{
void generateTree(TemplateManager manager, World world, BlockPos pos, Wood tree, Random rand);
}
54 changes: 54 additions & 0 deletions src/main/java/net/dries007/tfc/objects/trees/TreeGenNormal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*
*/

package net.dries007.tfc.objects.trees;

import java.util.Random;

import net.minecraft.block.state.IBlockState;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.structure.template.PlacementSettings;
import net.minecraft.world.gen.structure.template.Template;
import net.minecraft.world.gen.structure.template.TemplateManager;

import net.dries007.tfc.Constants;
import net.dries007.tfc.objects.Wood;
import net.dries007.tfc.objects.blocks.wood.BlockLogTFC;
import net.dries007.tfc.world.classic.worldgen.WorldGenTrees;

public class TreeGenNormal implements ITreeGenerator
{

@Override
public void generateTree(TemplateManager manager, World world, BlockPos pos, Wood tree, Random rand)
{
ResourceLocation base = new ResourceLocation(Constants.MOD_ID, tree + "/base");
ResourceLocation overlay = new ResourceLocation(Constants.MOD_ID, tree + "/overlay");

Template structureBase = manager.getTemplate(world.getMinecraftServer(), base);
Template structureOverlay = manager.getTemplate(world.getMinecraftServer(), overlay);

PlacementSettings settings = WorldGenTrees.getDefaultSettings();

int height = 1 + rand.nextInt(4);

BlockPos size = structureBase.getSize();
pos = pos.add(-size.getX() / 2, height, -size.getZ() / 2);

if (WorldGenTrees.canGenerateTree(world, pos.down(height), structureBase, settings, tree))
{
structureBase.addBlocksToWorld(world, pos, settings);
structureOverlay.addBlocksToWorld(world, pos, settings.setIntegrity(0.5f));

final IBlockState log = BlockLogTFC.get(tree).getDefaultState();
for (int i = 0; i < height; i++)
world.setBlockState(pos.add(size.getX() / 2, i - height, size.getZ() / 2), log);
}
}

}
43 changes: 43 additions & 0 deletions src/main/java/net/dries007/tfc/objects/trees/TreeGenTall.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*
*/

package net.dries007.tfc.objects.trees;

import java.util.Random;

import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.structure.template.PlacementSettings;
import net.minecraft.world.gen.structure.template.Template;
import net.minecraft.world.gen.structure.template.TemplateManager;

import net.dries007.tfc.Constants;
import net.dries007.tfc.objects.Wood;
import net.dries007.tfc.world.classic.worldgen.WorldGenTrees;

public class TreeGenTall implements ITreeGenerator
{
@Override
public void generateTree(TemplateManager manager, World world, BlockPos pos, Wood tree, Random rand)
{
ResourceLocation base = new ResourceLocation(Constants.MOD_ID, tree + "/base");
ResourceLocation overlay = new ResourceLocation(Constants.MOD_ID, tree + "/overlay");

Template structureBase = manager.getTemplate(world.getMinecraftServer(), base);
Template structureOverlay = manager.getTemplate(world.getMinecraftServer(), overlay);

PlacementSettings settings = WorldGenTrees.getDefaultSettings();
BlockPos size = structureBase.getSize();
pos = pos.add(-size.getX() / 2, 0, -size.getZ() / 2);

if (WorldGenTrees.canGenerateTree(world, pos, structureBase, settings, tree))
{
structureBase.addBlocksToWorld(world, pos, settings);
structureOverlay.addBlocksToWorld(world, pos, settings.setIntegrity(0.5f));
}
}
}
Loading

0 comments on commit 09f4a1a

Please sign in to comment.