Replaced lots of else if constructs by switch/case and other simpler constructs.

Dieser Commit ist enthalten in:
TomyLobo 2011-09-05 03:53:39 +02:00
Ursprung 9ea977af77
Commit 3bcd9a932b
5 geänderte Dateien mit 367 neuen und 234 gelöschten Zeilen

Datei anzeigen

@ -515,20 +515,36 @@ public class CuboidClipboard {
BlockVector pt = new BlockVector(x, y, z); BlockVector pt = new BlockVector(x, y, z);
BaseBlock block; BaseBlock block;
if (blocks[index] == BlockID.WALL_SIGN || blocks[index] == BlockID.SIGN_POST) { switch (blocks[index]) {
case BlockID.WALL_SIGN:
case BlockID.SIGN_POST:
block = new SignBlock(blocks[index], blockData[index]); block = new SignBlock(blocks[index], blockData[index]);
} else if (blocks[index] == BlockID.CHEST) { break;
case BlockID.CHEST:
block = new ChestBlock(blockData[index]); block = new ChestBlock(blockData[index]);
} else if (blocks[index] == BlockID.FURNACE || blocks[index] == BlockID.BURNING_FURNACE) { break;
case BlockID.FURNACE:
case BlockID.BURNING_FURNACE:
block = new FurnaceBlock(blocks[index], blockData[index]); block = new FurnaceBlock(blocks[index], blockData[index]);
} else if (blocks[index] == BlockID.DISPENSER) { break;
case BlockID.DISPENSER:
block = new DispenserBlock(blockData[index]); block = new DispenserBlock(blockData[index]);
} else if (blocks[index] == BlockID.MOB_SPAWNER) { break;
case BlockID.MOB_SPAWNER:
block = new MobSpawnerBlock(blockData[index]); block = new MobSpawnerBlock(blockData[index]);
} else if (blocks[index] == BlockID.NOTE_BLOCK) { break;
case BlockID.NOTE_BLOCK:
block = new NoteBlock(blockData[index]); block = new NoteBlock(blockData[index]);
} else { break;
default:
block = new BaseBlock(blocks[index], blockData[index]); block = new BaseBlock(blocks[index], blockData[index]);
break;
} }
if (block instanceof TileEntityBlock if (block instanceof TileEntityBlock

Datei anzeigen

@ -156,7 +156,6 @@ public class EditSession {
public boolean rawSetBlock(Vector pt, BaseBlock block) { public boolean rawSetBlock(Vector pt, BaseBlock block) {
int y = pt.getBlockY(); int y = pt.getBlockY();
int type = block.getType(); int type = block.getType();
if (y < 0 || y > 127) { if (y < 0 || y > 127) {
return false; return false;
} }
@ -184,16 +183,14 @@ public class EditSession {
world.setBlockType(pt, BlockID.AIR); world.setBlockType(pt, BlockID.AIR);
} }
int id = block.getType();
if (blockBag != null) { if (blockBag != null) {
if (id > 0) { if (type > 0) {
try { try {
blockBag.fetchPlacedBlock(id); blockBag.fetchPlacedBlock(type);
} catch (UnplaceableBlockException e) { } catch (UnplaceableBlockException e) {
return false; return false;
} catch (BlockBagException e) { } catch (BlockBagException e) {
missingBlocks.add(id); missingBlocks.add(type);
return false; return false;
} }
} }
@ -208,7 +205,7 @@ public class EditSession {
boolean result; boolean result;
if (BlockType.usesData(id)) { if (BlockType.usesData(type)) {
if (fastMode) { if (fastMode) {
result = world.setTypeIdAndDataFast(pt, type, block.getData()); result = world.setTypeIdAndDataFast(pt, type, block.getData());
} else { } else {
@ -216,39 +213,21 @@ public class EditSession {
} }
} else { } else {
if (fastMode) { if (fastMode) {
result = world.setBlockTypeFast(pt, id); result = world.setBlockTypeFast(pt, type);
} else { } else {
result = world.setBlockType(pt, id); result = world.setBlockType(pt, type);
} }
} }
//System.out.println(pt + "" +result); //System.out.println(pt + "" +result);
if (id != 0) { if (type != 0) {
if (block instanceof ContainerBlock) {
// Signs if (blockBag == null) {
if (block instanceof SignBlock) { world.copyToWorld(pt, block);
SignBlock signBlock = (SignBlock) block; }
world.copyToWorld(pt, signBlock); }
// Chests else if (block instanceof TileEntityBlock) {
} else if (block instanceof ChestBlock && blockBag == null) { world.copyToWorld(pt, block);
ChestBlock chestBlock = (ChestBlock) block;
world.copyToWorld(pt, chestBlock);
// Furnaces
} else if (block instanceof FurnaceBlock && blockBag == null) {
FurnaceBlock furnaceBlock = (FurnaceBlock) block;
world.copyToWorld(pt, furnaceBlock);
// Dispenser
} else if (block instanceof DispenserBlock && blockBag == null) {
DispenserBlock dispenserBlock = (DispenserBlock) block;
world.copyToWorld(pt, dispenserBlock);
// Mob spawners
} else if (block instanceof MobSpawnerBlock) {
MobSpawnerBlock mobSpawnerblock = (MobSpawnerBlock) block;
world.copyToWorld(pt, mobSpawnerblock);
// Note blocks
} else if (block instanceof NoteBlock) {
NoteBlock noteBlock = (NoteBlock) block;
world.copyToWorld(pt, noteBlock);
} }
} }
return result; return result;
@ -420,37 +399,46 @@ public class EditSession {
int type = world.getBlockType(pt); int type = world.getBlockType(pt);
int data = world.getBlockData(pt); int data = world.getBlockData(pt);
// Sign switch (type) {
if (type == BlockID.WALL_SIGN || type == BlockID.SIGN_POST) { case BlockID.WALL_SIGN:
case BlockID.SIGN_POST: {
SignBlock block = new SignBlock(type, data); SignBlock block = new SignBlock(type, data);
world.copyFromWorld(pt, block); world.copyFromWorld(pt, block);
return block; return block;
// Chest }
} else if (type == BlockID.CHEST) {
case BlockID.CHEST: {
ChestBlock block = new ChestBlock(data); ChestBlock block = new ChestBlock(data);
world.copyFromWorld(pt, block); world.copyFromWorld(pt, block);
return block; return block;
// Furnace }
} else if (type == BlockID.FURNACE || type == BlockID.BURNING_FURNACE) {
case BlockID.FURNACE:
case BlockID.BURNING_FURNACE: {
FurnaceBlock block = new FurnaceBlock(type, data); FurnaceBlock block = new FurnaceBlock(type, data);
world.copyFromWorld(pt, block); world.copyFromWorld(pt, block);
return block; return block;
// Dispenser }
} else if (type == BlockID.DISPENSER) {
case BlockID.DISPENSER: {
DispenserBlock block = new DispenserBlock(data); DispenserBlock block = new DispenserBlock(data);
world.copyFromWorld(pt, block); world.copyFromWorld(pt, block);
return block; return block;
// Mob spawner }
} else if (type == BlockID.MOB_SPAWNER) {
case BlockID.MOB_SPAWNER: {
MobSpawnerBlock block = new MobSpawnerBlock(data); MobSpawnerBlock block = new MobSpawnerBlock(data);
world.copyFromWorld(pt, block); world.copyFromWorld(pt, block);
return block; return block;
// Note block }
} else if (type == BlockID.NOTE_BLOCK) {
case BlockID.NOTE_BLOCK: {
NoteBlock block = new NoteBlock(data); NoteBlock block = new NoteBlock(data);
world.copyFromWorld(pt, block); world.copyFromWorld(pt, block);
return block; return block;
} else { }
default:
return new BaseBlock(type, data); return new BaseBlock(type, data);
} }
} }
@ -2155,17 +2143,27 @@ public class EditSession {
Vector pt = new Vector(x, y, z); Vector pt = new Vector(x, y, z);
int id = getBlockType(pt); int id = getBlockType(pt);
if (id == BlockID.ICE) { // Ice switch (id) {
case BlockID.ICE:
if (setBlock(pt, water)) { if (setBlock(pt, water)) {
++affected; ++affected;
} }
} else if (id == BlockID.SNOW) { break;
case BlockID.SNOW:
if (setBlock(pt, air)) { if (setBlock(pt, air)) {
++affected; ++affected;
} }
} else if (id != 0) { break;
case BlockID.AIR:
continue;
default:
break; break;
} }
break;
} }
} }
} }
@ -2204,10 +2202,8 @@ public class EditSession {
Vector pt = new Vector(x, y, z); Vector pt = new Vector(x, y, z);
int id = getBlockType(pt); int id = getBlockType(pt);
// Snow should not cover these blocks if (id == BlockID.AIR) {
if (BlockType.canPassThrough(id) continue;
&& !(id == BlockID.WATER || id == BlockID.STATIONARY_WATER)) {
break;
} }
// Ice! // Ice!
@ -2218,17 +2214,21 @@ public class EditSession {
break; break;
} }
// Cover // Snow should not cover these blocks
if (id != BlockID.AIR) { if (BlockType.canPassThrough(id)) {
if (y == 127) { // Too high!
break;
}
if (setBlock(pt.add(0, 1, 0), snow)) {
++affected;
}
break; break;
} }
// Too high?
if (y == 127) {
break;
}
// add snow cover
if (setBlock(pt.add(0, 1, 0), snow)) {
++affected;
}
break;
} }
} }
} }
@ -2347,7 +2347,8 @@ public class EditSession {
BaseBlock log = new BaseBlock(BlockID.LOG); BaseBlock log = new BaseBlock(BlockID.LOG);
BaseBlock pumpkin = new BaseBlock(BlockID.PUMPKIN); BaseBlock pumpkin = new BaseBlock(BlockID.PUMPKIN);
if (t == 0) { switch (t) {
case 0:
if (prng.nextBoolean()) { if (prng.nextBoolean()) {
makePumpkinPatchVine(basePos, pos.add(1, 0, 0)); makePumpkinPatchVine(basePos, pos.add(1, 0, 0));
} }
@ -2355,7 +2356,9 @@ public class EditSession {
setBlockIfAir(pos.add(1, h, -1), log); setBlockIfAir(pos.add(1, h, -1), log);
} }
setBlockIfAir(pos.add(0, 0, -1), pumpkin); setBlockIfAir(pos.add(0, 0, -1), pumpkin);
} else if (t == 1) { break;
case 1:
if (prng.nextBoolean()) { if (prng.nextBoolean()) {
makePumpkinPatchVine(basePos, pos.add(0, 0, 1)); makePumpkinPatchVine(basePos, pos.add(0, 0, 1));
} }
@ -2363,7 +2366,9 @@ public class EditSession {
setBlockIfAir(pos.add(1, h, 0), log); setBlockIfAir(pos.add(1, h, 0), log);
} }
setBlockIfAir(pos.add(1, 0, 1), pumpkin); setBlockIfAir(pos.add(1, 0, 1), pumpkin);
} else if (t == 2) { break;
case 2:
if (prng.nextBoolean()) { if (prng.nextBoolean()) {
makePumpkinPatchVine(basePos, pos.add(0, 0, -1)); makePumpkinPatchVine(basePos, pos.add(0, 0, -1));
} }
@ -2371,7 +2376,9 @@ public class EditSession {
setBlockIfAir(pos.add(-1, h, 0), log); setBlockIfAir(pos.add(-1, h, 0), log);
} }
setBlockIfAir(pos.add(-1, 0, 1), pumpkin); setBlockIfAir(pos.add(-1, 0, 1), pumpkin);
} else if (t == 3) { break;
case 3:
if (prng.nextBoolean()) { if (prng.nextBoolean()) {
makePumpkinPatchVine(basePos, pos.add(-1, 0, 0)); makePumpkinPatchVine(basePos, pos.add(-1, 0, 0));
} }

Datei anzeigen

@ -251,66 +251,150 @@ public abstract class LocalWorld {
int type = getBlockType(pt); int type = getBlockType(pt);
//setBlockType(pt, 0); //setBlockType(pt, 0);
if (type == BlockID.STONE) { dropItem(pt, new BaseItemStack(BlockID.COBBLESTONE)); } // Stone switch (type) {
else if (type == BlockID.GRASS) { dropItem(pt, new BaseItemStack(BlockID.DIRT)); } // Grass case BlockID.STONE:
else if (type == BlockID.BEDROCK) { } // Bedrock dropItem(pt, new BaseItemStack(BlockID.COBBLESTONE));
else if (type == BlockID.WATER) { } // Water break;
else if (type == BlockID.STATIONARY_WATER) { } // Water
else if (type == BlockID.LAVA) { } // Lava case BlockID.GRASS:
else if (type == BlockID.STATIONARY_LAVA) { } // Lava dropItem(pt, new BaseItemStack(BlockID.DIRT));
else if (type == BlockID.GRAVEL) { // Gravel break;
case BlockID.GRAVEL:
if (random.nextDouble() >= 0.9) { if (random.nextDouble() >= 0.9) {
dropItem(pt, new BaseItemStack(ItemType.FLINT.getID())); dropItem(pt, new BaseItemStack(ItemType.FLINT.getID()));
} else { } else {
dropItem(pt, new BaseItemStack(type)); dropItem(pt, new BaseItemStack(type));
} }
} break;
else if (type == BlockID.COAL_ORE) { dropItem(pt, new BaseItemStack(ItemType.COAL.getID())); } // Coal ore
else if (type == BlockID.LOG) { dropItem(pt, new BaseItemStack(type, 1, (short) getBlockData(pt))); } // Log case BlockID.COAL_ORE:
else if (type == BlockID.LEAVES) { // Leaves dropItem(pt, new BaseItemStack(ItemType.COAL.getID()));
break;
case BlockID.LOG:
dropItem(pt, new BaseItemStack(type, 1, (short) getBlockData(pt)));
break;
case BlockID.LEAVES:
if (random.nextDouble() > 0.95) { if (random.nextDouble() > 0.95) {
dropItem(pt, new BaseItemStack(BlockID.SAPLING, 1, (short) getBlockData(pt))); dropItem(pt, new BaseItemStack(BlockID.SAPLING, 1, (short) getBlockData(pt)));
} }
} break;
else if (type == BlockID.GLASS) { } // Glass
else if (type == BlockID.LAPIS_LAZULI_ORE) { case BlockID.LAPIS_LAZULI_ORE:
dropItem(pt, new BaseItemStack(ItemType.INK_SACK.getID(), 1, (short) 4), (random.nextInt(5) + 4)); dropItem(pt, new BaseItemStack(ItemType.INK_SACK.getID(), 1, (short) 4), (random.nextInt(5) + 4));
} // Lapis Lazuli ore break;
else if (type == BlockID.BED) { dropItem(pt, new BaseItemStack(ItemType.BED_ITEM.getID())); } // Bed
else if (type == BlockID.LONG_GRASS) { if (random.nextInt(8) == 0) dropItem(pt, new BaseItemStack(ItemType.SEEDS.getID())); } // Tall Grass case BlockID.BED:
else if (type == BlockID.PISTON_EXTENSION) { } // Piston Head dropItem(pt, new BaseItemStack(ItemType.BED_ITEM.getID()));
else if (type == BlockID.CLOTH) { dropItem(pt, new BaseItemStack(type, 1, (short) getBlockData(pt))); } // Cloth break;
else if (type == BlockID.DOUBLE_STEP) { // Double step
case BlockID.LONG_GRASS:
if (random.nextInt(8) == 0) dropItem(pt, new BaseItemStack(ItemType.SEEDS.getID()));
break;
case BlockID.CLOTH:
dropItem(pt, new BaseItemStack(type, 1, (short) getBlockData(pt)));
break;
case BlockID.DOUBLE_STEP:
dropItem(pt, new BaseItemStack(BlockID.STEP, 1, (short) getBlockData(pt)), 2); dropItem(pt, new BaseItemStack(BlockID.STEP, 1, (short) getBlockData(pt)), 2);
} break;
else if (type == BlockID.STEP) { dropItem(pt, new BaseItemStack(type, 1, (short) getBlockData(pt))); } // Step
else if (type == BlockID.BOOKCASE) { } // Bookshelves case BlockID.STEP:
else if (type == BlockID.FIRE) { } // Fire dropItem(pt, new BaseItemStack(type, 1, (short) getBlockData(pt)));
else if (type == BlockID.MOB_SPAWNER) { } // Mob spawner break;
else if (type == BlockID.WOODEN_STAIRS) { dropItem(pt, new BaseItemStack(BlockID.WOOD)); } // Wooden stairs
else if (type == BlockID.REDSTONE_WIRE) { dropItem(pt, new BaseItemStack(ItemType.REDSTONE_DUST.getID())); } // Redstone wire case BlockID.WOODEN_STAIRS:
else if (type == BlockID.DIAMOND_ORE) { dropItem(pt, new BaseItemStack(ItemType.DIAMOND.getID())); } // Diamond ore dropItem(pt, new BaseItemStack(BlockID.WOOD));
else if (type == BlockID.CROPS) { dropItem(pt, new BaseItemStack(ItemType.SEEDS.getID())); } // Crops break;
else if (type == BlockID.SOIL) { dropItem(pt, new BaseItemStack(BlockID.DIRT)); } // Soil
else if (type == BlockID.BURNING_FURNACE) { dropItem(pt, new BaseItemStack(BlockID.FURNACE)); } // Furnace case BlockID.REDSTONE_WIRE:
else if (type == BlockID.SIGN_POST) { dropItem(pt, new BaseItemStack(ItemType.SIGN.getID())); } // Sign post dropItem(pt, new BaseItemStack(ItemType.REDSTONE_DUST.getID()));
else if (type == BlockID.WOODEN_DOOR) { dropItem(pt, new BaseItemStack(ItemType.WOODEN_DOOR_ITEM.getID())); } // Wood door break;
else if (type == BlockID.COBBLESTONE_STAIRS) { dropItem(pt, new BaseItemStack(BlockID.COBBLESTONE)); } // Cobblestone stairs
else if (type == BlockID.WALL_SIGN) { dropItem(pt, new BaseItemStack(ItemType.SIGN.getID())); } // Wall sign case BlockID.DIAMOND_ORE:
else if (type == BlockID.IRON_DOOR) { dropItem(pt, new BaseItemStack(ItemType.IRON_DOOR_ITEM.getID())); } // Iron door dropItem(pt, new BaseItemStack(ItemType.DIAMOND.getID()));
else if (type == BlockID.REDSTONE_ORE) { dropItem(pt, new BaseItemStack(ItemType.REDSTONE_DUST.getID()), (random.nextInt(2) + 4)); } // Redstone ore break;
else if (type == BlockID.GLOWING_REDSTONE_ORE) { dropItem(pt, new BaseItemStack(ItemType.REDSTONE_DUST.getID()), (random.nextInt(2) + 4)); } // Glowing redstone ore
else if (type == BlockID.REDSTONE_TORCH_OFF) { dropItem(pt, new BaseItemStack(BlockID.REDSTONE_TORCH_ON)); } // Redstone torch case BlockID.CROPS:
else if (type == BlockID.SNOW) { } // Snow dropItem(pt, new BaseItemStack(ItemType.SEEDS.getID()));
else if (type == BlockID.ICE) { } // Ice break;
else if (type == BlockID.CLAY) { dropItem(pt, new BaseItemStack(ItemType.CLAY_BALL.getID()), 4); } // Clay
else if (type == BlockID.REED) { dropItem(pt, new BaseItemStack(ItemType.SUGAR_CANE_ITEM.getID())); } // Reed case BlockID.SOIL:
else if (type == BlockID.LIGHTSTONE) { dropItem(pt, new BaseItemStack(ItemType.LIGHTSTONE_DUST.getID()), (random.nextInt(3) + 2)); } // Lightstone dropItem(pt, new BaseItemStack(BlockID.DIRT));
else if (type == BlockID.PORTAL) { } // Portal break;
else if (type == BlockID.REDSTONE_REPEATER_OFF) { dropItem(pt, new BaseItemStack(ItemType.REDSTONE_REPEATER.getID())); } // Repeater
else if (type == BlockID.REDSTONE_REPEATER_ON) { dropItem(pt, new BaseItemStack(ItemType.REDSTONE_REPEATER.getID())); } // Repeater case BlockID.BURNING_FURNACE:
else if (type != BlockID.AIR) { dropItem(pt, new BaseItemStack(BlockID.FURNACE));
break;
case BlockID.SIGN_POST:
dropItem(pt, new BaseItemStack(ItemType.SIGN.getID()));
break;
case BlockID.WOODEN_DOOR:
dropItem(pt, new BaseItemStack(ItemType.WOODEN_DOOR_ITEM.getID()));
break;
case BlockID.COBBLESTONE_STAIRS:
dropItem(pt, new BaseItemStack(BlockID.COBBLESTONE));
break;
case BlockID.WALL_SIGN:
dropItem(pt, new BaseItemStack(ItemType.SIGN.getID()));
break;
case BlockID.IRON_DOOR:
dropItem(pt, new BaseItemStack(ItemType.IRON_DOOR_ITEM.getID()));
break;
case BlockID.REDSTONE_ORE:
case BlockID.GLOWING_REDSTONE_ORE:
dropItem(pt, new BaseItemStack(ItemType.REDSTONE_DUST.getID()), (random.nextInt(2) + 4));
break;
case BlockID.REDSTONE_TORCH_OFF:
dropItem(pt, new BaseItemStack(BlockID.REDSTONE_TORCH_ON));
break;
case BlockID.CLAY:
dropItem(pt, new BaseItemStack(ItemType.CLAY_BALL.getID()), 4);
break;
case BlockID.REED:
dropItem(pt, new BaseItemStack(ItemType.SUGAR_CANE_ITEM.getID()));
break;
case BlockID.LIGHTSTONE:
dropItem(pt, new BaseItemStack(ItemType.LIGHTSTONE_DUST.getID()), (random.nextInt(3) + 2));
break;
case BlockID.REDSTONE_REPEATER_OFF:
case BlockID.REDSTONE_REPEATER_ON:
dropItem(pt, new BaseItemStack(ItemType.REDSTONE_REPEATER.getID()));
break;
case BlockID.BEDROCK:
case BlockID.WATER:
case BlockID.STATIONARY_WATER:
case BlockID.LAVA:
case BlockID.STATIONARY_LAVA:
case BlockID.GLASS:
case BlockID.PISTON_EXTENSION:
case BlockID.BOOKCASE:
case BlockID.FIRE:
case BlockID.MOB_SPAWNER:
case BlockID.SNOW:
case BlockID.ICE:
case BlockID.PORTAL:
case BlockID.AIR:
break;
default:
dropItem(pt, new BaseItemStack(type)); dropItem(pt, new BaseItemStack(type));
break;
} }
} }

Datei anzeigen

@ -312,7 +312,8 @@ public class WorldEdit {
data = 0; data = 0;
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
if (blockType == BlockType.CLOTH) { switch (blockType) {
case CLOTH:
ClothColor col = ClothColor.lookup(args1[1]); ClothColor col = ClothColor.lookup(args1[1]);
if (col != null) { if (col != null) {
@ -320,26 +321,39 @@ public class WorldEdit {
} else { } else {
throw new InvalidItemException(arg, "Unknown cloth color '" + args1[1] + "'"); throw new InvalidItemException(arg, "Unknown cloth color '" + args1[1] + "'");
} }
} else if (blockType == BlockType.STEP break;
|| blockType == BlockType.DOUBLE_STEP) {
case STEP:
case DOUBLE_STEP:
BlockType dataType = BlockType.lookup(args1[1]); BlockType dataType = BlockType.lookup(args1[1]);
if (dataType != null) { if (dataType != null) {
if (dataType == BlockType.STONE) { switch (dataType) {
case STONE:
data = 0; data = 0;
} else if (dataType == BlockType.SANDSTONE) { break;
case SANDSTONE:
data = 1; data = 1;
} else if (dataType == BlockType.WOOD) { break;
case WOOD:
data = 2; data = 2;
} else if (dataType == BlockType.COBBLESTONE) { break;
case COBBLESTONE:
data = 3; data = 3;
} else { break;
default:
throw new InvalidItemException(arg, "Invalid step type '" + args1[1] + "'"); throw new InvalidItemException(arg, "Invalid step type '" + args1[1] + "'");
} }
} else { } else {
throw new InvalidItemException(arg, "Unknown step type '" + args1[1] + "'"); throw new InvalidItemException(arg, "Unknown step type '" + args1[1] + "'");
} }
} else { break;
default:
throw new InvalidItemException(arg, "Unknown data value '" + args1[1] + "'"); throw new InvalidItemException(arg, "Unknown data value '" + args1[1] + "'");
} }
} }
@ -731,41 +745,48 @@ public class WorldEdit {
*/ */
public Vector getDirection(LocalPlayer player, String dirStr) public Vector getDirection(LocalPlayer player, String dirStr)
throws UnknownDirectionException { throws UnknownDirectionException {
int xm = 0;
int ym = 0;
int zm = 0;
PlayerDirection dir = null;
dirStr = dirStr.toLowerCase(); dirStr = dirStr.toLowerCase();
boolean wasDetected = false;
if (dirStr.equals("me")) { if (dirStr.equals("me")) {
dir = player.getCardinalDirection(); final PlayerDirection dir = player.getCardinalDirection();
wasDetected = true; switch (dir) {
} case WEST:
case EAST:
case SOUTH:
case NORTH:
case UP:
case DOWN:
dirStr = dir.name().toLowerCase();
break;
if (dirStr.charAt(0) == 'w' || dir == PlayerDirection.WEST) { default:
zm += 1;
} else if (dirStr.charAt(0) == 'e' || dir == PlayerDirection.EAST) {
zm -= 1;
} else if (dirStr.charAt(0) == 's' || dir == PlayerDirection.SOUTH) {
xm += 1;
} else if (dirStr.charAt(0) == 'n' || dir == PlayerDirection.NORTH) {
xm -= 1;
} else if (dirStr.charAt(0) == 'u' || dir == PlayerDirection.UP) {
ym += 1;
} else if (dirStr.charAt(0) == 'd' || dir == PlayerDirection.DOWN) {
ym -= 1;
} else {
if (wasDetected) {
throw new UnknownDirectionException(dir.name()); throw new UnknownDirectionException(dir.name());
} else {
throw new UnknownDirectionException(dirStr);
} }
} }
return new Vector(xm, ym, zm); switch (dirStr.charAt(0)) {
case 'w':
return new Vector(0, 0, 1);
case 'e':
return new Vector(0, 0, -1);
case 's':
return new Vector(1, 0, 0);
case 'n':
return new Vector(-1, 0, 0);
case 'u':
return new Vector(0, 1, 0);
case 'd':
return new Vector(0, -1, 0);
default:
throw new UnknownDirectionException(dirStr);
}
} }
/** /**
@ -779,53 +800,51 @@ public class WorldEdit {
*/ */
public Vector getDiagonalDirection( LocalPlayer player, String dirStr ) public Vector getDiagonalDirection( LocalPlayer player, String dirStr )
throws UnknownDirectionException { throws UnknownDirectionException {
int xm = 0;
int ym = 0;
int zm = 0;
PlayerDirection dir = null;
dirStr = dirStr.toLowerCase(); dirStr = dirStr.toLowerCase();
boolean wasDetected = false;
if ( dirStr.equals( "me" ) ) { if (dirStr.equals("me")) {
dir = player.getCardinalDirection(); dirStr = player.getCardinalDirection().name().toLowerCase();
wasDetected = true;
} }
if ((dirStr.charAt(0) == 's' && dirStr.indexOf( 'w' ) > 0) || dir == PlayerDirection.SOUTH_WEST) { switch (dirStr.charAt(0)) {
zm += 1; case 'w':
xm += 1; return new Vector(0, 0, 1);
} else if ((dirStr.charAt(0) == 'n' && dirStr.indexOf( 'w' ) > 0) || dir == PlayerDirection.NORTH_WEST) {
zm += 1; case 'e':
xm -= 1; return new Vector(0, 0, -1);
} else if ((dirStr.charAt(0) == 's' && dirStr.indexOf( 'e' ) > 0) || dir == PlayerDirection.SOUTH_EAST) {
zm -= 1; case 's':
xm += 1; if (dirStr.indexOf('w') > 0) {
} else if ((dirStr.charAt(0) == 'n' && dirStr.indexOf( 'e' ) > 0) || dir == PlayerDirection.NORTH_EAST) { return new Vector(1, 0, 1);
zm -= 1;
xm -= 1;
} else if (dirStr.charAt(0) == 'w' || dir == PlayerDirection.WEST) {
zm += 1;
} else if (dirStr.charAt(0) == 'e' || dir == PlayerDirection.EAST) {
zm -= 1;
} else if (dirStr.charAt(0) == 's' || dir == PlayerDirection.SOUTH) {
xm += 1;
} else if (dirStr.charAt(0) == 'n' || dir == PlayerDirection.NORTH) {
xm -= 1;
} else if (dirStr.charAt(0) == 'u' || dir == PlayerDirection.UP) {
ym += 1;
} else if (dirStr.charAt(0) == 'd' || dir == PlayerDirection.DOWN) {
ym -= 1;
} else {
if (wasDetected) {
throw new UnknownDirectionException(dir.name());
} else {
throw new UnknownDirectionException(dirStr);
} }
}
return new Vector( xm, ym, zm ); if (dirStr.indexOf('e') > 0) {
return new Vector(1, 0, -1);
}
return new Vector(1, 0, 0);
case 'n':
if (dirStr.indexOf('w') > 0) {
return new Vector(-1, 0, 1);
}
if (dirStr.indexOf('e') > 0) {
return new Vector(-1, 0, -1);
}
return new Vector(-1, 0, 0);
case 'u':
return new Vector(0, 1, 0);
case 'd':
return new Vector(0, -1, 0);
default:
throw new UnknownDirectionException(dirStr);
}
} }
/** /**

Datei anzeigen

@ -50,52 +50,59 @@ public abstract class BlockBag {
public void fetchPlacedBlock(int id) throws BlockBagException { public void fetchPlacedBlock(int id) throws BlockBagException {
try { try {
// Blocks that can't be fetched... // Blocks that can't be fetched...
if (id == BlockID.BEDROCK switch (id) {
|| id == BlockID.GOLD_ORE case BlockID.BEDROCK:
|| id == BlockID.IRON_ORE case BlockID.GOLD_ORE:
|| id == BlockID.COAL_ORE case BlockID.IRON_ORE:
|| id == BlockID.DIAMOND_ORE case BlockID.COAL_ORE:
|| id == BlockID.LEAVES case BlockID.DIAMOND_ORE:
|| id == BlockID.TNT case BlockID.LEAVES:
|| id == BlockID.MOB_SPAWNER case BlockID.TNT:
|| id == BlockID.CROPS case BlockID.MOB_SPAWNER:
|| id == BlockID.REDSTONE_ORE case BlockID.CROPS:
|| id == BlockID.GLOWING_REDSTONE_ORE case BlockID.REDSTONE_ORE:
|| id == BlockID.SNOW case BlockID.GLOWING_REDSTONE_ORE:
|| id == BlockID.LIGHTSTONE case BlockID.SNOW:
|| id == BlockID.PORTAL) { case BlockID.LIGHTSTONE:
case BlockID.PORTAL:
throw new UnplaceableBlockException(); throw new UnplaceableBlockException();
}
// Override liquids case BlockID.WATER:
if (id == BlockID.WATER case BlockID.STATIONARY_WATER:
|| id == BlockID.STATIONARY_WATER case BlockID.LAVA:
|| id == BlockID.LAVA case BlockID.STATIONARY_LAVA:
|| id == BlockID.STATIONARY_LAVA) { // Override liquids
return; return;
default:
fetchBlock(id);
break;
} }
fetchBlock(id);
} catch (OutOfBlocksException e) { } catch (OutOfBlocksException e) {
// Look for cobblestone switch (id) {
if (id == BlockID.STONE) { case BlockID.STONE:
fetchBlock(BlockID.COBBLESTONE); fetchBlock(BlockID.COBBLESTONE);
// Look for dirt break;
} else if (id == BlockID.GRASS) {
case BlockID.GRASS:
fetchBlock(BlockID.DIRT); fetchBlock(BlockID.DIRT);
// Look for redstone dust break;
} else if (id == BlockID.REDSTONE_WIRE) {
case BlockID.REDSTONE_WIRE:
fetchBlock(ItemType.REDSTONE_DUST.getID()); fetchBlock(ItemType.REDSTONE_DUST.getID());
// Look for furnace break;
} else if (id == BlockID.BURNING_FURNACE) {
fetchBlock(BlockID.FURNACE); case BlockID.REDSTONE_TORCH_OFF:
// Look for lit redstone torch
} else if (id == BlockID.REDSTONE_TORCH_OFF) {
fetchBlock(BlockID.REDSTONE_TORCH_ON); fetchBlock(BlockID.REDSTONE_TORCH_ON);
// Look for signs break;
} else if (id == BlockID.WALL_SIGN || id == BlockID.SIGN_POST) {
case BlockID.WALL_SIGN:
case BlockID.SIGN_POST:
fetchBlock(ItemType.SIGN.getID()); fetchBlock(ItemType.SIGN.getID());
} else { break;
default:
throw e; throw e;
} }
} }