Simplified switch statements and minor formatting

This commit is contained in:
matt 2019-03-27 11:36:26 -04:00
parent 67fd0668ee
commit 1424998327
8 changed files with 50 additions and 86 deletions

View File

@ -202,16 +202,12 @@ public abstract class IntFaweChunk<T, V extends FaweQueue> extends FaweChunk<T>
} }
vs[j] = combinedId; vs[j] = combinedId;
this.count[i]++; this.count[i]++;
switch (BlockTypes.getFromStateId(combinedId).getResource().toUpperCase()) { if (BlockTypes.getFromStateId(combinedId).getMaterial().isAir()) {
case "AIR": this.air[i]++;
case "CAVE_AIR": return;
case "VOID_AIR":
this.air[i]++;
return;
default:
heightMap[z << 4 | x] = (byte) y;
return;
} }
heightMap[z << 4 | x] = (byte) y;
return;
} }
@Deprecated @Deprecated

View File

@ -284,11 +284,8 @@ public interface FaweQueue extends HasFaweQueue, Extent {
int combined = getCombinedId4Data(xx, y, zz); int combined = getCombinedId4Data(xx, y, zz);
BaseBlock block = BlockState.getFromInternalId(combined).toBaseBlock(); BaseBlock block = BlockState.getFromInternalId(combined).toBaseBlock();
BlockType type = block.getBlockType(); BlockType type = block.getBlockType();
switch (type.getResource().toUpperCase()) { if (type.getMaterial().isAir()) {
case "AIR": continue;
case "VOID_AIR":
case "CAVE_AIR":
continue;
} }
mutable.mutY(y); mutable.mutY(y);
CompoundTag tile = getTileEntity(x, y, z); CompoundTag tile = getTileEntity(x, y, z);

View File

@ -115,17 +115,12 @@ public class VisualChunk extends FaweChunk<FaweChunk> {
public void setBlock(int x, int y, int z, int combinedId) { public void setBlock(int x, int y, int z, int combinedId) {
int index = getIndex(x, y, z); int index = getIndex(x, y, z);
try { try {
switch (BlockTypes.getFromStateId(combinedId).getResource().toUpperCase()) { if (BlockTypes.getFromStateId(combinedId).getMaterial().isAir()) {
case "AIR": add.clear(index);
case "CAVE_AIR": remove.set(index);
case "VOID_AIR": } else {
add.clear(index); remove.clear(index);
remove.set(index); add.set(index);
break;
default:
remove.clear(index);
add.set(index);
break;
} }
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -175,13 +175,8 @@ public class CPUOptimizedClipboard extends FaweClipboard {
for (int z = 0; z < length; z++) { for (int z = 0; z < length; z++) {
for (int x = 0; x < width; x++, index++) { for (int x = 0; x < width; x++, index++) {
BaseBlock block = getBlock(index); BaseBlock block = getBlock(index);
switch (block.getBlockType().getResource().toUpperCase()) { if (!block.getMaterial().isAir()) {
case "AIR": task.run(x, y, z, block);
case "CAVE_AIR":
case "VOID_AIR":
continue;
default:
task.run(x, y, z, block);
} }
} }
} }

View File

@ -404,23 +404,18 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
for (int x = 0; x < width; x++, pos += 4) { for (int x = 0; x < width; x++, pos += 4) {
int combinedId = mbb.getInt(pos); int combinedId = mbb.getInt(pos);
BlockType type = BlockTypes.getFromStateId(combinedId); BlockType type = BlockTypes.getFromStateId(combinedId);
switch (type.getResource().toUpperCase()) { if (!type.getMaterial().isAir()) {
case "AIR": BlockState state = type.withStateId(combinedId);
case "CAVE_AIR": if (type.getMaterial().hasContainer()) {
case "VOID_AIR": trio.set(x, y, z);
continue; CompoundTag nbt = nbtMap.get(trio);
default: if (nbt != null) {
BlockState state = type.withStateId(combinedId); BaseBlock block = new BaseBlock(state, nbt);
if (type.getMaterial().hasContainer()) { task.run(x, y, z, block);
trio.set(x, y, z); continue;
CompoundTag nbt = nbtMap.get(trio);
if (nbt != null) {
BaseBlock block = new BaseBlock(state, nbt);
task.run(x, y, z, block);
continue;
}
} }
task.run(x, y, z, state); }
task.run(x, y, z, state);
} }
} }
} }

View File

@ -205,11 +205,8 @@ public class MemoryOptimizedClipboard extends FaweClipboard {
} }
if (lastCombinedIds == null) { if (lastCombinedIds == null) {
BlockType bt = BlockTypes.getFromStateId(v); BlockType bt = BlockTypes.getFromStateId(v);
switch (bt.getResource().toUpperCase()) { if (bt.getMaterial().isAir()) {
case "AIR": return;
case "CAVE_AIR":
case "VOID_AIR":
return;
} }
lastCombinedIds = new byte[BLOCK_SIZE]; lastCombinedIds = new byte[BLOCK_SIZE];
} }
@ -299,13 +296,8 @@ public class MemoryOptimizedClipboard extends FaweClipboard {
for (int z = 0; z < length; z++) { for (int z = 0; z < length; z++) {
for (int x = 0; x < width; x++, index++) { for (int x = 0; x < width; x++, index++) {
BaseBlock block = getBlock(index); BaseBlock block = getBlock(index);
switch (block.getBlockType().getResource().toUpperCase()) { if (!block.getMaterial().isAir()) {
case "AIR": task.run(x, y, z, block);
case "CAVE_AIR":
case "VOID_AIR":
continue;
default:
task.run(x, y, z, block);
} }
} }
} }

View File

@ -84,7 +84,7 @@ public class StructureFormat implements ClipboardReader, ClipboardWriter {
ListTag blocks = (ListTag) tags.get("blocks"); ListTag blocks = (ListTag) tags.get("blocks");
if (blocks != null) { if (blocks != null) {
// Palette // Palette
List<CompoundTag> palette = (List<CompoundTag>) (List<?>) tags.get("palette").getValue(); List<CompoundTag> palette = (List<CompoundTag>) tags.get("palette").getValue();
BlockState[] combinedArray = new BlockState[palette.size()]; BlockState[] combinedArray = new BlockState[palette.size()];
for (int i = 0; i < palette.size(); i++) { for (int i = 0; i < palette.size(); i++) {
CompoundTag compound = palette.get(i); CompoundTag compound = palette.get(i);
@ -108,7 +108,7 @@ public class StructureFormat implements ClipboardReader, ClipboardWriter {
combinedArray[i] = state; combinedArray[i] = state;
} }
// Populate blocks // Populate blocks
List<CompoundTag> blocksList = (List<CompoundTag>) (List<?>) tags.get("blocks").getValue(); List<CompoundTag> blocksList = (List<CompoundTag>) tags.get("blocks").getValue();
try { try {
for (CompoundTag compound : blocksList) { for (CompoundTag compound : blocksList) {
Map<String, Tag> blockMap = compound.getValue(); Map<String, Tag> blockMap = compound.getValue();
@ -184,7 +184,7 @@ public class StructureFormat implements ClipboardReader, ClipboardWriter {
continue; continue;
} }
indexes.put((int) combined, (Integer) palette.size()); indexes.put(combined, (Integer) palette.size());
HashMap<String, Object> paletteEntry = new HashMap<>(); HashMap<String, Object> paletteEntry = new HashMap<>();
paletteEntry.put("Name", type.getId()); paletteEntry.put("Name", type.getId());
if (block.getInternalId() != type.getInternalId()) { if (block.getInternalId() != type.getInternalId()) {
@ -213,18 +213,17 @@ public class StructureFormat implements ClipboardReader, ClipboardWriter {
BlockVector3 min = region.getMinimumPoint(); BlockVector3 min = region.getMinimumPoint();
for (BlockVector3 point : region) { for (BlockVector3 point : region) {
BaseBlock block = clipboard.getFullBlock(point); BaseBlock block = clipboard.getFullBlock(point);
switch (block.getBlockType().getResource().toUpperCase()) { if (block.getBlockType() != BlockTypes.STRUCTURE_VOID) {
case "STRUCTURE_VOID": int combined = block.getInternalId();
continue; int index = indexes.get(combined);
default: List<Integer> pos = Arrays.asList(point.getX() - min.getX(),
int combined = block.getInternalId(); point.getY() - min.getY(), point.getZ() - min.getZ());
int index = indexes.get(combined); if (!block.hasNbtData()) {
List<Integer> pos = Arrays.asList((int) (point.getX() - min.getX()), (int) (point.getY() - min.getY()), (int) (point.getZ() - min.getZ())); blocks.add(FaweCache.asMap("state", index, "pos", pos));
if (!block.hasNbtData()) { } else {
blocks.add(FaweCache.asMap("state", index, "pos", pos)); blocks.add(
} else { FaweCache.asMap("state", index, "pos", pos, "nbt", block.getNbtData()));
blocks.add(FaweCache.asMap("state", index, "pos", pos, "nbt", block.getNbtData())); }
}
} }
} }
if (!blocks.isEmpty()) { if (!blocks.isEmpty()) {
@ -268,7 +267,7 @@ public class StructureFormat implements ClipboardReader, ClipboardWriter {
} }
private Tag writeVector(BlockVector3 vector, String name) { private Tag writeVector(BlockVector3 vector, String name) {
List<DoubleTag> list = new ArrayList<DoubleTag>(); List<DoubleTag> list = new ArrayList<>();
list.add(new DoubleTag(vector.getX())); list.add(new DoubleTag(vector.getX()));
list.add(new DoubleTag(vector.getY())); list.add(new DoubleTag(vector.getY()));
list.add(new DoubleTag(vector.getZ())); list.add(new DoubleTag(vector.getZ()));
@ -276,7 +275,7 @@ public class StructureFormat implements ClipboardReader, ClipboardWriter {
} }
private Tag writeRotation(Location location, String name) { private Tag writeRotation(Location location, String name) {
List<FloatTag> list = new ArrayList<FloatTag>(); List<FloatTag> list = new ArrayList<>();
list.add(new FloatTag(location.getYaw())); list.add(new FloatTag(location.getYaw()));
list.add(new FloatTag(location.getPitch())); list.add(new FloatTag(location.getPitch()));
return new ListTag(FloatTag.class, list); return new ListTag(FloatTag.class, list);

View File

@ -66,7 +66,7 @@ public class FloatingTreeRemover implements BlockTool {
@Override @Override
public boolean actPrimary(Platform server, LocalConfiguration config, public boolean actPrimary(Platform server, LocalConfiguration config,
Player player, LocalSession session, Location clicked) { Player player, LocalSession session, Location clicked) {
final World world = (World) clicked.getExtent(); final World world = (World) clicked.getExtent();
final BlockState state = world.getBlock(clicked.toVector().toBlockPoint()); final BlockState state = world.getBlock(clicked.toVector().toBlockPoint());
@ -132,13 +132,8 @@ public class FloatingTreeRemover implements BlockTool {
if (visited.add(next)) { if (visited.add(next)) {
BlockState state = world.getBlock(next); BlockState state = world.getBlock(next);
BlockType type = state.getBlockType(); if (state.getBlockType().getMaterial().isAir() || state.getBlockType() == BlockTypes.SNOW) {
switch (type.getResource().toUpperCase()) { continue;
case "AIR":
case "CAVE_AIR":
case "VOID_AIR":
case "SNOW":
continue;
} }
if (isTreeBlock(state.getBlockType())) { if (isTreeBlock(state.getBlockType())) {
queue.addLast(next); queue.addLast(next);