water height

This commit is contained in:
Jesse Boyd 2017-05-01 03:04:35 +10:00
parent 94e5a931ec
commit b756f93361
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 215 additions and 151 deletions

View File

@ -13,6 +13,7 @@ import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.BlockPattern;
@ -43,10 +44,11 @@ public class HeightMapMCAGenerator extends MCAWriter implements Extent {
private final char[] floor;
private final char[] main;
private char[] overlay;
private int waterHeight = 0;
private TextureUtil textureUtil;
private boolean randomVariation = true;
private int biomePriority = 0;
private byte waterId = BlockID.STATIONARY_WATER;
private boolean modifiedMain = false;
public HeightMapMCAGenerator(BufferedImage img, File regionFolder) {
@ -78,6 +80,14 @@ public class HeightMapMCAGenerator extends MCAWriter implements Extent {
}
}
public void setWaterHeight(int waterHeight) {
this.waterHeight = waterHeight;
}
public void setWaterId(int waterId) {
this.waterId = (byte) waterId;
}
public void setTextureRandomVariation(boolean randomVariation) {
this.randomVariation = randomVariation;
}
@ -214,6 +224,9 @@ public class HeightMapMCAGenerator extends MCAWriter implements Extent {
}
}
}
if (y > waterHeight) {
return FaweCache.CACHE_BLOCK[waterId << 4];
}
return FaweCache.CACHE_BLOCK[0];
} else if (y == height) {
return FaweCache.CACHE_BLOCK[floor[index]];
@ -630,6 +643,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements Extent {
@Override
public MCAChunk write(MCAChunk chunk, int csx, int cex, int csz, int cez) {
try {
int cx = chunk.getX();
int cz = chunk.getZ();
int[] indexes = indexStore.get();
@ -698,6 +712,27 @@ public class HeightMapMCAGenerator extends MCAWriter implements Extent {
Arrays.fill(chunk.ids[layer], (byte) 1);
}
}
if (waterHeight != 0) {
maxY = Math.max(maxY, waterHeight);
int maxWaterLayer = ((waterHeight + 15) >> 4);
for (int layer = 0; layer < maxWaterLayer; layer++) {
boolean fillAll = (layer << 4) + 15 <= waterHeight;
byte[] ids = chunk.ids[layer];
if (ids == null) {
chunk.ids[layer] = ids = new byte[4096];
chunk.data[layer] = new byte[2048];
chunk.skyLight[layer] = new byte[2048];
chunk.blockLight[layer] = new byte[2048];
Arrays.fill(chunk.skyLight[layer], (byte) 255);
}
if (fillAll) {
Arrays.fill(ids, waterId);
} else {
int maxIndex = maxWaterLayer << 8;
Arrays.fill(ids, 0, maxIndex, waterId);
}
}
}
for (int layer = fillLayers; layer <= maxLayer; layer++) {
Arrays.fill(chunk.skyLight[layer], (byte) 255);
byte[] layerIds = chunk.ids[layer];
@ -812,6 +847,9 @@ public class HeightMapMCAGenerator extends MCAWriter implements Extent {
}
}
}
} catch (Throwable e) {
e.printStackTrace();
}
return chunk;
}

View File

@ -145,6 +145,8 @@ public class CreateFromImage extends Command {
fp.sendMessage(BBC.getPrefix() + "/2 cfi ore[s]");
fp.sendMessage(BBC.getPrefix() + "/2 cfi schem <mask> <schem> <rarity> <rotate>");
fp.sendMessage(BBC.getPrefix() + "/2 cfi height <image-url|height>");
fp.sendMessage(BBC.getPrefix() + "/2 cfi waterheight <height>");
fp.sendMessage(BBC.getPrefix() + "/2 cfi waterid <number-id>");
fp.sendMessage(BBC.getPrefix() + "/2 cfi color <image-url>");
fp.sendMessage(BBC.getPrefix() + "/2 cfi glass <image-url>");
fp.sendMessage(BBC.getPrefix() + "/2 cfi biomeColor <image-url>");
@ -304,6 +306,30 @@ public class CreateFromImage extends Command {
player.sendMessage("Set glass color, what's next?");
return;
}
case "waterheight":
case "setwaterheight": {
// roughness
// blocks
if (argList.size() != 2) {
C.COMMAND_SYNTAX.send(player, "/2 cfi " + argList.get(0) + " <height>");
return;
}
generator.setWaterHeight(Integer.parseInt(argList.get(1)));
player.sendMessage("Set water height, what's next?");
return;
}
case "waterid":
case "setwaterid": {
// roughness
// blocks
if (argList.size() != 2) {
C.COMMAND_SYNTAX.send(player, "/2 cfi " + argList.get(0) + " <id>");
return;
}
generator.setWaterId(Integer.parseInt(argList.get(1)));
player.sendMessage("Set water id, what's next?");
return;
}
case "height":
case "setheight": {
if (argList.size() != 2) {