Skip to content

Commit

Permalink
Merge pull request #288 from GrowthcraftCE/bugfix/Growthcraft-1.12-26…
Browse files Browse the repository at this point in the history
…5-Chunk-Lag

Bugfix/growthcraft 1.12 265 chunk lag
  • Loading branch information
Alatyami authored Dec 15, 2019
2 parents 0afba45 + 3461fc2 commit 975abdd
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 138 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Growthcraft
===========
[![](http://cf.way2muchnoise.eu/versions/growthcraft-community-edition_latest.svg)](https://minecraft.curseforge.com/projects/growthcraft-community-edition/)
[![Growthcraft Version](https://img.shields.io/badge/Growthcraft-4.1.1.200-orange.svg)](https://github.com/GrowthcraftCE/Growthcraft-1.12)
[![Growthcraft Version](https://img.shields.io/badge/Growthcraft-4.1.1.300-orange.svg)](https://github.com/GrowthcraftCE/Growthcraft-1.12)
[![Forge Version](https://img.shields.io/badge/Minecraft%20Forge-14.23.4.2768-yellow.svg)](http://files.minecraftforge.net/maven/net/minecraftforge/forge/index_1.12.2.html)
[![Java Version](https://img.shields.io/badge/JAVA-8-blue.svg)](https://www.java.com/en/)
[![Build Status](https://travis-ci.org/GrowthcraftCE/Growthcraft-1.12.svg?branch=development)](https://travis-ci.org/GrowthcraftCE/Growthcraft-1.12)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx3G
org.gradle.logging.level=warn

# Growthcraft Version
mod_version=4.1.1.200
mod_version=4.1.1.300

# Minecraft Versions
minecraft_version=1.12.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.block.IGrowable;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
Expand Down Expand Up @@ -50,14 +51,13 @@ public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state) {
}

private boolean canSustainApple(World worldIn, BlockPos pos, IBlockState state) {
if (state.getBlock() != this)
if (state.getBlock() != this || !state.getValue(DECAYABLE))
return false;
if (!state.getValue(DECAYABLE))
return false; // Not originally growing on tree, so no apples.

Block block = worldIn.getBlockState(pos.down()).getBlock();
if (!(block instanceof BlockAir))
return false;

return true;
}

Expand Down Expand Up @@ -116,4 +116,8 @@ protected void dropApple(World worldIn, BlockPos pos, IBlockState state, int cha
}
}

@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
return GrowthcraftApplesBlocks.blockAppleSapling.getItem();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
import java.io.IOException;

public class TileEntityFermentBarrel extends TileEntityCellarDevice implements IInventory, ITickable, ITileProgressiveDevice, INBTItemSerializable {
public static enum FermentBarrelDataID {

private static final String NBTNAME = "ferment_barrel";

public enum FermentBarrelDataID {
TIME,
TIME_MAX,
UNKNOWN;
Expand Down Expand Up @@ -95,9 +98,7 @@ public int getDeviceProgressScaled(int scale) {
@Override
public void update() {
if (!world.isRemote) {
world.markBlockRangeForRenderUpdate(pos, pos);
world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 3);
world.scheduleBlockUpdate(pos, getBlockType(), 0, 0);
this.markDirtyAndUpdate();
fermentBarrel.update();
}
}
Expand Down Expand Up @@ -134,23 +135,23 @@ protected void readTanksFromNBT(NBTTagCompound nbt) {
@Override
public void readFromNBTForItem(NBTTagCompound nbt) {
super.readFromNBTForItem(nbt);
fermentBarrel.readFromNBT(nbt, "ferment_barrel");
fermentBarrel.readFromNBT(nbt, NBTNAME);
}

@TileEventHandler(event = TileEventHandler.EventType.NBT_READ)
public void readFromNBT_FermentBarrel(NBTTagCompound nbt) {
fermentBarrel.readFromNBT(nbt, "ferment_barrel");
fermentBarrel.readFromNBT(nbt, NBTNAME);
}

@Override
public void writeToNBTForItem(NBTTagCompound nbt) {
super.writeToNBTForItem(nbt);
fermentBarrel.writeToNBT(nbt, "ferment_barrel");
fermentBarrel.writeToNBT(nbt, NBTNAME);
}

@TileEventHandler(event = TileEventHandler.EventType.NBT_WRITE)
public void writeToNBT_FermentBarrel(NBTTagCompound nbt) {
fermentBarrel.writeToNBT(nbt, "ferment_barrel");
fermentBarrel.writeToNBT(nbt, NBTNAME);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/growthcraft/core/shared/Reference.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ private Reference() {

public static final String MODID = "growthcraft";
public static final String NAME = "GrowthcraftCore";
public static final String VERSION = "4.1.1.200";
public static final String VERSION = "4.1.1.300";
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package growthcraft.core.shared.block;

import growthcraft.core.shared.definition.BlockDefinition;
import net.minecraft.block.BlockAir;
import net.minecraft.block.BlockLeaves;
import net.minecraft.block.BlockPlanks;
import net.minecraft.block.properties.IProperty;
Expand Down Expand Up @@ -123,6 +124,7 @@ public int damageDropped(IBlockState state) {

@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {

return blockSapling.getItem();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenAbstractTree;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class GrowthcraftTreeWorldGen extends WorldGenAbstractTree {
Expand All @@ -16,6 +18,8 @@ public class GrowthcraftTreeWorldGen extends WorldGenAbstractTree {
private Block blockLog;
private Block blockLeaves;

private Random random = new Random();

public GrowthcraftTreeWorldGen(Block blockLog, Block blockLeaves, int minTreeHeight, int maxTreeHeight, boolean notify) {
super(notify);
this.blockLog = blockLog;
Expand All @@ -35,123 +39,24 @@ public boolean generate(World worldIn, Random rand, BlockPos pos) {
if (!worldIn.isRemote) {
final int maxGrowthHeight = rand.nextInt(maxTreeHeight - minTreeHeight) + minTreeHeight;

BlockPos baseBlockPos = pos.down();

if (canGrow(worldIn, pos, maxGrowthHeight)) {
worldIn.setBlockState(pos, blockLog.getDefaultState());
// Spawn the wood logs for the tree.
for (int i = 1; i <= maxGrowthHeight; i++) {
worldIn.setBlockState(pos.up(i), blockLog.getDefaultState());
if (i == maxGrowthHeight) {
// Top layer
spawnLeaves(worldIn, pos.up(i + 1));
spawnLeaves(worldIn, pos.up(i + 1).north());
spawnLeaves(worldIn, pos.up(i + 1).east());
spawnLeaves(worldIn, pos.up(i + 1).south());
spawnLeaves(worldIn, pos.up(i + 1).west());

// Top Layer -1
spawnLeaves(worldIn, pos.up(i).north());
spawnLeaves(worldIn, pos.up(i).north(2));

spawnLeaves(worldIn, pos.up(i).east());
spawnLeaves(worldIn, pos.up(i).east().north());
spawnLeaves(worldIn, pos.up(i).east().north(2));
spawnLeaves(worldIn, pos.up(i).east(2));
spawnLeaves(worldIn, pos.up(i).east(2).north());
spawnLeaves(worldIn, pos.up(i).east().south());
spawnLeaves(worldIn, pos.up(i).east().south(2));
spawnLeaves(worldIn, pos.up(i).east(2).south());

spawnLeaves(worldIn, pos.up(i).west());
spawnLeaves(worldIn, pos.up(i).west().north());
spawnLeaves(worldIn, pos.up(i).west().north(2));
spawnLeaves(worldIn, pos.up(i).west(2));
spawnLeaves(worldIn, pos.up(i).west(2).north());
spawnLeaves(worldIn, pos.up(i).west().south());
spawnLeaves(worldIn, pos.up(i).west().south(2));

spawnLeaves(worldIn, pos.up(i).south());
spawnLeaves(worldIn, pos.up(i).south(2));

// Top Layer -2
spawnLeaves(worldIn, pos.up(i - 1).north());
spawnLeaves(worldIn, pos.up(i - 1).north(2));
spawnLeaves(worldIn, pos.up(i - 1).north(3));

spawnLeaves(worldIn, pos.up(i - 1).east());
spawnLeaves(worldIn, pos.up(i - 1).east().north());
spawnLeaves(worldIn, pos.up(i - 1).east().north(2));
spawnLeaves(worldIn, pos.up(i - 1).east().north(3));
spawnLeaves(worldIn, pos.up(i - 1).east().south());
spawnLeaves(worldIn, pos.up(i - 1).east().south(2));
spawnLeaves(worldIn, pos.up(i - 1).east().south(3));
spawnLeaves(worldIn, pos.up(i - 1).east(2));
spawnLeaves(worldIn, pos.up(i - 1).east(2).north());
spawnLeaves(worldIn, pos.up(i - 1).east(2).north(2));
spawnLeaves(worldIn, pos.up(i - 1).east(2).south());
spawnLeaves(worldIn, pos.up(i - 1).east(2).south(2));
spawnLeaves(worldIn, pos.up(i - 1).east(3));
spawnLeaves(worldIn, pos.up(i - 1).east(3).north());
spawnLeaves(worldIn, pos.up(i - 1).east(3).north(2));
spawnLeaves(worldIn, pos.up(i - 1).east(3).south());

spawnLeaves(worldIn, pos.up(i - 1).west());
spawnLeaves(worldIn, pos.up(i - 1).west().north());
spawnLeaves(worldIn, pos.up(i - 1).west().north(2));
spawnLeaves(worldIn, pos.up(i - 1).west().north(3));
spawnLeaves(worldIn, pos.up(i - 1).west().south());
spawnLeaves(worldIn, pos.up(i - 1).west().south(2));
spawnLeaves(worldIn, pos.up(i - 1).west().south(3));
spawnLeaves(worldIn, pos.up(i - 1).west(2));
spawnLeaves(worldIn, pos.up(i - 1).west(2).north());
spawnLeaves(worldIn, pos.up(i - 1).west(2).north(2));
spawnLeaves(worldIn, pos.up(i - 1).west(2).south());
spawnLeaves(worldIn, pos.up(i - 1).west(2).south(1));
spawnLeaves(worldIn, pos.up(i - 1).west(3));
spawnLeaves(worldIn, pos.up(i - 1).west(3).north());
spawnLeaves(worldIn, pos.up(i - 1).west(3).south());

spawnLeaves(worldIn, pos.up(i - 1).south());
spawnLeaves(worldIn, pos.up(i - 1).south(2));
spawnLeaves(worldIn, pos.up(i - 1).south(3));

// Top Layer -3
spawnLeaves(worldIn, pos.up(i - 2).north());
spawnLeaves(worldIn, pos.up(i - 2).north(2));
spawnLeaves(worldIn, pos.up(i - 2).north(3));

spawnLeaves(worldIn, pos.up(i - 2).east());
spawnLeaves(worldIn, pos.up(i - 2).east().north());
spawnLeaves(worldIn, pos.up(i - 2).east().north(2));
spawnLeaves(worldIn, pos.up(i - 2).east().north(3));
spawnLeaves(worldIn, pos.up(i - 2).east().south());
spawnLeaves(worldIn, pos.up(i - 2).east().south(2));
spawnLeaves(worldIn, pos.up(i - 2).east(2));
spawnLeaves(worldIn, pos.up(i - 2).east(2).north());
spawnLeaves(worldIn, pos.up(i - 2).east(2).south());
spawnLeaves(worldIn, pos.up(i - 2).east(2).south(2));
spawnLeaves(worldIn, pos.up(i - 2).east(2).north(2));
spawnLeaves(worldIn, pos.up(i - 2).east(3));
spawnLeaves(worldIn, pos.up(i - 2).east(3).south());

spawnLeaves(worldIn, pos.up(i - 2).west());
spawnLeaves(worldIn, pos.up(i - 2).west().north());
spawnLeaves(worldIn, pos.up(i - 2).west().north(2));
spawnLeaves(worldIn, pos.up(i - 2).west().north(3));
spawnLeaves(worldIn, pos.up(i - 2).west().south());
spawnLeaves(worldIn, pos.up(i - 2).west().south(2));
spawnLeaves(worldIn, pos.up(i - 2).west().south(3));
spawnLeaves(worldIn, pos.up(i - 2).west(2));
spawnLeaves(worldIn, pos.up(i - 2).west(2).north());
spawnLeaves(worldIn, pos.up(i - 2).west(2).north(2));
spawnLeaves(worldIn, pos.up(i - 2).west(2).south());
spawnLeaves(worldIn, pos.up(i - 2).west(2).south(2));
spawnLeaves(worldIn, pos.up(i - 2).west(3));
spawnLeaves(worldIn, pos.up(i - 2).west(3).north());
spawnLeaves(worldIn, pos.up(i - 2).west(3).south());

spawnLeaves(worldIn, pos.up(i - 2).south());
spawnLeaves(worldIn, pos.up(i - 2).south(2));
spawnLeaves(worldIn, pos.up(i - 2).south(3));
worldIn.setBlockState(baseBlockPos.up(i), blockLog.getDefaultState());
}

// Spawn the leaves downward, starting at max height + 1.
for (int layerId = maxGrowthHeight + 1; layerId >= maxGrowthHeight - 4; layerId--) {
if (layerId == maxGrowthHeight + 1) {
spawnLeavesOnRadius(worldIn, pos.up(layerId), 1, false);
} else if (layerId == maxGrowthHeight) {
spawnLeavesOnRadius(worldIn, pos.up(layerId), 2, false);
} else if (layerId == maxGrowthHeight - 1) {
spawnLeavesOnRadius(worldIn, pos.up(layerId), 3, true);
} else if ( layerId == maxGrowthHeight - 2 ) {
spawnLeavesOnRadius(worldIn, pos.up(layerId), 3, true);
}
}

Expand All @@ -171,12 +76,40 @@ private boolean canGrow(World worldIn, BlockPos pos, int growthHeight) {
return true;
}

/**
* Spawn a given block leaves at the given block pos.
* @param worldIn The world instance.
* @param pos BlockPos to spawn a leaf block.
*/
private void spawnLeaves(World worldIn, BlockPos pos) {
if (isReplaceable(worldIn, pos)) {
worldIn.setBlockState(pos, blockLeaves.getDefaultState());
}
}

/**
* Spawn a set leaves around a give block position.
* @param worldIn The world object.
* @param centerPos Center of the area to spawn leaves.
* @param radius Radius to spawn the leaves.
* @param randomLeaves Determine if leaves should be random.
*/
private void spawnLeavesOnRadius(World worldIn, BlockPos centerPos, int radius, boolean randomLeaves) {
// List of block positions to spawn leaves.
BlockPos posUpperLeft = new BlockPos(centerPos.getX() + radius, centerPos.getY(), centerPos.getZ() + radius );
BlockPos posLowerRight = new BlockPos(centerPos.getX() - radius, centerPos.getY(), centerPos.getZ() - radius );

Iterable<BlockPos> blockPosList = BlockPos.getAllInBox(posUpperLeft, posLowerRight);

blockPosList.forEach( blockPos -> {
boolean spawnBlock = true;
// Check if there is already a block in this position.
if ( worldIn.getBlockState(blockPos).getBlock() instanceof BlockAir ) {
//if ( randomLeaves && random.nextInt(100) <= 5 ) spawnBlock = false;
if ( spawnBlock ) spawnLeaves(worldIn, blockPos);
}
} );

}

}
Loading

0 comments on commit 975abdd

Please sign in to comment.