Tenanea generator prototype
This commit is contained in:
parent
8aa8d1463a
commit
1a4eaa7c6e
6 changed files with 156 additions and 0 deletions
21
src/main/java/ru/betterend/blocks/BlockTenaneaSapling.java
Normal file
21
src/main/java/ru/betterend/blocks/BlockTenaneaSapling.java
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
package ru.betterend.blocks;
|
||||||
|
|
||||||
|
import net.minecraft.world.gen.feature.Feature;
|
||||||
|
import ru.betterend.blocks.basis.BlockFeatureSapling;
|
||||||
|
import ru.betterend.registry.EndFeatures;
|
||||||
|
|
||||||
|
public class BlockTenaneaSapling extends BlockFeatureSapling {
|
||||||
|
public BlockTenaneaSapling() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Feature<?> getFeature() {
|
||||||
|
return EndFeatures.TENANEA.getFeature();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*@Override
|
||||||
|
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
|
||||||
|
return world.getBlockState(pos.down()).isOf(EndBlocks.SHADOW_GRASS);
|
||||||
|
}*/
|
||||||
|
}
|
|
@ -34,6 +34,7 @@ import ru.betterend.blocks.BlockPath;
|
||||||
import ru.betterend.blocks.BlockPythadendronSapling;
|
import ru.betterend.blocks.BlockPythadendronSapling;
|
||||||
import ru.betterend.blocks.BlockShadowBerry;
|
import ru.betterend.blocks.BlockShadowBerry;
|
||||||
import ru.betterend.blocks.BlockShadowGrass;
|
import ru.betterend.blocks.BlockShadowGrass;
|
||||||
|
import ru.betterend.blocks.BlockTenaneaSapling;
|
||||||
import ru.betterend.blocks.BlockTerrain;
|
import ru.betterend.blocks.BlockTerrain;
|
||||||
import ru.betterend.blocks.BlockTerrainPlant;
|
import ru.betterend.blocks.BlockTerrainPlant;
|
||||||
import ru.betterend.blocks.BlockUmbrellaMoss;
|
import ru.betterend.blocks.BlockUmbrellaMoss;
|
||||||
|
@ -116,6 +117,8 @@ public class EndBlocks {
|
||||||
public static final Block DRAGON_TREE_LEAVES = registerBlock("dragon_tree_leaves", new BlockLeaves(MaterialColor.MAGENTA));
|
public static final Block DRAGON_TREE_LEAVES = registerBlock("dragon_tree_leaves", new BlockLeaves(MaterialColor.MAGENTA));
|
||||||
public static final WoodenMaterial DRAGON_TREE = new WoodenMaterial("dragon_tree", MaterialColor.BLACK, MaterialColor.MAGENTA);
|
public static final WoodenMaterial DRAGON_TREE = new WoodenMaterial("dragon_tree", MaterialColor.BLACK, MaterialColor.MAGENTA);
|
||||||
|
|
||||||
|
public static final Block TENANEA_SAPLING = registerBlock("tenanea_sapling", new BlockTenaneaSapling());
|
||||||
|
public static final Block TENANEA_LEAVES = registerBlock("tenanea_leaves", new BlockLeaves(MaterialColor.PINK));
|
||||||
public static final WoodenMaterial TENANEA = new WoodenMaterial("tenanea", MaterialColor.PINK, MaterialColor.PINK);
|
public static final WoodenMaterial TENANEA = new WoodenMaterial("tenanea", MaterialColor.PINK, MaterialColor.PINK);
|
||||||
|
|
||||||
// Small Plants //
|
// Small Plants //
|
||||||
|
|
|
@ -31,6 +31,7 @@ import ru.betterend.world.features.trees.DragonTreeFeature;
|
||||||
import ru.betterend.world.features.trees.LacugroveFeature;
|
import ru.betterend.world.features.trees.LacugroveFeature;
|
||||||
import ru.betterend.world.features.trees.MossyGlowshroomFeature;
|
import ru.betterend.world.features.trees.MossyGlowshroomFeature;
|
||||||
import ru.betterend.world.features.trees.PythadendronTreeFeature;
|
import ru.betterend.world.features.trees.PythadendronTreeFeature;
|
||||||
|
import ru.betterend.world.features.trees.TenaneaFeature;
|
||||||
|
|
||||||
public class EndFeatures {
|
public class EndFeatures {
|
||||||
// Trees //
|
// Trees //
|
||||||
|
@ -38,6 +39,7 @@ public class EndFeatures {
|
||||||
public static final EndFeature PYTHADENDRON_TREE = new EndFeature("pythadendron_tree", new PythadendronTreeFeature(), 2);
|
public static final EndFeature PYTHADENDRON_TREE = new EndFeature("pythadendron_tree", new PythadendronTreeFeature(), 2);
|
||||||
public static final EndFeature LACUGROVE = new EndFeature("lacugrove", new LacugroveFeature(), 4);
|
public static final EndFeature LACUGROVE = new EndFeature("lacugrove", new LacugroveFeature(), 4);
|
||||||
public static final EndFeature DRAGON_TREE = new EndFeature("dragon_tree", new DragonTreeFeature(), 3);
|
public static final EndFeature DRAGON_TREE = new EndFeature("dragon_tree", new DragonTreeFeature(), 3);
|
||||||
|
public static final EndFeature TENANEA = new EndFeature("tenanea", new TenaneaFeature(), 3);
|
||||||
|
|
||||||
// Bushes //
|
// Bushes //
|
||||||
public static final EndFeature PYTHADENDRON_BUSH = new EndFeature("pythadendron_bush", new BushFeature(EndBlocks.PYTHADENDRON_LEAVES, EndBlocks.PYTHADENDRON.bark), 4);
|
public static final EndFeature PYTHADENDRON_BUSH = new EndFeature("pythadendron_bush", new BushFeature(EndBlocks.PYTHADENDRON_LEAVES, EndBlocks.PYTHADENDRON.bark), 4);
|
||||||
|
|
|
@ -87,6 +87,15 @@ public class BlocksHelper {
|
||||||
}
|
}
|
||||||
return pos.getY() - POS.getY();
|
return pos.getY() - POS.getY();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int raycastSqr(WorldAccess world, BlockPos pos, int dx, int dy, int dz, int maxDist) {
|
||||||
|
POS.set(pos);
|
||||||
|
for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++)
|
||||||
|
{
|
||||||
|
POS.move(dx, dy, dz);
|
||||||
|
}
|
||||||
|
return (int) pos.getSquaredDistance(POS);
|
||||||
|
}
|
||||||
|
|
||||||
public static BlockState rotateHorizontal(BlockState state, BlockRotation rotation, Property<Direction> facing) {
|
public static BlockState rotateHorizontal(BlockState state, BlockRotation rotation, Property<Direction> facing) {
|
||||||
return (BlockState) state.with(facing, rotation.rotate((Direction) state.get(facing)));
|
return (BlockState) state.with(facing, rotation.rotate((Direction) state.get(facing)));
|
||||||
|
|
|
@ -124,4 +124,13 @@ public class MHelper {
|
||||||
h = (h ^ (h >> 13)) * 1274126177;
|
h = (h ^ (h >> 13)) * 1274126177;
|
||||||
return h ^ (h >> 16);
|
return h ^ (h >> 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> void shuffle(T[] array, Random random) {
|
||||||
|
for (int i = 0; i < array.length; i++) {
|
||||||
|
int i2 = random.nextInt(array.length);
|
||||||
|
T element = array[i];
|
||||||
|
array[i] = array[i2];
|
||||||
|
array[i2] = element;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,112 @@
|
||||||
|
package ru.betterend.world.features.trees;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.block.Blocks;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.BlockPos.Mutable;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
|
import net.minecraft.util.math.Vec3i;
|
||||||
|
import net.minecraft.world.StructureWorldAccess;
|
||||||
|
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||||
|
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
||||||
|
import ru.betterend.util.BlocksHelper;
|
||||||
|
import ru.betterend.util.MHelper;
|
||||||
|
import ru.betterend.world.features.DefaultFeature;
|
||||||
|
|
||||||
|
public class TenaneaFeature extends DefaultFeature {
|
||||||
|
private static final Vec3i[] DIRECTIONS;
|
||||||
|
private static final Vec3i UP;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
|
||||||
|
branch(world, pos, UP, 100, random);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void branch(StructureWorldAccess world, BlockPos pos, Vec3i dir, int length, Random random) {
|
||||||
|
Mutable mut = new Mutable().set(pos);
|
||||||
|
int upCount = 0;
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
MHelper.shuffle(DIRECTIONS, random);
|
||||||
|
boolean up = false;
|
||||||
|
|
||||||
|
BlocksHelper.setWithoutUpdate(world, mut, Blocks.DIAMOND_BLOCK);
|
||||||
|
|
||||||
|
for (Direction hor: BlocksHelper.HORIZONTAL) {
|
||||||
|
if (!isReplaceable(world.getBlockState(mut.offset(hor)))) {
|
||||||
|
upCount = -1;
|
||||||
|
up = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (up) {
|
||||||
|
upCount ++;
|
||||||
|
mut.move(Direction.UP);
|
||||||
|
if (upCount > 8) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
up = true;
|
||||||
|
for (Vec3i d: DIRECTIONS) {
|
||||||
|
BlockPos offseted = mut.add(d.getX(), d.getY(), d.getZ());
|
||||||
|
if (isReplaceable(world.getBlockState(offseted))) {
|
||||||
|
int dist = BlocksHelper.raycastSqr(world, offseted, d.getX(), d.getY(), d.getZ(), 18);
|
||||||
|
if (dist < 64) {
|
||||||
|
mut.move(d.getX(), d.getY(), d.getZ());
|
||||||
|
upCount = 0;
|
||||||
|
up = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (up) {
|
||||||
|
upCount ++;
|
||||||
|
mut.move(Direction.UP);
|
||||||
|
if (upCount > 8) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!world.getBlockState(mut).getMaterial().isReplaceable()) {
|
||||||
|
boolean br = true;
|
||||||
|
for (Direction hor: BlocksHelper.HORIZONTAL) {
|
||||||
|
if (isReplaceable(world.getBlockState(mut.offset(hor)))) {
|
||||||
|
mut.move(hor);
|
||||||
|
br = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (br) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isReplaceable(BlockState state) {
|
||||||
|
return state.getMaterial().isReplaceable();
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
DIRECTIONS = new Vec3i[] {
|
||||||
|
new Vec3i(0, 0, 1),
|
||||||
|
new Vec3i(0, 0, -1),
|
||||||
|
new Vec3i(1, 0, 0),
|
||||||
|
new Vec3i(-1, 0, 0),
|
||||||
|
new Vec3i(1, 0, 1),
|
||||||
|
new Vec3i(1, 0, -1),
|
||||||
|
new Vec3i(-1, 0, 1),
|
||||||
|
new Vec3i(-1, 0, -1),
|
||||||
|
new Vec3i(1, 1, 1),
|
||||||
|
new Vec3i(1, 1, -1),
|
||||||
|
new Vec3i(-1, 1, 1),
|
||||||
|
new Vec3i(-1, 1, -1)
|
||||||
|
};
|
||||||
|
|
||||||
|
UP = new Vec3i(0, 1, 0);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue