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);
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]);
} else if (blocks[index] == BlockID.CHEST) {
break;
case BlockID.CHEST:
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]);
} else if (blocks[index] == BlockID.DISPENSER) {
break;
case BlockID.DISPENSER:
block = new DispenserBlock(blockData[index]);
} else if (blocks[index] == BlockID.MOB_SPAWNER) {
break;
case BlockID.MOB_SPAWNER:
block = new MobSpawnerBlock(blockData[index]);
} else if (blocks[index] == BlockID.NOTE_BLOCK) {
break;
case BlockID.NOTE_BLOCK:
block = new NoteBlock(blockData[index]);
} else {
break;
default:
block = new BaseBlock(blocks[index], blockData[index]);
break;
}
if (block instanceof TileEntityBlock

Datei anzeigen

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

Datei anzeigen

@ -251,66 +251,150 @@ public abstract class LocalWorld {
int type = getBlockType(pt);
//setBlockType(pt, 0);
if (type == BlockID.STONE) { dropItem(pt, new BaseItemStack(BlockID.COBBLESTONE)); } // Stone
else if (type == BlockID.GRASS) { dropItem(pt, new BaseItemStack(BlockID.DIRT)); } // Grass
else if (type == BlockID.BEDROCK) { } // Bedrock
else if (type == BlockID.WATER) { } // Water
else if (type == BlockID.STATIONARY_WATER) { } // Water
else if (type == BlockID.LAVA) { } // Lava
else if (type == BlockID.STATIONARY_LAVA) { } // Lava
else if (type == BlockID.GRAVEL) { // Gravel
switch (type) {
case BlockID.STONE:
dropItem(pt, new BaseItemStack(BlockID.COBBLESTONE));
break;
case BlockID.GRASS:
dropItem(pt, new BaseItemStack(BlockID.DIRT));
break;
case BlockID.GRAVEL:
if (random.nextDouble() >= 0.9) {
dropItem(pt, new BaseItemStack(ItemType.FLINT.getID()));
} else {
dropItem(pt, new BaseItemStack(type));
}
}
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
else if (type == BlockID.LEAVES) { // Leaves
break;
case BlockID.COAL_ORE:
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) {
dropItem(pt, new BaseItemStack(BlockID.SAPLING, 1, (short) getBlockData(pt)));
}
}
else if (type == BlockID.GLASS) { } // Glass
else if (type == BlockID.LAPIS_LAZULI_ORE) {
break;
case BlockID.LAPIS_LAZULI_ORE:
dropItem(pt, new BaseItemStack(ItemType.INK_SACK.getID(), 1, (short) 4), (random.nextInt(5) + 4));
} // Lapis Lazuli ore
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
else if (type == BlockID.PISTON_EXTENSION) { } // Piston Head
else if (type == BlockID.CLOTH) { dropItem(pt, new BaseItemStack(type, 1, (short) getBlockData(pt))); } // Cloth
else if (type == BlockID.DOUBLE_STEP) { // Double step
break;
case BlockID.BED:
dropItem(pt, new BaseItemStack(ItemType.BED_ITEM.getID()));
break;
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);
}
else if (type == BlockID.STEP) { dropItem(pt, new BaseItemStack(type, 1, (short) getBlockData(pt))); } // Step
else if (type == BlockID.BOOKCASE) { } // Bookshelves
else if (type == BlockID.FIRE) { } // Fire
else if (type == BlockID.MOB_SPAWNER) { } // Mob spawner
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
else if (type == BlockID.DIAMOND_ORE) { dropItem(pt, new BaseItemStack(ItemType.DIAMOND.getID())); } // Diamond ore
else if (type == BlockID.CROPS) { dropItem(pt, new BaseItemStack(ItemType.SEEDS.getID())); } // Crops
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
else if (type == BlockID.SIGN_POST) { dropItem(pt, new BaseItemStack(ItemType.SIGN.getID())); } // Sign post
else if (type == BlockID.WOODEN_DOOR) { dropItem(pt, new BaseItemStack(ItemType.WOODEN_DOOR_ITEM.getID())); } // Wood door
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
else if (type == BlockID.IRON_DOOR) { dropItem(pt, new BaseItemStack(ItemType.IRON_DOOR_ITEM.getID())); } // Iron door
else if (type == BlockID.REDSTONE_ORE) { dropItem(pt, new BaseItemStack(ItemType.REDSTONE_DUST.getID()), (random.nextInt(2) + 4)); } // Redstone ore
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
else if (type == BlockID.SNOW) { } // Snow
else if (type == BlockID.ICE) { } // Ice
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
else if (type == BlockID.LIGHTSTONE) { dropItem(pt, new BaseItemStack(ItemType.LIGHTSTONE_DUST.getID()), (random.nextInt(3) + 2)); } // Lightstone
else if (type == BlockID.PORTAL) { } // Portal
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
else if (type != BlockID.AIR) {
break;
case BlockID.STEP:
dropItem(pt, new BaseItemStack(type, 1, (short) getBlockData(pt)));
break;
case BlockID.WOODEN_STAIRS:
dropItem(pt, new BaseItemStack(BlockID.WOOD));
break;
case BlockID.REDSTONE_WIRE:
dropItem(pt, new BaseItemStack(ItemType.REDSTONE_DUST.getID()));
break;
case BlockID.DIAMOND_ORE:
dropItem(pt, new BaseItemStack(ItemType.DIAMOND.getID()));
break;
case BlockID.CROPS:
dropItem(pt, new BaseItemStack(ItemType.SEEDS.getID()));
break;
case BlockID.SOIL:
dropItem(pt, new BaseItemStack(BlockID.DIRT));
break;
case BlockID.BURNING_FURNACE:
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));
break;
}
}

Datei anzeigen

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

Datei anzeigen

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