Created
June 23, 2020 04:33
-
-
Save eatmyvenom/921946af8f65bb80dfae2d1903534a8e to your computer and use it in GitHub Desktop.
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
public void tickChunk(WorldChunk currentChunk, int i) { | |
// set a bunch of local variables | |
boolean isCurrentlyRaining = this.isRaining(); | |
ChunkPos currentChunkPos = currentChunk.getPos(); | |
int chunkBlockPosX = currentChunkPos.getStartX(); | |
int chunkBlockPosZ = currentChunkPos.getStartZ(); | |
BlockPos randomBlockAtSurface = this.getSurface(this.getRandomPosInChunk(chunkBlockPosX, 0, chunkBlockPosZ, 15)); | |
Profiler profiler = this.getProfiler(); | |
// thunder code here | |
profiler.push("thunder"); | |
if (isCurrentlyRaining && this.isThundering() && this.random.nextInt(100000) == 0 && this.hasRain(randomBlockAtSurface)) { | |
boolean shouldDoMobSpawning = this.getGameRules().getBoolean(GameRules.DO_MOB_SPAWNING); | |
LocalDifficulty lv4 = this.getLocalDifficulty(randomBlockAtSurface); | |
if (shouldDoMobSpawning) { | |
SkeletonHorseEntity skeleHorse = EntityType.SKELETON_HORSE.create(this); | |
skeleHorse.setTrapped(true); | |
skeleHorse.setBreedingAge(0); | |
skeleHorse.updatePosition(randomBlockAtSurface.getX(), randomBlockAtSurface.getY(), randomBlockAtSurface.getZ()); | |
this.spawnEntity(skeleHorse); | |
} | |
LightningEntity lightningBolt = EntityType.LIGHTNING_BOLT.create(this); | |
lightningBolt.positAfterTeleport(Vec3d.ofBottomCenter(randomBlockAtSurface)); | |
lightningBolt.setCosmetic(shouldDoMobSpawning); | |
this.spawnEntity(lightningBolt); | |
} | |
// end thunder code | |
// Ice and snow code here | |
profiler.swap("iceandsnow"); | |
if (this.random.nextInt(16) == 0) { | |
BlockPos randomPosInChunk = this.getTopPosition(Heightmap.Type.MOTION_BLOCKING, this.getRandomPosInChunk(chunkBlockPosX, 0, chunkBlockPosZ, 15)); | |
BlockPos randomPosBelow = randomPosInChunk.down(); | |
Biome currentBiome = this.getBiome(randomPosInChunk); | |
if (currentBiome.canSetIce(this, randomPosBelow)) { | |
this.setBlockState(randomPosBelow, Blocks.ICE.getDefaultState()); | |
} | |
if (isCurrentlyRaining && currentBiome.canSetSnow(this, randomPosInChunk)) { | |
this.setBlockState(randomPosInChunk, Blocks.SNOW.getDefaultState()); | |
} | |
if (isCurrentlyRaining && this.getBiome(randomPosBelow).getPrecipitation() == Biome.Precipitation.RAIN) { | |
this.getBlockState(randomPosBelow).getBlock().rainTick(this, randomPosBelow); | |
} | |
} | |
// end Ice and snow code | |
// block tick code | |
profiler.swap("tickBlocks"); | |
if (i > 0) { | |
for (ChunkSection chunkSection : currentChunk.getSectionArray()) { | |
if (chunkSection == WorldChunk.EMPTY_SECTION || !chunkSection.hasRandomTicks()) continue; | |
int yOffset = chunkSection.getYOffset(); | |
for (int m = 0; m < i; ++m) { | |
FluidState fluidState; | |
BlockPos randomPos = this.getRandomPosInChunk(chunkBlockPosX, yOffset, chunkBlockPosZ, 15); | |
// random tick code | |
profiler.push("randomTick"); | |
BlockState randomPosBlockState = chunkSection.getBlockState(randomPos.getX() - chunkBlockPosX, randomPos.getY() - yOffset, randomPos.getZ() - chunkBlockPosZ); | |
if (randomPosBlockState.hasRandomTicks()) { | |
randomPosBlockState.randomTick(this, randomPos, this.random); | |
} | |
if ((fluidState = randomPosBlockState.getFluidState()).hasRandomTicks()) { | |
fluidState.onRandomTick(this, randomPos, this.random); | |
} | |
profiler.pop(); | |
// end random tick code | |
} | |
} | |
} | |
profiler.pop(); | |
// end block tick code | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment