-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The implementation of grass growth has been moved to a separate class
- Loading branch information
1 parent
91f1ab1
commit 0ddf616
Showing
3 changed files
with
126 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
...-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/event/OnEventOvergrowingGrass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package org.imesense.dynamicspawncontrol.event; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockDoublePlant; | ||
import net.minecraft.block.BlockTallGrass; | ||
import net.minecraft.block.state.IBlockState; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.init.Blocks; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||
import net.minecraftforge.fml.common.gameevent.TickEvent; | ||
import org.imesense.dynamicspawncontrol.DynamicSpawnControlStructure; | ||
import org.imesense.dynamicspawncontrol.core.field.UniqueField; | ||
import org.imesense.dynamicspawncontrol.core.logfile.Log; | ||
import org.imesense.dynamicspawncontrol.core.util.CodeGeneric; | ||
|
||
/** | ||
* | ||
*/ | ||
@Mod.EventBusSubscriber(modid = DynamicSpawnControlStructure.STRUCT_INFO_MOD.MOD_ID) | ||
public final class OnEventOvergrowingGrass | ||
{ | ||
/** | ||
* | ||
*/ | ||
private static volatile int _TICK_COUNTER = 0; | ||
|
||
/** | ||
* | ||
*/ | ||
private static boolean instanceExists = false; | ||
|
||
/** | ||
* | ||
*/ | ||
public OnEventOvergrowingGrass() | ||
{ | ||
CodeGeneric.printInitClassToLog(this.getClass()); | ||
|
||
if (instanceExists) | ||
{ | ||
Log.writeDataToLogFile(2, String.format("An instance of [%s] already exists!", this.getClass().getSimpleName())); | ||
throw new RuntimeException(); | ||
} | ||
|
||
instanceExists = true; | ||
} | ||
|
||
/** | ||
* | ||
* @param worldTickEvent | ||
*/ | ||
@SubscribeEvent | ||
public static void onWorldTick_0(TickEvent.WorldTickEvent worldTickEvent) | ||
{ | ||
if (worldTickEvent.phase == TickEvent.Phase.END || worldTickEvent.world.isRemote) | ||
{ | ||
return; | ||
} | ||
|
||
if (++_TICK_COUNTER < 20) | ||
{ | ||
return; | ||
} | ||
|
||
_TICK_COUNTER = 0; | ||
|
||
World world = worldTickEvent.world; | ||
|
||
for (EntityPlayer player : world.playerEntities) | ||
{ | ||
BlockPos playerPos = player.getPosition(); | ||
|
||
int x = UniqueField.RANDOM.nextInt(16) + playerPos.getX() - 8; | ||
int z = UniqueField.RANDOM.nextInt(16) + playerPos.getZ() - 8; | ||
|
||
int y = world.getHeight(x, z) - 1; | ||
|
||
BlockPos groundPos = new BlockPos(x, y, z); | ||
Block block = world.getBlockState(groundPos).getBlock(); | ||
|
||
if (block == Blocks.GRASS) | ||
{ | ||
BlockPos abovePos = groundPos.up(); | ||
|
||
IBlockState stateAbove = world.getBlockState(abovePos); | ||
|
||
if (stateAbove.getBlock() == Blocks.TALLGRASS) | ||
{ | ||
if (stateAbove.getValue(BlockTallGrass.TYPE) == BlockTallGrass.EnumType.GRASS) | ||
{ | ||
BlockPos upperPos = abovePos.up(); | ||
|
||
if (world.isAirBlock(upperPos) && UniqueField.RANDOM.nextInt(100) < 95) | ||
{ | ||
IBlockState doubleTallGrassLower = Blocks.DOUBLE_PLANT.getDefaultState() | ||
.withProperty(BlockDoublePlant.VARIANT, BlockDoublePlant.EnumPlantType.GRASS) | ||
.withProperty(BlockDoublePlant.HALF, BlockDoublePlant.EnumBlockHalf.LOWER); | ||
|
||
IBlockState doubleTallGrassUpper = Blocks.DOUBLE_PLANT.getDefaultState() | ||
.withProperty(BlockDoublePlant.VARIANT, BlockDoublePlant.EnumPlantType.GRASS) | ||
.withProperty(BlockDoublePlant.HALF, BlockDoublePlant.EnumBlockHalf.UPPER); | ||
|
||
world.setBlockState(abovePos, doubleTallGrassLower, 3); | ||
world.setBlockState(upperPos, doubleTallGrassUpper, 3); | ||
} | ||
} | ||
} | ||
else if (world.isAirBlock(abovePos)) | ||
{ | ||
if (UniqueField.RANDOM.nextInt(100) < 95) | ||
{ | ||
IBlockState smallGrassState = Blocks.TALLGRASS.getDefaultState() | ||
.withProperty(BlockTallGrass.TYPE, BlockTallGrass.EnumType.GRASS); | ||
|
||
world.setBlockState(abovePos, smallGrassState, 3); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |