Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///-------------------Here is the code that is throwing the ConcurrentModificationException, found in the StructureStart class-------
- public void generateStructure(World worldIn, Random rand, StructureBoundingBox structurebb)
- {
- Iterator<StructureComponent> iterator = this.components.iterator();
- while (iterator.hasNext())
- {
- StructureComponent structurecomponent = (StructureComponent)iterator.next();
- if (structurecomponent.getBoundingBox().intersectsWith(structurebb) && !structurecomponent.addComponentParts(worldIn, rand, structurebb))
- {
- iterator.remove();
- }
- }
- }
- ///------------Events > These are being called as expected-----------------------
- @SubscribeEvent
- public void onEvent(PopulateChunkEvent.Pre event) {
- Console.println("*Event: PopulateChunk_pre");
- this.mapGenScatteredRuin.generate(event.getWorld(), event.getChunkX(), event.getChunkZ(), new ChunkPrimer());
- }
- @SubscribeEvent
- public void onEvent(PopulateChunkEvent.Post event) {
- Console.println("*Event: PopulateChunk_post");
- ChunkPos chunkpos = new ChunkPos(event.getChunkX(), event.getChunkZ());
- this.mapGenScatteredRuin.generateStructure(event.getWorld(), event.getRand(), chunkpos); // <--- This calls the code above in Structure Start, which throws the ConcurrentModification error
- }
- //--------------------------------------------------------------------------------------------------------------------
- public class MapGenScatteredRuin extends MapGenStructure {
- private static final List<Biome> BIOMELIST = Arrays.<Biome>asList(new Biome[] {Biomes.PLAINS, Biomes.TAIGA, Biomes.FOREST, Biomes.BIRCH_FOREST, Biomes.SWAMPLAND, Biomes.ICE_PLAINS, Biomes.COLD_TAIGA});
- private int maxDistanceBetweenRuins;
- private Random rand;
- private MapGenStructureData structureData;
- public MapGenScatteredRuin() {
- this.maxDistanceBetweenRuins = 15;
- ComponentScatteredRuinsPieces.registerScatteredRuinPieces();
- MapGenStructureIO.registerStructure(MapGenScatteredRuin.Start.class, getStructureName());
- }
- @Override
- public String getStructureName() {
- return "Ruin";
- }
- @Override
- public BlockPos getClosestStrongholdPos(World worldIn, BlockPos pos, boolean findUnexplored) {
- this.world = worldIn;
- return findNearestStructurePosBySpacing(worldIn, this, pos, this.maxDistanceBetweenRuins, 8, 14357617, false, 100, findUnexplored);
- }
- @Override
- protected boolean canSpawnStructureAtCoords(int chunkX, int chunkZ) {
- int x = chunkX;
- int z = chunkZ;
- if (chunkX < 0)
- {
- chunkX -= this.maxDistanceBetweenRuins - 1;
- }
- if (chunkZ < 0)
- {
- chunkZ -= this.maxDistanceBetweenRuins - 1;
- }
- int i = chunkX / this.maxDistanceBetweenRuins;
- int k = chunkZ / this.maxDistanceBetweenRuins;
- this.rand = this.world.setRandomSeed(i, k, 14357617);
- i = (i * this.maxDistanceBetweenRuins) + this.rand.nextInt(this.maxDistanceBetweenRuins - 8);
- k = (k * this.maxDistanceBetweenRuins) + this.rand.nextInt(this.maxDistanceBetweenRuins - 8);
- if (i == x && k == z) {
- Biome biome = this.world.getBiomeProvider().getBiome(new BlockPos(x * 16 + 8, 0, z * 16 + 8));
- if (biome == null)
- {
- return false;
- }
- for (Biome biome1 : BIOMELIST)
- {
- if (biome == biome1)
- {
- Console.println("Can spawn a ruin here");
- return true;
- }
- }
- }
- return false;
- }
- @Override
- protected StructureStart getStructureStart(int chunkX, int chunkZ) {
- return new MapGenScatteredRuin.Start(this.world, this.rand, chunkX, chunkZ);
- }
- public static class Start extends StructureStart
- {
- public Start()
- {
- }
- public Start(World worldIn, Random random, int chunkX, int chunkZ)
- {
- this(worldIn, random, chunkX, chunkZ, worldIn.getBiome(new BlockPos(chunkX * 16 + 8, 0, chunkZ * 16 + 8)));
- }
- public Start(World worldIn, Random random, int chunkX, int chunkZ, Biome biomeIn)
- {
- super(chunkX, chunkZ);
- if (biomeIn == Biomes.PLAINS) {
- ComponentScatteredRuinsPieces.CircleAltar circleAltar = new ComponentScatteredRuinsPieces.CircleAltar(random, chunkX * 16, chunkZ * 16);
- this.components.add(circleAltar);
- Console.println("Adding altar to components");
- }
- else {
- ComponentScatteredRuinsPieces.CircleAltar circleAltar = new ComponentScatteredRuinsPieces.CircleAltar(random, chunkX * 16, chunkZ * 16);
- this.components.add(circleAltar);
- Console.println("Adding altar to components");
- }
- this.updateBoundingBox();
- }
- }
- }
- //--------------------------------------------------------------------------------------------
- public class ComponentScatteredRuinsPieces {
- public static void registerScatteredRuinPieces() {
- MapGenStructureIO.registerStructureComponent(ComponentScatteredRuinsPieces.CircleAltar.class, "CircAlt");
- Console.println("ID mapping registered");
- }
- abstract static class Ruin extends StructureComponent {
- protected int sizeX;
- protected int sizeY;
- protected int sizeZ;
- protected int horizontalPos = -1;
- public Ruin() {
- }
- protected Ruin(Random rand, int x, int y, int z, int sizeX, int sizeY, int sizeZ) {
- super(0);
- this.sizeX = sizeX;
- this.sizeY = sizeY;
- this.sizeZ = sizeZ;
- this.setCoordBaseMode(EnumFacing.Plane.HORIZONTAL.random(rand));
- if (this.getCoordBaseMode().getAxis() == EnumFacing.Axis.Z)
- {
- this.boundingBox = new StructureBoundingBox(x, y, z, x + sizeX - 1, y + sizeY - 1, z + sizeZ - 1);
- }
- else
- {
- this.boundingBox = new StructureBoundingBox(x, y, z, x + sizeZ - 1, y + sizeY - 1, z + sizeX - 1);
- }
- }
- protected void writeStructureToNBT(NBTTagCompound tagCompound)
- {
- tagCompound.setInteger("Width", this.sizeX);
- tagCompound.setInteger("Height", this.sizeY);
- tagCompound.setInteger("Depth", this.sizeZ);
- tagCompound.setInteger("HPos", this.horizontalPos);
- }
- protected void readStructureFromNBT(NBTTagCompound tagCompound, TemplateManager p_143011_2_)
- {
- this.sizeX = tagCompound.getInteger("Width");
- this.sizeY = tagCompound.getInteger("Height");
- this.sizeZ = tagCompound.getInteger("Depth");
- this.horizontalPos = tagCompound.getInteger("HPos");
- }
- protected boolean offsetToAverageGroundLevel(World worldIn, StructureBoundingBox structurebb, int yOffset)
- {
- if (this.horizontalPos >= 0)
- {
- return true;
- }
- else
- {
- int i = 0;
- int j = 0;
- BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
- for (int k = this.boundingBox.minZ; k <= this.boundingBox.maxZ; ++k)
- {
- for (int l = this.boundingBox.minX; l <= this.boundingBox.maxX; ++l)
- {
- blockpos$mutableblockpos.setPos(l, 64, k);
- if (structurebb.isVecInside(blockpos$mutableblockpos))
- {
- i += Math.max(worldIn.getTopSolidOrLiquidBlock(blockpos$mutableblockpos).getY(), worldIn.provider.getAverageGroundLevel());
- ++j;
- }
- }
- }
- if (j == 0)
- {
- return false;
- }
- else
- {
- this.horizontalPos = i / j;
- this.boundingBox.offset(0, this.horizontalPos - this.boundingBox.minY + yOffset, 0);
- return true;
- }
- }
- }
- }
- public static class CircleAltar extends ComponentScatteredRuinsPieces.Ruin {
- private static final StructureWrapper structure = new NordRuin1();
- public CircleAltar() {}
- public CircleAltar(Random rand, int x, int z) {
- super(rand, x, 64, z, 16, 16, 16); //**Find way to dynamically get sizes**
- }
- @Override
- public boolean addComponentParts(World worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn) {
- if (!this.offsetToAverageGroundLevel(worldIn, structureBoundingBoxIn, -1))
- {
- return false;
- }
- else {
- StructureBoundingBox structureboundingbox = this.getBoundingBox();
- BlockPos blockpos = new BlockPos(structureboundingbox.minX, structureboundingbox.minY, structureboundingbox.minZ);
- structure.generate(worldIn, randomIn, blockpos);
- }
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment