Skip to content
Permalink
Browse files

Added fruit tree leaf itemblocks, overhauled fruit tree growth, remov…

…ed fruit tree leaf blocks collision, fixed blockstate errors, fixed saplings and fruit tree branches AABB.
  • Loading branch information...
DisasterMoo committed Jul 16, 2019
1 parent 08907b6 commit 67be259b30eb77f252049f0d145920bf17a604da
@@ -303,6 +303,10 @@ public static void registerColorHandlerItems(ColorHandlerEvent.Item event)
event.getBlockColors().colorMultiplier(((ItemBlock) stack.getItem()).getBlock().getStateFromMeta(stack.getMetadata()), null, null, tintIndex),
BlocksTFC.getAllLeafBlocks().toArray(new BlockLeavesTFC[0]));

itemColors.registerItemColorHandler((stack, tintIndex) ->
event.getBlockColors().colorMultiplier(((ItemBlock) stack.getItem()).getBlock().getStateFromMeta(stack.getMetadata()), null, null, tintIndex),
BlocksTFC.getAllFruitTreeLeavesBlocks().toArray(new BlockFruitTreeLeaves[0]));

itemColors.registerItemColorHandler((stack, tintIndex) -> tintIndex == 1 ? EnumDyeColor.byDyeDamage(stack.getItemDamage()).getColorValue() : 0xFFFFFF,
ItemsTFC.CERAMICS_UNFIRED_VESSEL_GLAZED, ItemsTFC.CERAMICS_FIRED_VESSEL_GLAZED);

@@ -523,6 +523,7 @@ public static void registerBlocks(RegistryEvent.Register<Block> event)

//Add ItemBlocks
allFruitTreeSaplingBlocks.forEach(x -> inventoryItemBlocks.add(new ItemBlockTFC(x)));
allFruitTreeLeavesBlocks.forEach(x -> inventoryItemBlocks.add(new ItemBlockTFC(x)));
}

{
@@ -14,10 +14,12 @@
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
@@ -29,6 +31,10 @@
/* Facing of this branch */
public static final PropertyEnum<EnumFacing> FACING = PropertyEnum.create("facing", EnumFacing.class);

private static final AxisAlignedBB VERTICAL_AABB = new AxisAlignedBB(0.3125D, 0.0D, 0.3125D, 0.6875D, 1.0D, 0.6875D);
private static final AxisAlignedBB HORIZONTAL_Z_AABB = new AxisAlignedBB(0.375D, 0.375D, 0.0D, 0.625, 0.625, 1.0D);
private static final AxisAlignedBB HORIZONTAL_X_AABB = new AxisAlignedBB(0.0D, 0.375D, 0.375D, 1.0D, 0.625, 0.625);

private static final Map<IFruitTree, BlockFruitTreeBranch> MAP = new HashMap<>();

public static BlockFruitTreeBranch get(IFruitTree tree)
@@ -46,7 +52,34 @@ public BlockFruitTreeBranch(IFruitTree tree)
setHarvestLevel("axe", 0);
setSoundType(SoundType.WOOD);
this.tree = tree;
}

@Override
@SuppressWarnings("deprecation")
@Nonnull
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
EnumFacing face = getFacing(source, pos);
if (face == null) return VERTICAL_AABB;
switch (face)
{
case NORTH:
case SOUTH:
return HORIZONTAL_Z_AABB;
case EAST:
case WEST:
return HORIZONTAL_X_AABB;
default:
return VERTICAL_AABB;
}
}

@Override
@Nonnull
@SuppressWarnings("deprecation")
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}

@Override
@@ -19,6 +19,7 @@
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
@@ -27,6 +28,7 @@
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
@@ -70,6 +72,29 @@ public BlockFruitTreeLeaves(IFruitTree tree)
setTickRandomly(true);
}

@SuppressWarnings("deprecation")
@Override
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
{
return NULL_AABB;
}

@Override
public void onEntityCollision(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
{
//Copy-paste from BlockLeavesTFC
//Player will take damage when falling through leaves if fall is over 9 blocks, fall damage is then set to 0.
entityIn.fall((entityIn.fallDistance - 6), 1.0F); // TODO: 17/4/18 Balance fall distance reduction.
entityIn.fallDistance = 0;
//Entity motion is reduced by leaves.
entityIn.motionX *= 0.1D;
if (entityIn.motionY < 0)
{
entityIn.motionY *= 0.1D;
}
entityIn.motionZ *= 0.1D;
}

@SuppressWarnings("deprecation")
@Override
@Nonnull
@@ -23,6 +23,7 @@
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import mcp.MethodsReturnNonnullByDefault;
import net.dries007.tfc.api.types.IFruitTree;
import net.dries007.tfc.objects.te.TETickCounter;
import net.dries007.tfc.util.Helpers;
@@ -31,10 +32,12 @@
import net.dries007.tfc.world.classic.ClimateTFC;
import net.dries007.tfc.world.classic.chunkdata.ChunkDataTFC;

@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class BlockFruitTreeSapling extends BlockBush implements IGrowable
{
protected static final AxisAlignedBB SAPLING_AABB = new AxisAlignedBB(0.1, 0, 0.1, 0.9, 0., 0.9);
private static final AxisAlignedBB SAPLING_AABB = new AxisAlignedBB(0.1, 0, 0.1, 0.9, 0.9, 0.9);

private static final Map<IFruitTree, BlockFruitTreeSapling> MAP = new HashMap<>();

public static BlockFruitTreeSapling get(IFruitTree tree)
@@ -101,6 +104,7 @@ public TileEntity createTileEntity(World world, IBlockState state)
return new TETickCounter();
}


@SuppressWarnings("deprecation")
@Override
@Nonnull
@@ -153,41 +153,94 @@ public void randomTick(World worldIn, BlockPos pos, IBlockState state, Random ra
long hours = te.getTicksSinceUpdate() / ICalendar.TICKS_IN_HOUR;
if (hours > tree.getGrowthTime() && tree.isValidForGrowth(temp, rainfall))
{
if (this.getTrunkHeight(worldIn, pos) < 4)
if (worldIn.getBlockState(pos.up()).getBlock() != this) //If the above block is a trunk, this one don't need to do anything
{
if (worldIn.getBlockState(pos.up()).getMaterial().isReplaceable() || worldIn.getBlockState(pos.up()).getBlock() == BlockFruitTreeLeaves.get(tree))
if (this.getTrunkHeight(worldIn, pos) < 4)
{
worldIn.setBlockState(pos.up(), this.getDefaultState());
}
if (worldIn.getBlockState(pos.up(2)).getMaterial().isReplaceable())
{
worldIn.setBlockState(pos.up(2), BlockFruitTreeLeaves.get(tree).getDefaultState().withProperty(BlockFruitTreeLeaves.HARVESTABLE, false));
BlockPos missingLeaf = getMissingLeaf(worldIn, pos);
if (missingLeaf != null)
{
//Missing leaf, spawn that first
if (worldIn.getBlockState(missingLeaf).getMaterial().isReplaceable())
{
worldIn.setBlockState(missingLeaf, BlockFruitTreeLeaves.get(tree).getDefaultState().withProperty(BlockFruitTreeLeaves.HARVESTABLE, false));
}
}
else
{
//Time to grow one trunk
worldIn.setBlockState(pos.up(), this.getDefaultState());
//Set all remaining leaf blocks to air
levelUpLeaves(worldIn, pos, false);
}
}
}
else
{
for (EnumFacing branchFacing : EnumFacing.VALUES)
else
{
if (branchFacing == EnumFacing.DOWN) continue;
BlockPos branchPos = pos.offset(branchFacing);
if (worldIn.getBlockState(branchPos).getMaterial().isReplaceable() || worldIn.getBlockState(branchPos).getBlock() == BlockFruitTreeLeaves.get(tree))
boolean flag = false; //If true, just grown a leaf/branch
if (worldIn.getBlockState(pos.up()).getBlock() != BlockFruitTreeBranch.get(tree))
{
worldIn.setBlockState(branchPos, BlockFruitTreeBranch.get(tree).getDefaultState());
BlockPos missingLeaf = getMissingLeaf(worldIn, pos);
if (missingLeaf != null)
{
//There is a missing leaf
flag = true;
if (worldIn.getBlockState(missingLeaf).getMaterial().isReplaceable())
{
worldIn.setBlockState(missingLeaf, BlockFruitTreeLeaves.get(tree).getDefaultState().withProperty(BlockFruitTreeLeaves.HARVESTABLE, true));
}
}
else
{
flag = true;
worldIn.setBlockState(pos.up(), BlockFruitTreeBranch.get(tree).getDefaultState());
levelUpLeaves(worldIn, pos, true);
}
}
for (BlockPos leafPos : BlockPos.getAllInBoxMutable(branchPos.add(-1, 0, -1), branchPos.add(1, 0, 1)))
else
{
if (leafPos.equals(branchPos)) continue;
if (worldIn.getBlockState(leafPos).getMaterial().isReplaceable())
BlockPos missingLeaf = getMissingLeaf(worldIn, pos.up()); //Please note that this is pos.up()
if (missingLeaf != null)
{
worldIn.setBlockState(leafPos, BlockFruitTreeLeaves.get(tree).getDefaultState().withProperty(BlockFruitTreeLeaves.HARVESTABLE, true));
//There is a missing leaf
flag = true;
if (worldIn.getBlockState(missingLeaf).getMaterial().isReplaceable())
{
worldIn.setBlockState(missingLeaf, BlockFruitTreeLeaves.get(tree).getDefaultState().withProperty(BlockFruitTreeLeaves.HARVESTABLE, true));
}
}
}
if (branchFacing == EnumFacing.UP)
//Starting with top
for (EnumFacing branchFacing : EnumFacing.VALUES)
{
if (worldIn.getBlockState(branchPos.up()).getMaterial().isReplaceable())
if (flag) break;
if (branchFacing == EnumFacing.DOWN) continue;
BlockPos branchPos = pos.offset(branchFacing);
if (worldIn.getBlockState(branchPos).getMaterial().isReplaceable() || worldIn.getBlockState(branchPos).getBlock() == BlockFruitTreeLeaves.get(tree))
{
flag = true;
worldIn.setBlockState(branchPos, BlockFruitTreeBranch.get(tree).getDefaultState());
}
if (flag) break;
for (BlockPos leafPos : BlockPos.getAllInBoxMutable(branchPos.add(-1, 0, -1), branchPos.add(1, 0, 1)))
{
worldIn.setBlockState(branchPos.up(), BlockFruitTreeLeaves.get(tree).getDefaultState().withProperty(BlockFruitTreeLeaves.HARVESTABLE, true));
if (leafPos.equals(branchPos)) continue;
if (worldIn.getBlockState(leafPos).getMaterial().isReplaceable())
{
flag = true;
worldIn.setBlockState(leafPos, BlockFruitTreeLeaves.get(tree).getDefaultState().withProperty(BlockFruitTreeLeaves.HARVESTABLE, true));
}
if (flag) break;
}
if (flag) break;
if (branchFacing == EnumFacing.UP)
{
if (worldIn.getBlockState(branchPos.up()).getMaterial().isReplaceable())
{
flag = true;
worldIn.setBlockState(branchPos.up(), BlockFruitTreeLeaves.get(tree).getDefaultState().withProperty(BlockFruitTreeLeaves.HARVESTABLE, true));
}
}
if (flag) break;
}
}
}
@@ -197,6 +250,54 @@ public void randomTick(World worldIn, BlockPos pos, IBlockState state, Random ra
}
}

@Nullable
private BlockPos getMissingLeaf(World world, BlockPos pos)
{
//Helper method, checks if all 5 leafs blocks(horizontals + above) has a missing block leaf

//Above first
if (world.getBlockState(pos.offset(EnumFacing.UP)).getBlock() != BlockFruitTreeLeaves.get(tree))
{
return pos.offset(EnumFacing.UP);
}
for (EnumFacing facing : EnumFacing.HORIZONTALS)
{
if (world.getBlockState(pos.offset(facing)).getBlock() != BlockFruitTreeLeaves.get(tree))
{
return pos.offset(facing);
}
}
return null;
}

private void levelUpLeaves(World world, BlockPos oldCenter, boolean hasvestable)
{
//Remove the old ones
for (EnumFacing facing : EnumFacing.HORIZONTALS)
{
if (world.getBlockState(oldCenter.offset(facing)).getBlock() == BlockFruitTreeLeaves.get(tree))
{
world.setBlockToAir(oldCenter.offset(facing));
}
}
BlockPos missingLeaf = null;
//noinspection ConstantConditions
do
{
//Respawn leafs in the new height
missingLeaf = getMissingLeaf(world, oldCenter.up());
if (missingLeaf != null && world.getBlockState(missingLeaf).getMaterial().isReplaceable())
{
world.setBlockState(missingLeaf, BlockFruitTreeLeaves.get(tree).getDefaultState().withProperty(BlockFruitTreeLeaves.HARVESTABLE, hasvestable));
}
else
{
//Found a block(ceiling?) that prevents this tree to grow leafs, aborting
break;
}
} while (missingLeaf != null);
}

@Override
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
@@ -36,7 +36,7 @@
public class BlockSaplingTFC extends BlockBush implements IGrowable
{
public static final PropertyInteger STAGE = PropertyInteger.create("stage", 0, 4);
protected static final AxisAlignedBB SAPLING_AABB = new AxisAlignedBB(0.1, 0, 0.1, 0.9, 0., 0.9);
protected static final AxisAlignedBB SAPLING_AABB = new AxisAlignedBB(0.1, 0, 0.1, 0.9, 0.9, 0.9);
private static final Map<Tree, BlockSaplingTFC> MAP = new HashMap<>();

public static BlockSaplingTFC get(Tree wood)

0 comments on commit 67be259

Please sign in to comment.
You can’t perform that action at this time.