From 93bc9b1b89c4ed2f4d75d9ac9f90c7ab6110f936 Mon Sep 17 00:00:00 2001 From: Electroblob77 <35599699+Electroblob77@users.noreply.github.com> Date: Sun, 18 Aug 2019 22:44:09 +0100 Subject: [PATCH] Add tree blocks config option, fixes #165 --- .../java/electroblob/wizardry/Settings.java | 12 +++++++++++ .../wizardry/util/WizardryUtilities.java | 21 +++++++++++++++---- .../worldgen/WorldGenSurfaceStructure.java | 3 +-- .../assets/ebwizardry/lang/en_gb.lang | 2 ++ .../assets/ebwizardry/lang/en_us.lang | 2 ++ 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/main/java/electroblob/wizardry/Settings.java b/src/main/java/electroblob/wizardry/Settings.java index f4e94229..60bd5068 100644 --- a/src/main/java/electroblob/wizardry/Settings.java +++ b/src/main/java/electroblob/wizardry/Settings.java @@ -67,6 +67,10 @@ public final class Settings { /** The unlocalised name of the compatibility config category. */ public static final String COMPATIBILITY_CATEGORY = "compatibility"; + private static final String[] DEFAULT_TREE_BLOCKS = {"dynamictrees:oakbranch", "dynamictrees:sprucebranch", + "dynamictrees:birchbranch", "dynamictrees:junglebranch", "dynamictrees:darkoakbranch", + "dynamictrees:acaciabranch", "dynamictrees:cactusbranch", "dynamictrees:leaves0", "dynamictrees:leaves1"}; + private static final String[] DEFAULT_LOOT_INJECTION_LOCATIONS = {"minecraft:chests/simple_dungeon", "minecraft:chests/abandoned_mineshaft", "minecraft:chests/desert_pyramid", "minecraft:chests/jungle_temple", "minecraft:chests/stronghold_corridor", "minecraft:chests/stronghold_crossing", @@ -119,6 +123,8 @@ public final class Settings { new ResourceLocation(Wizardry.MODID, "shrine_5"), new ResourceLocation(Wizardry.MODID, "shrine_6"), new ResourceLocation(Wizardry.MODID, "shrine_7")}; + /** [Server-only] List of solid blocks (usually trees) which are ignored by the structure generators. */ + public ResourceLocation[] treeBlocks = toResourceLocations(DEFAULT_TREE_BLOCKS); /** [Server-only] The chance for wizard towers to generate with an evil wizard and chest inside. */ public double evilWizardChance = 0.2; /** [Server-only] List of dimension ids in which to generate crystal ore. */ @@ -772,6 +778,12 @@ public final class Settings { shrineFiles = getResourceLocationList(property); propOrder.add(property.getName()); + property = config.get(GAMEPLAY_CATEGORY, "treeBlocks", DEFAULT_TREE_BLOCKS, "List of registry names of blocks which can be overwritten by wizardry's structure generators, affecting both fast and fancy structure generation. Most tree blocks and other foliage should work automatically, but those that don't can be added manually here. Block names are not case sensitive. For mod blocks, prefix with the mod ID (e.g. dynamictrees:oakbranch)."); + property.setLanguageKey("config." + Wizardry.MODID + ".tree_blocks"); + property.setRequiresWorldRestart(true); + treeBlocks = getResourceLocationList(property); + propOrder.add(property.getName()); + property = config.get(WORLDGEN_CATEGORY, "oreDimensions", new int[]{0}, "List of dimension ids in which crystal ore will generate. Note that removing the overworld (id 0) from this list will make the mod VERY difficult to play!"); property.setLanguageKey("config." + Wizardry.MODID + ".ore_dimensions"); property.setRequiresWorldRestart(true); diff --git a/src/main/java/electroblob/wizardry/util/WizardryUtilities.java b/src/main/java/electroblob/wizardry/util/WizardryUtilities.java index 8cbdcb58..d6772355 100644 --- a/src/main/java/electroblob/wizardry/util/WizardryUtilities.java +++ b/src/main/java/electroblob/wizardry/util/WizardryUtilities.java @@ -7,6 +7,7 @@ import electroblob.wizardry.entity.living.ISpellCaster; import electroblob.wizardry.item.ISpellCastingItem; import electroblob.wizardry.spell.Spell; import net.minecraft.block.Block; +import net.minecraft.block.BlockCactus; import net.minecraft.block.BlockLog; import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; @@ -285,13 +286,25 @@ public final class WizardryUtilities { /** Surface criterion which defines a surface as the boundary between a block that cannot be moved through, and * a block that can be moved through or a tree block (log or leaves). Used for structure generation. */ SurfaceCriteria COLLIDABLE_IGNORING_TREES = basedOn((world, pos) -> - world.getBlockState(pos).getMaterial().blocksMovement() - && !(world.getBlockState(pos).getBlock() instanceof BlockLog) - && !(world.getBlockState(pos).getBlock().isLeaves(world.getBlockState(pos), world, pos) - && !(world.getBlockState(pos).getBlock().isFoliage(world, pos)))); + world.getBlockState(pos).getMaterial().blocksMovement() && !isTreeBlock(world, pos)); } + /** + * Returns true if the block at the given position is a tree block (or other 'solid' vegetation, such as cacti). + * Used for structure generation. + * @param world The world the block is in + * @param pos The position of the block to be tested + * @return True if the given block is a tree block, false if not. + */ + public static boolean isTreeBlock(World world, BlockPos pos){ + return world.getBlockState(pos).getBlock() instanceof BlockLog + || world.getBlockState(pos).getBlock() instanceof BlockCactus + || world.getBlockState(pos).getBlock().isLeaves(world.getBlockState(pos), world, pos) + || world.getBlockState(pos).getBlock().isFoliage(world, pos) + || Arrays.asList(Wizardry.settings.treeBlocks).contains(world.getBlockState(pos).getBlock().getRegistryName()); + } + /** * Finds the nearest floor level in the given direction from the given position, * within the range specified. This is a shorthand for diff --git a/src/main/java/electroblob/wizardry/worldgen/WorldGenSurfaceStructure.java b/src/main/java/electroblob/wizardry/worldgen/WorldGenSurfaceStructure.java index a2b58c31..c55ba7c4 100644 --- a/src/main/java/electroblob/wizardry/worldgen/WorldGenSurfaceStructure.java +++ b/src/main/java/electroblob/wizardry/worldgen/WorldGenSurfaceStructure.java @@ -327,8 +327,7 @@ public abstract class WorldGenSurfaceStructure implements IWorldGenerator { Block below = world.getBlockState(pos.down()).getBlock(); if(block instanceof BlockLog){ - if(below != Blocks.GRASS && below != Blocks.DIRT && !(below instanceof BlockLog) && - !below.isLeaves(world.getBlockState(pos.down()), world, pos.down())){ + if(below != Blocks.GRASS && below != Blocks.DIRT && !WizardryUtilities.isTreeBlock(world, pos.down())){ world.setBlockToAir(pos); changed = true; } diff --git a/src/main/resources/assets/ebwizardry/lang/en_gb.lang b/src/main/resources/assets/ebwizardry/lang/en_gb.lang index 7e733c22..04f73802 100644 --- a/src/main/resources/assets/ebwizardry/lang/en_gb.lang +++ b/src/main/resources/assets/ebwizardry/lang/en_gb.lang @@ -1175,6 +1175,8 @@ config.ebwizardry.shrine_rarity=Shrine Rarity config.ebwizardry.shrine_rarity.tooltip=Rarity of shrines. 1 in this many chunks will contain a shrine, meaning higher numbers are rarer. config.ebwizardry.shrine_files=Shrine Structure Files config.ebwizardry.shrine_files.tooltip=List of structure file locations for shrines. One of these files will be randomly selected each time a shrine is generated. File locations are of the format [mod id]\:[filename], which refers to the file assets/[mod id]/structures/[filename].nbt. Duplicate entries are permitted, allowing for simple weighting without duplicating the structure files themselves. +config.ebwizardry.tree_blocks=Tree Blocks +config.ebwizardry.tree_blocks.tooltip=List of registry names of blocks which can be overwritten by wizardry's structure generators, affecting both fast and fancy structure generation. Most tree blocks and other foliage should work automatically, but those that don't can be added manually here. Block names are not case sensitive. For mod blocks, prefix with the mod ID (e.g. dynamictrees:oakbranch). config.ebwizardry.ore_dimensions=Ore Dimensions config.ebwizardry.ore_dimensions.tooltip=List of ids of dimensions in which crystal ore will generate. Note that removing the overworld (id 0) from this list will make the mod VERY difficult to play! config.ebwizardry.flower_dimensions=Flower Dimensions diff --git a/src/main/resources/assets/ebwizardry/lang/en_us.lang b/src/main/resources/assets/ebwizardry/lang/en_us.lang index bcc6666f..cbec640c 100644 --- a/src/main/resources/assets/ebwizardry/lang/en_us.lang +++ b/src/main/resources/assets/ebwizardry/lang/en_us.lang @@ -1175,6 +1175,8 @@ config.ebwizardry.shrine_rarity=Shrine Rarity config.ebwizardry.shrine_rarity.tooltip=Rarity of shrines. 1 in this many chunks will contain a shrine, meaning higher numbers are rarer. config.ebwizardry.shrine_files=Shrine Structure Files config.ebwizardry.shrine_files.tooltip=List of structure file locations for shrines. One of these files will be randomly selected each time a shrine is generated. File locations are of the format [mod id]\:[filename], which refers to the file assets/[mod id]/structures/[filename].nbt. Duplicate entries are permitted, allowing for simple weighting without duplicating the structure files themselves. +config.ebwizardry.tree_blocks=Tree Blocks +config.ebwizardry.tree_blocks.tooltip=List of registry names of blocks which can be overwritten by wizardry's structure generators, affecting both fast and fancy structure generation. Most tree blocks and other foliage should work automatically, but those that don't can be added manually here. Block names are not case sensitive. For mod blocks, prefix with the mod ID (e.g. dynamictrees:oakbranch). config.ebwizardry.ore_dimensions=Ore Dimensions config.ebwizardry.ore_dimensions.tooltip=List of ids of dimensions in which crystal ore will generate. Note that removing the overworld (id 0) from this list will make the mod VERY difficult to play! config.ebwizardry.flower_dimensions=Flower Dimensions