Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.steelfeathers.nethersurvival.worldgen;
- import java.util.Random;
- import com.google.common.base.Predicate;
- import net.minecraft.block.Block;
- import net.minecraft.block.properties.IProperty;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.init.Blocks;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.World;
- import net.minecraft.world.gen.feature.WorldGenerator;
- public class WorldGenCrystal extends WorldGenBase {
- private static boolean noState = false;
- private static IBlockState state;
- private static IBlockState state_up;
- private static IBlockState state_down;
- private static IBlockState state_north;
- private static IBlockState state_south;
- private static IBlockState state_east;
- private static IBlockState state_west;
- private static IProperty<EnumFacing> property;
- private static int clusterSize = 3;
- private static int clusterSpread = 5;
- private static Block targetBlock;
- public WorldGenCrystal(IBlockState state, Block targetBlock) {
- this.state = this.state_up = this.state_down = this.state_north = this.state_south = this.state_east = this.state_west = state;
- noState = true;
- this.targetBlock = targetBlock;
- }
- public WorldGenCrystal(IBlockState state, Block targetBlock, int clusterSize, int clusterSpread) {
- this.state = this.state_up = this.state_down = this.state_north = this.state_south = this.state_east = this.state_west = state;
- this.clusterSize = clusterSize;
- this.clusterSpread = clusterSpread;
- noState = true;
- this.targetBlock = targetBlock;
- }
- public WorldGenCrystal(IBlockState state, Block targetBlock, int clusterSize, int clusterSpread, IProperty<EnumFacing> property) {
- this.state = state;
- this.state_up = state.withProperty(property, EnumFacing.UP);
- this.state_down = state.withProperty(property, EnumFacing.DOWN);
- this.state_north = state.withProperty(property, EnumFacing.NORTH);
- this.state_south = state.withProperty(property, EnumFacing.SOUTH);
- this.state_east = state.withProperty(property, EnumFacing.EAST);
- this.state_west = state.withProperty(property, EnumFacing.WEST);
- this.property = property;
- this.clusterSize = clusterSize;
- this.clusterSpread = clusterSpread;
- noState = false;
- this.targetBlock = targetBlock;
- }
- @Override
- public boolean generate(World worldIn, Random rand, BlockPos position) {
- int D = 1; //use a directional hash to determine the combination of blocks surrounding the target position
- int U = 2;
- int N = 4;
- int S = 8;
- int W = 16;
- int E = 32;
- int hash = 0;
- int tot = D+U+N+S+W+E;
- // THIS IS THE WHERE THE ISSUE STARTS. If I comment out just the loop, so that the code only runs once, everything is fine.
- for (int i = 0; i < clusterSize; ++i)
- {
- if (worldIn.isAirBlock(position))
- {
- int r = rand.nextInt(6);
- boolean sideDown = false;
- boolean sideUp = false;
- boolean sideNorth = false;
- boolean sideEast = false;
- boolean sideWest = false;
- boolean sideSouth = false;
- IBlockState blockstate = worldIn.getBlockState(position);
- if (worldIn.getBlockState(position.up()).getBlock() == targetBlock)
- {
- hash += U;
- sideUp = true;
- }
- if (worldIn.getBlockState(position.down()).getBlock() == targetBlock)
- {
- hash += D;
- sideDown = true;
- }
- if (worldIn.getBlockState(position.north()).getBlock() == targetBlock)
- {
- hash += N;
- sideNorth = true;
- }
- if (worldIn.getBlockState(position.south()).getBlock() == targetBlock)
- {
- hash += S;
- sideSouth = true;
- }
- if (worldIn.getBlockState(position.east()).getBlock() == targetBlock)
- {
- hash += E;
- sideEast = true;
- }
- if (worldIn.getBlockState(position.west()).getBlock() == targetBlock)
- {
- hash += W;
- sideWest = true;
- }
- if (hash != tot)
- {
- if (hash == tot-D || hash == U) //all sides but down are target block, or only up side is target block
- {
- worldIn.setBlockState(position, state_down, 2);
- }
- else if (hash == tot-U || hash == D)
- {
- worldIn.setBlockState(position, state_up, 2);
- }
- else if (hash == tot-N || hash == S)
- {
- worldIn.setBlockState(position, state_north, 2);
- }
- else if (hash == tot-S || hash == N)
- {
- worldIn.setBlockState(position, state_south, 2);
- }
- else if (hash == tot-W || hash == E)
- {
- worldIn.setBlockState(position, state_west, 2);
- }
- else if (hash == tot-E || hash == W)
- {
- worldIn.setBlockState(position, state_east, 2);
- }
- else if (r == 0 && sideUp || r == 1 && sideDown || r == 2 && sideSouth ||
- r == 3 && sideNorth || r == 4 && sideEast || r == 5 && sideWest)
- {
- if (noState)
- {
- worldIn.setBlockState(position, state, 2);
- }
- else
- {
- worldIn.setBlockState(position, state.withProperty(property, EnumFacing.getFront(r)), 2);
- }
- }
- }
- }
- position = position.add(rand.nextInt(clusterSpread) - rand.nextInt(clusterSpread), rand.nextInt(clusterSpread) - rand.nextInt(clusterSpread), rand.nextInt(clusterSpread) - rand.nextInt(clusterSpread));
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment