added defering of pixel spawning
This commit is contained in:
		| @@ -17,6 +17,8 @@ import org.jetbrains.annotations.NotNull; | ||||
| import javax.annotation.Nullable; | ||||
| import java.io.File; | ||||
| import java.util.*; | ||||
| import java.util.stream.Collectors; | ||||
| import java.util.stream.IntStream; | ||||
|  | ||||
| public class PixelBlock { | ||||
|     private final PixelBlockWorld pixelWorld; | ||||
| @@ -122,9 +124,14 @@ public class PixelBlock { | ||||
|     } | ||||
|  | ||||
|     public void updateEntities() { | ||||
|         this.getBlockTaskChain() | ||||
|             .sync(this::clearEntities) | ||||
|             .sync(() -> { | ||||
|         record PixelData(PixelBlock parent, Vector relativeLocation, BlockData block, double scale) { | ||||
|             Pixel create() { | ||||
|                 return Pixel.newPixel(this.parent, this.relativeLocation, this.block, this.scale); | ||||
|             } | ||||
|         } | ||||
|         List<PixelData> pixelData = new ArrayList<>(); | ||||
|  | ||||
|         this.clearEntities(); | ||||
|         for (int x = 0; x < pixelsPerBlock; x++) { | ||||
|             for (int y = 0; y < pixelsPerBlock; y++) { | ||||
|                 for (int z = 0; z < pixelsPerBlock; z++) { | ||||
| @@ -141,15 +148,27 @@ public class PixelBlock { | ||||
|                     BlockData block = blockLocation.getBlock().getBlockData(); | ||||
|  | ||||
|                     if(!block.getMaterial().isEmpty()) { | ||||
|                                 this.getBlockTaskChain() | ||||
|                         pixelData.add(new PixelData(this, relativeLocation.toVector(), block, (double) 1 / pixelsPerBlock)); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         int spawnSpreadInTicks = 10; | ||||
|         int chunkSize = (int) Math.ceil((double) pixelData.size() / spawnSpreadInTicks); | ||||
|  | ||||
|         IntStream.range(0, spawnSpreadInTicks) | ||||
|             .mapToObj(i -> pixelData.stream() | ||||
|                 .skip((long) i * chunkSize) | ||||
|                 .limit(chunkSize) | ||||
|                 .collect(Collectors.toList())) | ||||
|             .forEach(pixels -> this.getBlockTaskChain() | ||||
|                 .delay(1) | ||||
|                                     .sync(() -> pixels.add(Pixel.newPixel(this, relativeLocation.toVector(), block, (double) 1 / pixelsPerBlock))) | ||||
|                                     .execute(); | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             }) | ||||
|                 .sync(() -> pixels.forEach(pixel -> this.pixels.add(pixel.create()))) | ||||
|                 .execute()); | ||||
|  | ||||
|  | ||||
|         this.getBlockTaskChain() | ||||
|             .sync(() -> { | ||||
|                 if(this.pixels.size() < 5) { | ||||
| //                    Location relativeLocation = new Location(pixelBlockLocation.getWorld(), 0, 0, 0); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user