问题描述
我在《我的世界》中为《岛屿》写了一个发电机。 每个岛屿的高度必须至少为35个街区。 但是我写的代码似乎太服务器密集了,导致出现以下错误
---- Minecraft Crash Report ----
// There are four lights!
Time: 18.07.15 18:05
Description: Watching Server
java.lang.Error
at org.bukkit.util.noise.OctaveGenerator.noise(OctaveGenerator.java:187)
at org.bukkit.util.noise.OctaveGenerator.noise(OctaveGenerator.java:161)
at org.bukkit.util.noise.OctaveGenerator.noise(OctaveGenerator.java:131)
at de.mineone.island.generator.Island.generateIsland(Island.java:114)
at de.mineone.island.generator.Island.generate(Island.java:40)
at de.mineone.island.generator.Island.<init>(Island.java:36)
at de.mineone.island.main.Main$1.run(Main.java:80)
at org.bukkit.craftbukkit.v1_8_R1.scheduler.CraftTask.run(CraftTask.java:53)
at org.bukkit.craftbukkit.v1_8_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:349)
at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:655)
at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:284)
at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:600)
at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:508)
at java.lang.Thread.run(Unknown Source)
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
-- Head --
Stacktrace:
at org.bukkit.util.noise.OctaveGenerator.noise(OctaveGenerator.java:187)
at org.bukkit.util.noise.OctaveGenerator.noise(OctaveGenerator.java:161)
at org.bukkit.util.noise.OctaveGenerator.noise(OctaveGenerator.java:131)
at de.mineone.island.generator.Island.generateIsland(Island.java:114)
at de.mineone.island.generator.Island.generate(Island.java:40)
at de.mineone.island.generator.Island.<init>(Island.java:36)
at de.mineone.island.main.Main$1.run(Main.java:80)
at org.bukkit.craftbukkit.v1_8_R1.scheduler.CraftTask.run(CraftTask.java:53)
at org.bukkit.craftbukkit.v1_8_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:349)
at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:655)
at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:284)
at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:600)
-- Thread Dump --
Details:
Threads: "Server Watchdog" Id=39 RUNNABLE
at sun.management.ThreadImpl.dumpThreads0(Native Method)
at sun.management.ThreadImpl.dumpAllThreads(Unknown Source)
at net.minecraft.server.v1_8_R1.ThreadWatchdog.run(SourceFile:43)
at java.lang.Thread.run(Unknown Source)
"Netty Server IO #0" Id=21 RUNNABLE (in native)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(Unknown Source)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(Unknown Source)
at sun.nio.ch.WindowsSelectorImpl.doSelect(Unknown Source)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(Unknown Source)
- locked io.netty.channel.nio.SelectedSelectionKeySet@51978c9e
- locked java.util.Collections$UnmodifiableSet@1c56ad43
- locked sun.nio.ch.WindowsSelectorImpl@5a968db1
at sun.nio.ch.SelectorImpl.select(Unknown Source)
at io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:618)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:306)
...
"Thread-5" Id=19 RUNNABLE
at java.io.FileOutputStream.writeBytes(Native Method)
at java.io.FileOutputStream.write(Unknown Source)
at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
at java.io.BufferedOutputStream.flush(Unknown Source)
- locked java.io.BufferedOutputStream@52308ded
at java.io.PrintStream.flush(Unknown Source)
- locked java.io.PrintStream@71b5ecc2
at java.io.FilterOutputStream.flush(Unknown Source)
at sun.nio.cs.StreamEncoder.implFlush(Unknown Source)
at sun.nio.cs.StreamEncoder.flush(Unknown Source)
- locked java.io.OutputStreamWriter@5ecaeee0
...
"Server console handler" Id=18 RUNNABLE (in native)
at org.fusesource.jansi.internal.Kernel32._getch(Native Method)
at org.fusesource.jansi.internal.WindowsSupport.readByte(WindowsSupport.java:46)
at org.bukkit.craftbukkit.libs.jline.WindowsTerminal.readByte(WindowsTerminal.java:184)
at org.bukkit.craftbukkit.libs.jline.WindowsTerminal.access$000(WindowsTerminal.java:53)
at org.bukkit.craftbukkit.libs.jline.WindowsTerminal$1.read(WindowsTerminal.java:151)
at java.io.FilterInputStream.read(Unknown Source)
at org.bukkit.craftbukkit.libs.jline.console.ConsoleReader$1.read(ConsoleReader.java:167)
at org.bukkit.craftbukkit.libs.jline.internal.InputStreamReader.read(InputStreamReader.java:267)
- locked org.bukkit.craftbukkit.libs.jline.console.ConsoleReader$1@72e1a5a9
...
"DestroyJavaVM" Id=17 RUNNABLE
"Server thread" Id=15 RUNNABLE
at org.bukkit.util.noise.OctaveGenerator.noise(OctaveGenerator.java:187)
at org.bukkit.util.noise.OctaveGenerator.noise(OctaveGenerator.java:161)
at org.bukkit.util.noise.OctaveGenerator.noise(OctaveGenerator.java:131)
at de.mineone.island.generator.Island.generateIsland(Island.java:114)
at de.mineone.island.generator.Island.generate(Island.java:40)
at de.mineone.island.generator.Island.<init>(Island.java:36)
at de.mineone.island.main.Main$1.run(Main.java:80)
at org.bukkit.craftbukkit.v1_8_R1.scheduler.CraftTask.run(CraftTask.java:53)
...
"Server Infinisleeper" Id=16 TIMED_WAITING
at java.lang.Thread.sleep(Native Method)
at net.minecraft.server.v1_8_R1.ThreadSleepForever.run(SourceFile:64)
"Snooper Timer" Id=12 WAITING on java.util.TaskQueue@3c43352b
at java.lang.Object.wait(Native Method)
- waiting on java.util.TaskQueue@3c43352b
at java.lang.Object.wait(Object.java:503)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)
"Attach Listener" Id=6 RUNNABLE
"Signal Dispatcher" Id=5 RUNNABLE
"Finalizer" Id=3 WAITING on java.lang.ref.ReferenceQueue$Lock@6057b8f5
at java.lang.Object.wait(Native Method)
- waiting on java.lang.ref.ReferenceQueue$Lock@6057b8f5
at java.lang.ref.ReferenceQueue.remove(Unknown Source)
at java.lang.ref.ReferenceQueue.remove(Unknown Source)
at java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)
"Reference Handler" Id=2 WAITING on java.lang.ref.Reference$Lock@1f300e3d
at java.lang.Object.wait(Native Method)
- waiting on java.lang.ref.Reference$Lock@1f300e3d
at java.lang.Object.wait(Object.java:503)
at java.lang.ref.Reference$ReferenceHandler.run(Unknown Source)
Stacktrace:
at net.minecraft.server.v1_8_R1.ThreadWatchdog.run(SourceFile:59)
at java.lang.Thread.run(Unknown Source)
-- System Details --
Details:
Minecraft Version: 1.8
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.7.0_65, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 99006072 bytes (94 MB) / 241586176 bytes (230 MB) up to 1037959168 bytes (989 MB)
JVM Flags: 2 total; -Xincgc -Xmx1G
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
CraftBukkit Information:
Running: CraftBukkit version git-Bukkit-f498585 (MC: 1.8) (Implementing API version 1.8-R0.1-SNAPSHOT) true
Plugins: { Island v0.1 de.mineone.island.main.Main [MinecraftTechnicLP, harry_potter4567],}
Warnings: DEFAULT
Threads: { WAITING Snooper Timer: [java.lang.Object.wait(Native Method), java.lang.Object.wait(Object.java:503), java.util.TimerThread.mainLoop(Unknown Source), java.util.TimerThread.run(Unknown Source)], WAITING Finalizer: [java.lang.Object.wait(Native Method), java.lang.ref.ReferenceQueue.remove(Unknown Source), java.lang.ref.ReferenceQueue.remove(Unknown Source), java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)], RUNNABLE Server thread: [org.bukkit.util.noise.OctaveGenerator.noise(OctaveGenerator.java:187), org.bukkit.util.noise.OctaveGenerator.noise(OctaveGenerator.java:161), org.bukkit.util.noise.OctaveGenerator.noise(OctaveGenerator.java:131), de.mineone.island.generator.Island.generateIsland(Island.java:114), de.mineone.island.generator.Island.generate(Island.java:40), de.mineone.island.generator.Island.<init>(Island.java:36), de.mineone.island.main.Main$1.run(Main.java:80), org.bukkit.craftbukkit.v1_8_R1.scheduler.CraftTask.run(CraftTask.java:53), org.bukkit.craftbukkit.v1_8_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:349), net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:655), net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:284), net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:600), net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:508), java.lang.Thread.run(Unknown Source)], RUNNABLE DestroyJavaVM: [], TIMED_WAITING Server Infinisleeper: [java.lang.Thread.sleep(Native Method), net.minecraft.server.v1_8_R1.ThreadSleepForever.run(SourceFile:64)], RUNNABLE Server Watchdog: [java.lang.Thread.dumpThreads(Native Method), java.lang.Thread.getAllStackTraces(Unknown Source), org.bukkit.craftbukkit.v1_8_R1.CraftCrashReport.call(CraftCrashReport.java:28), net.minecraft.server.v1_8_R1.CrashReportSystemDetails.a(SourceFile:78), net.minecraft.server.v1_8_R1.CrashReport.h(CrashReport.java:43), net.minecraft.server.v1_8_R1.CrashReport.<init>(CrashReport.java:32), net.minecraft.server.v1_8_R1.ThreadWatchdog.run(SourceFile:57), java.lang.Thread.run(Unknown Source)], RUNNABLE Netty Server IO #0: [sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method), sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(Unknown Source), sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(Unknown Source), sun.nio.ch.WindowsSelectorImpl.doSelect(Unknown Source), sun.nio.ch.SelectorImpl.lockAndDoSelect(Unknown Source), sun.nio.ch.SelectorImpl.select(Unknown Source), io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:618), io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:306), io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116), java.lang.Thread.run(Unknown Source)], WAITING Reference Handler: [java.lang.Object.wait(Native Method), java.lang.Object.wait(Object.java:503), java.lang.ref.Reference$ReferenceHandler.run(Unknown Source)], RUNNABLE Attach Listener: [], RUNNABLE Server console handler: [org.fusesource.jansi.internal.Kernel32._getch(Native Method), org.fusesource.jansi.internal.WindowsSupport.readByte(WindowsSupport.java:46), org.bukkit.craftbukkit.libs.jline.WindowsTerminal.readByte(WindowsTerminal.java:184), org.bukkit.craftbukkit.libs.jline.WindowsTerminal.access$000(WindowsTerminal.java:53), org.bukkit.craftbukkit.libs.jline.WindowsTerminal$1.read(WindowsTerminal.java:151), java.io.FilterInputStream.read(Unknown Source), org.bukkit.craftbukkit.libs.jline.console.ConsoleReader$1.read(ConsoleReader.java:167), org.bukkit.craftbukkit.libs.jline.internal.InputStreamReader.read(InputStreamReader.java:267), org.bukkit.craftbukkit.libs.jline.internal.InputStreamReader.read(InputStreamReader.java:204), org.bukkit.craftbukkit.libs.jline.console.ConsoleReader.readCharacter(ConsoleReader.java:995), org.bukkit.craftbukkit.libs.jline.console.ConsoleReader.readLine(ConsoleReader.java:1167), net.minecraft.server.v1_8_R1.ThreadCommandReader.run(ThreadCommandReader.java:33)], RUNNABLE Signal Dispatcher: [], WAITING Thread-5: [sun.misc.Unsafe.park(Native Method), java.util.concurrent.locks.LockSupport.park(Unknown Source), java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(Unknown Source), java.util.concurrent.LinkedBlockingQueue.take(Unknown Source), com.mojang.util.QueueLogAppender.getNextLogEvent(QueueLogAppender.java:77), org.bukkit.craftbukkit.v1_8_R1.util.TerminalConsoleWriterThread.run(TerminalConsoleWriterThread.java:25), java.lang.Thread.run(Unknown Source)],}
Recent tasks from -29-1{}
Profiler Position: N/A (disabled)
Player Count: 0 / 20; []
Is Modded: Definitely; Server brand changed to 'CraftBukkit'
Type: Dedicated Server (map_server.txt)
这些岛是使用以下类生成的
package de.mineone.island.generator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Banner;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.util.noise.SimplexOctaveGenerator;
import de.mineone.island.main.Main;
public class Island {
private static final int EDGE_BIAS = 12;
private static final int HEIGHT = 50;
private Location loc;
private int xWidth;
private int zWidth;
private Banner flag;
private DyeColor color;
private ArrayList<Integer> illegalX = new ArrayList<Integer>();
private ArrayList<Integer> illegalZ = new ArrayList<Integer>();
public Island(Location loc, int xWidth, int zWidth, DyeColor color) {
this.loc = loc;
this.xWidth = xWidth;
this.zWidth = zWidth;
this.color = color;
generate();
}
public void generate() {
generateIsland();
generateFlag();
generateTrees();
}
private void generateIsland() {
HashMap<Integer, Material> lvlMat = new HashMap<Integer, Material>();
lvlMat.put(1, Material.SAND);
lvlMat.put(2, Material.SAND);
lvlMat.put(3, Material.SAND);
lvlMat.put(4, Material.SAND);
lvlMat.put(5, Material.SAND);
lvlMat.put(6, Material.SAND);
lvlMat.put(7, Material.SAND);
lvlMat.put(8, Material.SAND);
lvlMat.put(9, Material.SAND);
lvlMat.put(10, Material.SAND);
lvlMat.put(11, Material.SAND);
lvlMat.put(12, Material.SAND);
lvlMat.put(13, Material.SAND);
lvlMat.put(14, Material.SAND);
lvlMat.put(15, Material.SAND);
lvlMat.put(16, Material.SAND);
lvlMat.put(17, Material.SAND);
lvlMat.put(18, Material.SAND);
lvlMat.put(19, Material.SAND);
lvlMat.put(20, Material.SAND);
lvlMat.put(21, Material.SAND);
lvlMat.put(22, Material.SAND);
lvlMat.put(23, Material.SAND);
lvlMat.put(24, Material.SAND);
lvlMat.put(25, Material.DIRT);
lvlMat.put(26, Material.DIRT);
lvlMat.put(27, Material.DIRT);
lvlMat.put(28, Material.DIRT);
lvlMat.put(29, Material.DIRT);
lvlMat.put(30, Material.DIRT);
lvlMat.put(31, Material.DIRT);
lvlMat.put(32, Material.DIRT);
lvlMat.put(33, Material.DIRT);
lvlMat.put(34, Material.DIRT);
lvlMat.put(35, Material.DIRT);
lvlMat.put(36, Material.STONE);
lvlMat.put(37, Material.STONE);
lvlMat.put(38, Material.STONE);
lvlMat.put(39, Material.STONE);
lvlMat.put(40, Material.STONE);
lvlMat.put(41, Material.STONE);
lvlMat.put(42, Material.STONE);
lvlMat.put(43, Material.STONE);
lvlMat.put(44, Material.STONE);
lvlMat.put(45, Material.STONE);
lvlMat.put(46, Material.STONE);
lvlMat.put(47, Material.STONE);
lvlMat.put(48, Material.STONE);
lvlMat.put(49, Material.STONE);
lvlMat.put(50, Material.STONE);
lvlMat.put(51, Material.STONE);
double[] rollingParticle = getRollingParticle();
SimplexOctaveGenerator gen = new SimplexOctaveGenerator(new Random(), 8);
gen.setScale(1 / 512.0D);
ArrayList<XYZLocation> blocks = new ArrayList<XYZLocation>();
int highestBlock = 0;
while(highestBlock < 35) {
blocks.clear();
int hb = 0;
for(int x = 0; x < xWidth; x++) {
for(int z = 0; z < zWidth; z++) {
double noise = gen.noise(x, z, 0.5, 0.5) * HEIGHT * rollingParticle[x + z * xWidth];
for(int y = 1; y < noise + 1; y++) {
if(y > hb) hb = y;
if(y == ((int)noise) + 1) {
blocks.add(new XYZLocation(x, y, z, true));
} else {
blocks.add(new XYZLocation(x, y, z, false));
}
}
}
}
highestBlock = hb;
}
for(XYZLocation xyz : blocks) {
Material mat = lvlMat.get(xyz.getY());
Location l = loc.add(xyz.getLocation(loc.getWorld()));
loc.getWorld().getChunkAt(l).load();
if(xyz.isSurface() && mat == Material.DIRT) {
loc.getWorld().getBlockAt(l).setBiome(Biome.BEACH);
loc.getWorld().getBlockAt(l).setType(Material.GRASS);
} else {
loc.getWorld().getBlockAt(l).setType(mat);
}
}
}
@SuppressWarnings("unused")
private double[] getGradient() {
double[] gradient = new double[xWidth * zWidth];
int xMid = xWidth / 2;
int zMid = zWidth / 2;
double xStep = 0.4 / xMid;
double zStep = 0.4 / zMid;
for(int x = 0; x < xWidth; x++) {
int xMultiplier = x > xMid ? xMid - x * -1 : x;
for(int z = 0; z < zWidth; z++) {
int zMultiplier = z > zMid ? zMid - z * -1 : z;
gradient[x + z * xWidth] = xMultiplier * xStep + zMultiplier * zStep + 0.2;
}
}
return gradient;
}
private double[] normalize(double[] array) {
int highest = 0;
int lowest = Integer.MAX_VALUE;
for(int x = 0; x < xWidth; x++) {
for(int z = 0; z < zWidth; z++) {
int i = x + z * xWidth;
if(array[i] < lowest) lowest = (int) array[i];
if(array[i] > highest) highest = (int) array[i];
}
}
for(int x = 0; x < xWidth; x++) {
for(int z = 0; z < zWidth; z++) {
int i = x + z * xWidth;
double percent = (array[i] - lowest) / (highest - lowest);
array[i] = percent;
}
}
return array;
}
private ArrayList<BlockLocation> getNeighbourHood(int srcX, int srcZ) {
ArrayList<BlockLocation> locs = new ArrayList<BlockLocation>();
for(int x = -1; x <= 1; x++) {
for(int z = -1; z <= 1; z++) {
if(x + srcX >= 0 && x + srcX < xWidth && z + srcZ >= 0 && z + srcZ < zWidth) {
if(x != 0 || z != 0) {
locs.add(new BlockLocation(x + srcX, z + srcZ));
}
}
}
}
return locs;
}
private double[] getRollingParticle() {
double[] rollingParticle = new double[xWidth * zWidth];
for(int i = 0; i < 2000; i++) {
int srcX = (int) (Math.random() * (xWidth - (EDGE_BIAS * 2)) + EDGE_BIAS);
int srcZ = (int) (Math.random() * (zWidth - (EDGE_BIAS * 2)) + EDGE_BIAS);
for(int length = 0; length < 50; length++) {
srcX += Math.round(Math.random() * 2 - 1);
srcZ += Math.round(Math.random() * 2 - 1);
if(srcX < 1 || srcX > xWidth - 2 || srcZ < 1 || srcZ > zWidth - 2) break;
for(BlockLocation loc : getNeighbourHood(srcX, srcZ)) {
if(rollingParticle[loc.getX() + loc.getZ() * xWidth] < rollingParticle[srcX + srcZ * xWidth]) {
srcX = loc.getX();
srcZ = loc.getZ();
break;
}
}
rollingParticle[srcX + srcZ * xWidth] += 1;
}
}
return normalize(rollingParticle);
}
private void generateFlag() {
Location highestLoc = null;
int highest = 0;
for(int x = 0; x < xWidth; x++) {
for(int z = 0; z < xWidth; z++) {
Location l = loc.clone().add(x, 0, z);
l.setY(l.getWorld().getHighestBlockYAt(l));
if(l.getBlockY() > highest) {
highest = l.getBlockY();
highestLoc = l;
}
}
}
loc.getWorld().getBlockAt(highestLoc.clone().add(0, 0, 0)).setType(Material.DARK_OAK_FENCE);
loc.getWorld().getBlockAt(highestLoc.clone().add(0, 1, 0)).setType(Material.DARK_OAK_FENCE);
Block block = loc.getWorld().getBlockAt(highestLoc.clone().add(0, 2, 0));
block.setType(Material.STANDING_BANNER);
Banner b = (Banner) block.getState();
b.setBaseColor(color);
b.update();
if(!illegalX.contains(b.getLocation().getBlockX())) illegalX.add(b.getLocation().getBlockX());
if(!illegalZ.contains(b.getLocation().getBlockZ())) illegalZ.add(b.getLocation().getBlockZ());
}
private void generateTrees() {
for(int i = 0; i < Main.TREES; i++) {
Location tree = null;
while(tree == null) {
Random rdm = new Random();
Location l = new Location(loc.getWorld(), rdm.nextInt(xWidth), 0, rdm.nextInt(zWidth));
l.setY(loc.getWorld().getHighestBlockYAt(l));
if(!(l.getBlockY() < 25 || illegalX.contains(l.getX()) || illegalX.contains(l.getX() + 1) || illegalX.contains(l.getX() - 1) || illegalZ.contains(l.getZ()) || illegalZ.contains(l.getZ() + 1) || illegalZ.contains(l.getZ() - 1))) {
tree = l;
}
}
generateRandomTree(loc.clone().add(tree));
}
}
@SuppressWarnings("deprecation")
private void generateRandomTree(Location l) {
int blocks = new Random().nextInt(5) + 8;
for(int b = 0; b <= blocks; b++) {
loc.getWorld().getBlockAt(l).setType(Material.LOG);
loc.getWorld().getBlockAt(l).setData((byte) 3);
if(!illegalX.contains(l.getBlockX())) {
illegalX.add(l.getBlockX());
}
if(!illegalZ.contains(l.getBlockZ())) {
illegalZ.add(l.getBlockZ());
}
if(b == blocks) continue;
Random rdm = new Random();
switch(rdm.nextInt(19)) {
case 0:
l.add(1, 0, 0);
break;
case 1:
l.add(-1, 0, 0);
break;
case 2:
l.add(0, 0, 1);
break;
case 3:
l.add(0, 0, -1);
break;
default:
l.add(0, 1, 0);
break;
}
}
//loc.getWorld().getBlockAt(loc.clone().add(x, y, z)).setBiome(Biome.BEACH);
ArrayList<Block> leaves = new ArrayList<Block>();
for(int x = -4; x <= 4; x++) {
if(x == -4 || x == 4) {
leaves.add(loc.getWorld().getBlockAt(l.clone().add(x, 1, 0)));
} else if(x == -3 || x == 3) {
leaves.add(loc.getWorld().getBlockAt(l.clone().add(x, 2, 0)));
leaves.add(loc.getWorld().getBlockAt(l.clone().add(x, 1, 3)));
leaves.add(loc.getWorld().getBlockAt(l.clone().add(x, 1, -3)));
} else if(x == -2 || x == 2) {
leaves.add(loc.getWorld().getBlockAt(l.clone().add(x, 2, 0)));
leaves.add(loc.getWorld().getBlockAt(l.clone().add(x, 2, 2)));
leaves.add(loc.getWorld().getBlockAt(l.clone().add(x, 2, -2)));
} else if(x == -1 || x == 1) {
leaves.add(loc.getWorld().getBlockAt(l.clone().add(x, 1, 0)));
leaves.add(loc.getWorld().getBlockAt(l.clone().add(x, 2, 1)));
leaves.add(loc.getWorld().getBlockAt(l.clone().add(x, 2, -1)));
} else if(x == 0) {
leaves.add(loc.getWorld().getBlockAt(l.clone().add(x, 1, -4)));
leaves.add(loc.getWorld().getBlockAt(l.clone().add(x, 2, -3)));
leaves.add(loc.getWorld().getBlockAt(l.clone().add(x, 2, -2)));
leaves.add(loc.getWorld().getBlockAt(l.clone().add(x, 1, -1)));
leaves.add(loc.getWorld().getBlockAt(l.clone().add(x, 1, 0)));
leaves.add(loc.getWorld().getBlockAt(l.clone().add(x, 1, 4)));
leaves.add(loc.getWorld().getBlockAt(l.clone().add(x, 2, 3)));
leaves.add(loc.getWorld().getBlockAt(l.clone().add(x, 2, 2)));
leaves.add(loc.getWorld().getBlockAt(l.clone().add(x, 1, 1)));
}
}
for(Block b : leaves) {
if(!illegalX.contains(b.getLocation().getBlockX())) {
illegalX.add(b.getLocation().getBlockX());
}
if(!illegalZ.contains(b.getLocation().getBlockZ())) {
illegalZ.add(b.getLocation().getBlockZ());
}
b.setBiome(Biome.BEACH);
b.setType(Material.LEAVES);
b.setData((byte) 3);
}
}
public Banner getFlag() {
return flag;
}
}
XYZLocation仅存储3个整数和1个布尔值以及BlockLocation 2个整数。 这只是为了保存尽可能少的世界实例,而且还保存整数而不是双精度。
离岛是在玩家能够加入之前生成的,因此,如果有可能防止服务器发狂,这也将非常有用。
我为此工作了好几天,却无法找出解决方案,因此,感谢您提前提供的帮助。
1楼
您的代码中有很多循环,您应该对其进行一些优化。 例如,此getRollingParticle不应小一些吗?
2楼
您在代码中创建了一个无限循环,具体取决于所生成的随机数,噪声将保持在-1以下,从而导致y for循环永远不会执行,因此变量hb
永远不会更新为除0以外的任何其他值。使可变噪声永远不低于0并不是一个好的解决方案,因为对于任何坐标,总是存在这样的风险,即噪声可能会在0到35之间徘徊,从而再次引起bug。
该错误的解决方案是更改代码以在生成器的第四维噪声谱中选择一个不同的点,然后再次尝试使用该点以查看它是否产生了至少35高度的更好噪声。
为此,将执行以下操作:
int attempt = 0;
while(highestBlock < 35) {
attempt++;
blocks.clear();
int hb = 0;
for(int x = 0; x < xWidth; x++) {
for(int z = 0; z < zWidth; z++) {
double noise = gen.noise(x, z, attempt*5, 0.5, 0.5) * HEIGHT * rollingParticle[x + z * xWidth];
double noisePlusOne = noise + 1;
for(int y = 1; y < noisePlusOne; y++) {
if(y > hb) hb = y;
if(y == ((int)noise)) {
blocks.add(new XYZLocation(x, y, z, true));
} else {
blocks.add(new XYZLocation(x, y, z, false));
}
}
}
}
System.out.println("max:" + hb);
highestBlock = hb;
}
请注意,我添加了一个system.out调试语句以打印出最大块数,尝试解决孤岛高度冲突时,您应该看到它有所变化,如果仍然花费很长时间,则可能需要将第三个参数增加到gen.noise,例如,使用attempt*10
使其在噪声频谱中移动得更快。
我建议您使用该参数,以查看产生最佳结果的参数。