added the ancient tree

This commit is contained in:
Ellpeck 2018-10-13 23:46:30 +02:00
parent 1a099ae221
commit 2be1a57e7a
20 changed files with 600 additions and 9 deletions

View file

@ -1,6 +1,6 @@
package de.ellpeck.naturesaura;
import de.ellpeck.naturesaura.blocks.OurBlocks;
import de.ellpeck.naturesaura.blocks.ModBlocks;
import de.ellpeck.naturesaura.proxy.IProxy;
import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.creativetab.CreativeTabs;
@ -37,7 +37,7 @@ public final class NaturesAura {
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
new OurBlocks();
new ModBlocks();
ModRegistry.preInit(event);
proxy.preInit(event);
}

View file

@ -0,0 +1,152 @@
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityAncientLeaves;
import de.ellpeck.naturesaura.reg.*;
import net.minecraft.block.BlockLeaves;
import net.minecraft.block.BlockPlanks;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.color.IBlockColor;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Random;
public class BlockAncientLeaves extends BlockLeaves implements
IModItem, IModelProvider, IColorProvidingBlock, IColorProvidingItem, ITileEntityProvider {
public BlockAncientLeaves() {
this.leavesFancy = true;
ModRegistry.addItemOrBlock(this);
}
@Override
public String getBaseName() {
return "ancient_leaves";
}
@Override
public boolean shouldAddCreative() {
return true;
}
@Override
public void onPreInit(FMLPreInitializationEvent event) {
}
@Override
public void onInit(FMLInitializationEvent event) {
GameRegistry.registerTileEntity(TileEntityAncientLeaves.class, new ResourceLocation(NaturesAura.MOD_ID, "ancient_leaves"));
}
@Override
public void onPostInit(FMLPostInitializationEvent event) {
}
@Override
public Map<ItemStack, ModelVariant> getModelLocations() {
return Collections.singletonMap(new ItemStack(this), new ModelVariant(new ResourceLocation(NaturesAura.MOD_ID, this.getBaseName()), "inventory"));
}
@Override
public List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) {
return Collections.singletonList(new ItemStack(this, 1, 0));
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, CHECK_DECAY, DECAYABLE);
}
@Override
public IBlockState getStateFromMeta(int meta) {
boolean check = (meta & 1) != 0;
boolean decay = (meta & 2) != 0;
return this.getDefaultState().withProperty(CHECK_DECAY, check).withProperty(DECAYABLE, decay);
}
@Override
public int getMetaFromState(IBlockState state) {
boolean check = state.getValue(CHECK_DECAY);
boolean decay = state.getValue(DECAYABLE);
return (check ? 1 : 0) | (decay ? 1 : 0) << 1;
}
@Override
public void beginLeavesDecay(IBlockState state, World world, BlockPos pos) {
if (!state.getValue(CHECK_DECAY) && state.getValue(DECAYABLE)) {
world.setBlockState(pos, state.withProperty(CHECK_DECAY, true), 4);
}
}
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
super.breakBlock(worldIn, pos, state);
worldIn.removeTileEntity(pos);
}
@Override
public BlockPlanks.EnumType getWoodType(int meta) {
return null;
}
@Nullable
@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
return new TileEntityAncientLeaves();
}
@Override
@SideOnly(Side.CLIENT)
public IBlockColor getBlockColor() {
return (state, worldIn, pos, tintIndex) -> 0xE480D9;
}
@Override
@SideOnly(Side.CLIENT)
public IItemColor getItemColor() {
return (stack, tintIndex) -> 0xE480D9;
}
@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
super.randomDisplayTick(stateIn, worldIn, pos, rand);
if (rand.nextFloat() >= 0.9F && !worldIn.getBlockState(pos.down()).isFullBlock()) {
NaturesAura.proxy.spawnMagicParticle(worldIn,
pos.getX() + rand.nextDouble(), pos.getY(), pos.getZ() + rand.nextDouble(),
0F, 0F, 0F, 0xc46df9,
rand.nextFloat() * 2F + 0.5F,
rand.nextInt(100) + 150,
rand.nextFloat() * 0.05F + 0.005F, true);
}
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
return Item.getItemFromBlock(ModBlocks.ANCIENT_SAPLING);
}
}

View file

@ -0,0 +1,69 @@
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.IModelProvider;
import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.block.BlockLog;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import java.util.Collections;
import java.util.Map;
public class BlockAncientLog extends BlockLog implements IModItem, IModelProvider {
public BlockAncientLog() {
ModRegistry.addItemOrBlock(this);
}
@Override
public String getBaseName() {
return "ancient_log";
}
@Override
public boolean shouldAddCreative() {
return true;
}
@Override
public void onPreInit(FMLPreInitializationEvent event) {
}
@Override
public void onInit(FMLInitializationEvent event) {
}
@Override
public void onPostInit(FMLPostInitializationEvent event) {
}
@Override
public Map<ItemStack, ModelVariant> getModelLocations() {
return Collections.singletonMap(new ItemStack(this), new ModelVariant(new ResourceLocation(NaturesAura.MOD_ID, this.getBaseName()), "inventory"));
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, LOG_AXIS);
}
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(LOG_AXIS).ordinal();
}
@Override
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState().withProperty(LOG_AXIS, EnumAxis.values()[meta]);
}
}

View file

@ -0,0 +1,121 @@
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.gen.WorldGenAncientTree;
import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.IModelProvider;
import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.block.BlockBush;
import net.minecraft.block.BlockSapling;
import net.minecraft.block.IGrowable;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.event.terraingen.TerrainGen;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import java.util.Collections;
import java.util.Map;
import java.util.Random;
public class BlockAncientSapling extends BlockBush implements IGrowable, IModItem, IModelProvider {
private static final AxisAlignedBB AABB = new AxisAlignedBB(
0.09999999403953552D, 0.0D, 0.09999999403953552D,
0.8999999761581421D, 0.800000011920929D, 0.8999999761581421D);
public BlockAncientSapling() {
this.setHardness(0.0F);
this.setSoundType(SoundType.PLANT);
ModRegistry.addItemOrBlock(this);
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
return AABB;
}
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
if (!world.isRemote) {
super.updateTick(world, pos, state, rand);
if (world.getLightFromNeighbors(pos.up()) >= 9 && rand.nextInt(7) == 0) {
this.grow(world, rand, pos, state);
}
}
}
@Override
public Map<ItemStack, ModelVariant> getModelLocations() {
return Collections.singletonMap(new ItemStack(this), new ModelVariant(new ResourceLocation(NaturesAura.MOD_ID, this.getBaseName()), "inventory"));
}
@Override
public String getBaseName() {
return "ancient_sapling";
}
@Override
public boolean shouldAddCreative() {
return true;
}
@Override
public void onPreInit(FMLPreInitializationEvent event) {
}
@Override
public void onInit(FMLInitializationEvent event) {
}
@Override
public void onPostInit(FMLPostInitializationEvent event) {
}
@Override
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState().withProperty(BlockSapling.STAGE, meta);
}
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(BlockSapling.STAGE);
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, BlockSapling.STAGE);
}
@Override
public boolean canGrow(World world, BlockPos pos, IBlockState state, boolean isClient) {
return true;
}
@Override
public boolean canUseBonemeal(World world, Random rand, BlockPos pos, IBlockState state) {
return world.rand.nextFloat() < 0.45F;
}
@Override
public void grow(World world, Random rand, BlockPos pos, IBlockState state) {
if (state.getValue(BlockSapling.STAGE) == 0) {
world.setBlockState(pos, state.cycleProperty(BlockSapling.STAGE), 4);
} else if (TerrainGen.saplingGrowTree(world, rand, pos)) {
new WorldGenAncientTree(true).generate(world, rand, pos);
}
}
}

View file

@ -5,6 +5,7 @@ import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.IModelProvider;
import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
@ -54,4 +55,9 @@ public class BlockImpl extends Block implements IModItem, IModelProvider {
public Map<ItemStack, ModelVariant> getModelLocations() {
return Collections.singletonMap(new ItemStack(this), new ModelVariant(new ResourceLocation(NaturesAura.MOD_ID, this.getBaseName()), "inventory"));
}
@Override
public Block setSoundType(SoundType sound) {
return super.setSoundType(sound);
}
}

View file

@ -0,0 +1,13 @@
package de.ellpeck.naturesaura.blocks;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
public final class ModBlocks {
public static final Block ANCIENT_LOG = new BlockAncientLog();
public static final Block ANCIENT_BARK = new BlockImpl("ancient_bark", Material.WOOD).setSoundType(SoundType.WOOD).setHardness(2F);
public static final Block ANCIENT_LEAVES = new BlockAncientLeaves();
public static final Block ANCIENT_SAPLING = new BlockAncientSapling();
}

View file

@ -1,6 +0,0 @@
package de.ellpeck.naturesaura.blocks;
public final class OurBlocks {
}

View file

@ -0,0 +1,4 @@
package de.ellpeck.naturesaura.blocks.tiles;
public class TileEntityAncientLeaves extends TileEntityImpl {
}

View file

@ -0,0 +1,138 @@
package de.ellpeck.naturesaura.gen;
import de.ellpeck.naturesaura.blocks.ModBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLeaves;
import net.minecraft.block.BlockLog;
import net.minecraft.block.BlockLog.EnumAxis;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenAbstractTree;
import java.util.Random;
public class WorldGenAncientTree extends WorldGenAbstractTree {
public WorldGenAncientTree(boolean notify) {
super(notify);
}
@Override
public boolean generate(World world, Random rand, BlockPos pos) {
int height = rand.nextInt(3) + 5;
BlockPos trunkTop = pos.up(height);
//Roots
int rootsAmount = rand.nextInt(4) + 5;
for (int i = 0; i < rootsAmount; i++) {
int length = rand.nextInt(3) + 3;
float angle = 2F * (float) Math.PI * (i / (float) rootsAmount);
float x = (float) Math.sin(angle) * length;
float z = (float) Math.cos(angle) * length;
BlockPos goal = pos.add(x, 0, z);
while (!world.getBlockState(goal).isFullBlock()) {
goal = goal.down();
}
this.makeBranch(world, pos.up(rand.nextInt(1)), goal, ModBlocks.ANCIENT_BARK.getDefaultState(), false);
}
//Trunk
for (int x = 0; x <= 1; x++) {
for (int z = 0; z <= 1; z++) {
for (int i = height - (x + z) * (rand.nextInt(2) + 2); i >= 0; i--) {
BlockPos goal = pos.add(x, i, z);
if (this.isReplaceable(world, goal)) {
this.setBlockAndNotifyAdequately(world, goal,
ModBlocks.ANCIENT_LOG.getDefaultState().withProperty(BlockLog.LOG_AXIS, EnumAxis.Y));
}
}
}
}
this.makeLeaves(world, trunkTop.up(rand.nextInt(2) - 1),
ModBlocks.ANCIENT_LEAVES.getDefaultState().withProperty(BlockLeaves.CHECK_DECAY, false), rand.nextInt(2) + 3, rand);
//Branches
int branchAmount = rand.nextInt(3) + 4;
for (int i = 0; i < branchAmount; i++) {
int length = rand.nextInt(2) + 3;
float angle = 2F * (float) Math.PI * (i / (float) branchAmount);
float x = (float) Math.sin(angle) * length;
float z = (float) Math.cos(angle) * length;
BlockPos goal = trunkTop.add(x, rand.nextInt(3) + 1, z);
this.makeBranch(world, trunkTop, goal, ModBlocks.ANCIENT_LOG.getDefaultState(), true);
this.makeLeaves(world, goal,
ModBlocks.ANCIENT_LEAVES.getDefaultState().withProperty(BlockLeaves.CHECK_DECAY, false), rand.nextInt(2) + 2, rand);
}
return true;
}
@Override
protected boolean canGrowInto(Block blockType) {
if (super.canGrowInto(blockType)) {
return true;
} else {
Material material = blockType.getDefaultState().getMaterial();
return material == Material.VINE || material == Material.PLANTS;
}
}
private void makeBranch(World world, BlockPos first, BlockPos second, IBlockState state, boolean hasAxis) {
BlockPos pos = second.add(-first.getX(), -first.getY(), -first.getZ());
int length = this.getHighestCoord(pos);
float stepX = (float) pos.getX() / (float) length;
float stepY = (float) pos.getY() / (float) length;
float stepZ = (float) pos.getZ() / (float) length;
for (int i = 0; i <= length; i++) {
BlockPos goal = first.add((0.5F + i * stepX), (0.5F + i * stepY), (0.5F + i * stepZ));
if (this.isReplaceable(world, goal)) {
if (hasAxis) {
EnumAxis axis = this.getLogAxis(first, goal);
this.setBlockAndNotifyAdequately(world, goal, state.withProperty(BlockLog.LOG_AXIS, axis));
} else {
this.setBlockAndNotifyAdequately(world, goal, state);
}
}
}
}
private void makeLeaves(World world, BlockPos pos, IBlockState state, int radius, Random rand) {
for (int x = -radius; x <= radius; x++) {
for (int y = -radius; y <= radius; y++) {
for (int z = -radius; z <= radius; z++) {
BlockPos goal = pos.add(x, y, z);
if (pos.distanceSq(goal) <= radius * radius + rand.nextInt(3) - 1) {
if (this.isReplaceable(world, goal) && !(world.getBlockState(goal).getBlock() instanceof BlockLog)) {
this.setBlockAndNotifyAdequately(world, goal, state);
}
}
}
}
}
}
private int getHighestCoord(BlockPos pos) {
return Math.max(MathHelper.abs(pos.getX()), Math.max(MathHelper.abs(pos.getY()), MathHelper.abs(pos.getZ())));
}
private EnumAxis getLogAxis(BlockPos pos, BlockPos goal) {
EnumAxis axis = EnumAxis.Y;
int x = Math.abs(goal.getX() - pos.getX());
int y = Math.abs(goal.getZ() - pos.getZ());
int highest = Math.max(x, y);
if (highest > 0) {
if (x == highest) {
axis = EnumAxis.X;
} else if (y == highest) {
axis = EnumAxis.Z;
}
}
return axis;
}
}

View file

@ -12,7 +12,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ParticleMagic extends Particle {
public static final ResourceLocation TEXTURE = new ResourceLocation(NaturesAura.MOD_ID, "particle/magic_round");
public static final ResourceLocation TEXTURE = new ResourceLocation(NaturesAura.MOD_ID, "particles/magic_round");
private final float desiredScale;

View file

@ -0,0 +1,14 @@
{
"forge_marker": 1,
"defaults": {
"model": "minecraft:cube_all",
"textures": {
"all": "naturesaura:blocks/ancient_log"
},
"transform": "forge:default-block"
},
"variants": {
"normal": [{}],
"inventory": [{}]
}
}

View file

@ -0,0 +1,22 @@
{
"forge_marker": 1,
"defaults": {
"model": "minecraft:leaves",
"textures": {
"all": "naturesaura:blocks/ancient_leaves"
},
"transform": "forge:default-block"
},
"variants": {
"normal": [{}],
"inventory": [{}],
"decayable": {
"true": {},
"false": {}
},
"check_decay": {
"true": {},
"false": {}
}
}
}

View file

@ -0,0 +1,26 @@
{
"forge_marker": 1,
"defaults": {
"model": "minecraft:cube_column",
"textures": {
"end": "naturesaura:blocks/ancient_log_top",
"side": "naturesaura:blocks/ancient_log"
},
"transform": "forge:default-block"
},
"variants": {
"normal": [{}],
"inventory": [{}],
"axis": {
"y": {},
"z": {
"x": 90
},
"x": {
"x": 90,
"y": 90
},
"none": {}
}
}
}

View file

@ -0,0 +1,26 @@
{
"forge_marker": 1,
"defaults": {
"model": "minecraft:cross",
"textures": {
"cross": "naturesaura:blocks/ancient_sapling"
},
"transform": "forge:default-block"
},
"variants": {
"normal": [{}],
"inventory": [
{
"model": "builtin/generated",
"transform": "forge:default-item",
"textures": {
"layer0": "naturesaura:blocks/ancient_sapling"
}
}
],
"stage": {
"0": {},
"1": {}
}
}
}

View file

@ -0,0 +1,6 @@
itemGroup.naturesaura=Nature's Aura
tile.naturesaura.ancient_log.name=Ancient Log
tile.naturesaura.ancient_bark.name=Ancient Bark
tile.naturesaura.ancient_leaves.name=Ancient Leaves
tile.naturesaura.ancient_sapling.name=Ancient Sapling

Binary file not shown.

After

Width:  |  Height:  |  Size: 407 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 606 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 540 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 753 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 576 B