-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trees .2 Each tree should have a ITreeGenerator which will be called …
…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
1 parent
8690815
commit 09f4a1a
Showing
73 changed files
with
306 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/net/dries007/tfc/objects/trees/ITreeGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
54
src/main/java/net/dries007/tfc/objects/trees/TreeGenNormal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
43
src/main/java/net/dries007/tfc/objects/trees/TreeGenTall.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
Oops, something went wrong.