Guest User

code

a guest
May 2nd, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.39 KB | None | 0 0
  1. ///-------------------Here is the code that is throwing the ConcurrentModificationException, found in the StructureStart class-------
  2.  
  3.     public void generateStructure(World worldIn, Random rand, StructureBoundingBox structurebb)
  4.     {
  5.         Iterator<StructureComponent> iterator = this.components.iterator();
  6.  
  7.         while (iterator.hasNext())
  8.         {
  9.             StructureComponent structurecomponent = (StructureComponent)iterator.next();
  10.  
  11.             if (structurecomponent.getBoundingBox().intersectsWith(structurebb) && !structurecomponent.addComponentParts(worldIn, rand, structurebb))
  12.             {
  13.                 iterator.remove();
  14.             }
  15.         }
  16.     }
  17.  
  18.  
  19. ///------------Events > These are being called as expected-----------------------
  20.  
  21.     @SubscribeEvent
  22.     public void onEvent(PopulateChunkEvent.Pre event) {
  23.         Console.println("*Event: PopulateChunk_pre");
  24.         this.mapGenScatteredRuin.generate(event.getWorld(), event.getChunkX(), event.getChunkZ(), new ChunkPrimer());
  25.     }
  26.    
  27.     @SubscribeEvent
  28.     public void onEvent(PopulateChunkEvent.Post event) {
  29.         Console.println("*Event: PopulateChunk_post");
  30.         ChunkPos chunkpos = new ChunkPos(event.getChunkX(), event.getChunkZ());
  31.         this.mapGenScatteredRuin.generateStructure(event.getWorld(), event.getRand(), chunkpos);  // <--- This calls the code above in Structure Start, which throws the ConcurrentModification error
  32.     }
  33.  
  34.  
  35. //--------------------------------------------------------------------------------------------------------------------
  36.  
  37. public class MapGenScatteredRuin extends MapGenStructure {
  38.  
  39.     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});
  40.     private int maxDistanceBetweenRuins;
  41.     private Random rand;
  42.    
  43.     private MapGenStructureData structureData;
  44.    
  45.     public MapGenScatteredRuin() {
  46.         this.maxDistanceBetweenRuins = 15; 
  47.         ComponentScatteredRuinsPieces.registerScatteredRuinPieces();
  48.         MapGenStructureIO.registerStructure(MapGenScatteredRuin.Start.class, getStructureName());
  49.     }
  50.    
  51.    
  52.     @Override
  53.     public String getStructureName() {
  54.         return "Ruin";
  55.     }
  56.  
  57.     @Override
  58.     public BlockPos getClosestStrongholdPos(World worldIn, BlockPos pos, boolean findUnexplored) {
  59.         this.world = worldIn;
  60.         return findNearestStructurePosBySpacing(worldIn, this, pos, this.maxDistanceBetweenRuins, 8, 14357617, false, 100, findUnexplored);
  61.     }
  62.  
  63.     @Override
  64.     protected boolean canSpawnStructureAtCoords(int chunkX, int chunkZ) {
  65.         int x = chunkX;
  66.         int z = chunkZ;
  67.  
  68.         if (chunkX < 0)
  69.         {
  70.             chunkX -= this.maxDistanceBetweenRuins - 1;
  71.         }
  72.  
  73.         if (chunkZ < 0)
  74.         {
  75.             chunkZ -= this.maxDistanceBetweenRuins - 1;
  76.         }
  77.                
  78.         int i = chunkX / this.maxDistanceBetweenRuins;
  79.         int k = chunkZ / this.maxDistanceBetweenRuins;
  80.         this.rand = this.world.setRandomSeed(i, k, 14357617);
  81.         i = (i * this.maxDistanceBetweenRuins) + this.rand.nextInt(this.maxDistanceBetweenRuins - 8);
  82.         k = (k * this.maxDistanceBetweenRuins) + this.rand.nextInt(this.maxDistanceBetweenRuins - 8);
  83.        
  84.         if (i == x && k == z) {
  85.              Biome biome = this.world.getBiomeProvider().getBiome(new BlockPos(x * 16 + 8, 0, z * 16 + 8));
  86.              
  87.              if (biome == null)
  88.              {
  89.                  return false;
  90.              }
  91.  
  92.              for (Biome biome1 : BIOMELIST)
  93.              {
  94.                  if (biome == biome1)
  95.                  {
  96.                      Console.println("Can spawn a ruin here");
  97.                      return true;
  98.                      
  99.                  }
  100.              }
  101.         }
  102.        
  103.         return false;
  104.     }
  105.  
  106.     @Override
  107.     protected StructureStart getStructureStart(int chunkX, int chunkZ) {
  108.         return new MapGenScatteredRuin.Start(this.world, this.rand, chunkX, chunkZ);
  109.     }
  110.  
  111.     public static class Start extends StructureStart
  112.     {
  113.         public Start()
  114.         {
  115.         }
  116.        
  117.         public Start(World worldIn, Random random, int chunkX, int chunkZ)
  118.         {
  119.             this(worldIn, random, chunkX, chunkZ, worldIn.getBiome(new BlockPos(chunkX * 16 + 8, 0, chunkZ * 16 + 8)));
  120.         }
  121.  
  122.         public Start(World worldIn, Random random, int chunkX, int chunkZ, Biome biomeIn)
  123.         {
  124.             super(chunkX, chunkZ);
  125.            
  126.             if (biomeIn == Biomes.PLAINS) {
  127.                 ComponentScatteredRuinsPieces.CircleAltar circleAltar = new ComponentScatteredRuinsPieces.CircleAltar(random, chunkX * 16, chunkZ * 16);
  128.                 this.components.add(circleAltar);
  129.                 Console.println("Adding altar to components");
  130.             }
  131.             else {
  132.                 ComponentScatteredRuinsPieces.CircleAltar circleAltar = new ComponentScatteredRuinsPieces.CircleAltar(random, chunkX * 16, chunkZ * 16);
  133.                 this.components.add(circleAltar);
  134.                 Console.println("Adding altar to components");
  135.             }
  136.            
  137.             this.updateBoundingBox();
  138.         }
  139.     }
  140. }
  141.  
  142. //--------------------------------------------------------------------------------------------
  143.  
  144. public class ComponentScatteredRuinsPieces {
  145.    
  146.     public static void registerScatteredRuinPieces() {
  147.         MapGenStructureIO.registerStructureComponent(ComponentScatteredRuinsPieces.CircleAltar.class, "CircAlt");
  148.         Console.println("ID mapping registered");
  149.     }
  150.    
  151.    
  152.     abstract static class Ruin extends StructureComponent {
  153.         protected int sizeX;
  154.         protected int sizeY;
  155.         protected int sizeZ;
  156.         protected int horizontalPos = -1;
  157.        
  158.         public Ruin() {        
  159.         }
  160.        
  161.         protected Ruin(Random rand, int x, int y, int z, int sizeX, int sizeY, int sizeZ) {
  162.             super(0);
  163.             this.sizeX = sizeX;
  164.             this.sizeY = sizeY;
  165.             this.sizeZ = sizeZ;
  166.             this.setCoordBaseMode(EnumFacing.Plane.HORIZONTAL.random(rand));
  167.  
  168.             if (this.getCoordBaseMode().getAxis() == EnumFacing.Axis.Z)
  169.             {
  170.                 this.boundingBox = new StructureBoundingBox(x, y, z, x + sizeX - 1, y + sizeY - 1, z + sizeZ - 1);
  171.             }
  172.             else
  173.             {
  174.                 this.boundingBox = new StructureBoundingBox(x, y, z, x + sizeZ - 1, y + sizeY - 1, z + sizeX - 1);
  175.             }
  176.            
  177.         }
  178.        
  179.         protected void writeStructureToNBT(NBTTagCompound tagCompound)
  180.         {
  181.             tagCompound.setInteger("Width", this.sizeX);
  182.             tagCompound.setInteger("Height", this.sizeY);
  183.             tagCompound.setInteger("Depth", this.sizeZ);
  184.             tagCompound.setInteger("HPos", this.horizontalPos);
  185.         }
  186.        
  187.         protected void readStructureFromNBT(NBTTagCompound tagCompound, TemplateManager p_143011_2_)
  188.         {
  189.             this.sizeX = tagCompound.getInteger("Width");
  190.             this.sizeY = tagCompound.getInteger("Height");
  191.             this.sizeZ = tagCompound.getInteger("Depth");
  192.             this.horizontalPos = tagCompound.getInteger("HPos");
  193.         }
  194.        
  195.         protected boolean offsetToAverageGroundLevel(World worldIn, StructureBoundingBox structurebb, int yOffset)
  196.         {
  197.             if (this.horizontalPos >= 0)
  198.             {
  199.                 return true;
  200.             }
  201.             else
  202.             {
  203.                 int i = 0;
  204.                 int j = 0;
  205.                 BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
  206.  
  207.                 for (int k = this.boundingBox.minZ; k <= this.boundingBox.maxZ; ++k)
  208.                 {
  209.                     for (int l = this.boundingBox.minX; l <= this.boundingBox.maxX; ++l)
  210.                     {
  211.                         blockpos$mutableblockpos.setPos(l, 64, k);
  212.  
  213.                         if (structurebb.isVecInside(blockpos$mutableblockpos))
  214.                         {
  215.                             i += Math.max(worldIn.getTopSolidOrLiquidBlock(blockpos$mutableblockpos).getY(), worldIn.provider.getAverageGroundLevel());
  216.                             ++j;
  217.                         }
  218.                     }
  219.                 }
  220.  
  221.                 if (j == 0)
  222.                 {
  223.                     return false;
  224.                 }
  225.                 else
  226.                 {
  227.                     this.horizontalPos = i / j;
  228.                     this.boundingBox.offset(0, this.horizontalPos - this.boundingBox.minY + yOffset, 0);
  229.                     return true;
  230.                 }
  231.             }
  232.         }
  233.     }
  234.  
  235.     public static class CircleAltar extends ComponentScatteredRuinsPieces.Ruin {
  236.  
  237.         private static final StructureWrapper structure = new NordRuin1();
  238.        
  239.         public CircleAltar() {}
  240.        
  241.         public CircleAltar(Random rand, int x, int z) {
  242.             super(rand, x, 64, z, 16, 16, 16);  //**Find way to dynamically get sizes**
  243.         }
  244.        
  245.        
  246.         @Override
  247.         public boolean addComponentParts(World worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn) {
  248.             if (!this.offsetToAverageGroundLevel(worldIn, structureBoundingBoxIn, -1))
  249.             {
  250.                 return false;
  251.             }
  252.             else {
  253.                 StructureBoundingBox structureboundingbox = this.getBoundingBox();
  254.                 BlockPos blockpos = new BlockPos(structureboundingbox.minX, structureboundingbox.minY, structureboundingbox.minZ);
  255.                 structure.generate(worldIn, randomIn, blockpos);
  256.             }
  257.             return false;
  258.         }
  259.        
  260.     }
  261. }
Advertisement
Add Comment
Please, Sign In to add comment