Skip to content

Commit

Permalink
More balancing on apples.
Browse files Browse the repository at this point in the history
  • Loading branch information
alesto authored and alesto committed Jan 21, 2019
1 parent 1a63ae0 commit 498a153
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/main/java/growthcraft/apples/common/block/BlockApple.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.block.Block;
import net.minecraft.block.BlockBush;
import net.minecraft.block.IGrowable;
import net.minecraft.block.SoundType;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
Expand Down Expand Up @@ -31,6 +32,10 @@

public class BlockApple extends BlockBush implements IGrowable {

// TODO: Make fields configurable
public static final int CHANCE_GROWTH = 10;
public static final int CHANCE_TO_FALL = 0; // CHANCE_GROWTH * 6; // NOTE: Must be approximately: "maximal production rate" * CHANCE_GROWTH

public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 7);

private static final AxisAlignedBB[] BOUNDING_BOXES = new AxisAlignedBB[]{
Expand All @@ -49,6 +54,7 @@ public BlockApple(String unlocalizedName) {
this.setUnlocalizedName(unlocalizedName);
this.setRegistryName(new ResourceLocation(Reference.MODID, unlocalizedName));
this.setTickRandomly(true);
this.setSoundType(SoundType.WOOD);
}

@Override
Expand Down Expand Up @@ -90,11 +96,20 @@ public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, Bloc
@Override
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
super.updateTick(worldIn, pos, state, rand);
if ( worldIn.getLightFromNeighbors(pos.up()) >= 9) {
if( ForgeHooks.onCropsGrowPre(worldIn, pos, state, rand.nextInt(7) == 0) ) {
grow(worldIn, rand, pos, state);
ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos));
}

if( worldIn.isRemote )
return;

if( ForgeHooks.onCropsGrowPre(worldIn, pos, state, rand.nextInt(CHANCE_GROWTH) == 0) ) {
grow(worldIn, rand, pos, state);
ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos));
}

if( CHANCE_TO_FALL > 0 ) {
if( this.getAge(state) == 7 && rand.nextInt(CHANCE_TO_FALL) == 0 ) {
this.dropBlockAsItem(worldIn, pos, state, 0);
worldIn.setBlockToAir(pos);
}
}
}

Expand All @@ -112,7 +127,7 @@ public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockSt
public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state) {
super.updateTick(worldIn, pos, state, rand);
// If we have enough light there is a 25% chance of growth to the next stage
if ( worldIn.getLightFromNeighbors(pos.up()) >= 9 && rand.nextInt(1) == 0) {
if ( worldIn.getLightFromNeighbors(pos.up()) >= 9 ) {
// If the apple isn't full grown
if ( this.getAge(state) != 7) {
// Then increment the age.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
public class BlockAppleLeaves extends BlockLeaves implements IGrowable {
public static final int LEAVES_COLOR = 0x58e21d; // 0x4fcb1a; // 0x48B518;

// TODO: Make fields configurable
private static final int APPLE_CHECK_AREA = 3;
private static final int MAX_APPLES_IN_AREA = 2;

Expand Down

0 comments on commit 498a153

Please sign in to comment.