Abstracted type detection of simulateBlockMine into BlockType.

Dieser Commit ist enthalten in:
zml2008 2011-09-17 21:52:12 -07:00
Ursprung a1cf6eb6da
Commit 3f369f104a
3 geänderte Dateien mit 126 neuen und 149 gelöschten Zeilen

Datei anzeigen

@ -1012,7 +1012,7 @@ public class EditSession {
BaseBlock curBlockType = getBlock(pt); BaseBlock curBlockType = getBlock(pt);
if ((fromBlockTypes == null && !curBlockType.isAir()) if ((fromBlockTypes == null && !curBlockType.isAir())
|| (fromBlockTypes != null && curBlockType.inIterable(fromBlockTypes))) { || (fromBlockTypes != null && curBlockType.inIterable(fromBlockTypes))) { // Probably faster if someone adds a proper hashCode to BaseBlock
if (setBlock(pt, toBlock)) { if (setBlock(pt, toBlock)) {
++affected; ++affected;
} }
@ -1068,7 +1068,7 @@ public class EditSession {
BaseBlock curBlockType = getBlock(pt); BaseBlock curBlockType = getBlock(pt);
if ((fromBlockTypes == null && !curBlockType.isAir()) if ((fromBlockTypes == null && !curBlockType.isAir())
|| (fromBlockTypes != null && curBlockType.inIterable(fromBlockTypes))) { || (fromBlockTypes != null && curBlockType.inIterable(fromBlockTypes))) { // Probably faster if someone adds a proper hashCode to BaseBlock
if (setBlock(pt, pattern.next(pt))) { if (setBlock(pt, pattern.next(pt))) {
++affected; ++affected;
} }

Datei anzeigen

@ -249,154 +249,11 @@ public abstract class LocalWorld {
* @param pt * @param pt
*/ */
public void simulateBlockMine(Vector pt) { public void simulateBlockMine(Vector pt) {
int type = getBlockType(pt); BaseItemStack stack = BlockType.getBlockDrop(getBlockType(pt), (short) getBlockData(pt));
//setBlockType(pt, 0); if (stack != null) dropItem(pt,
stack.getAmount() > 1 ? new BaseItemStack(stack.getType(),
1, stack.getDamage()) : stack, stack.getAmount());
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));
}
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)));
}
break;
case BlockID.LAPIS_LAZULI_ORE:
dropItem(pt, new BaseItemStack(ItemType.INK_SACK.getID(), 1, (short) 4), (random.nextInt(5) + 4));
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);
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

@ -24,9 +24,11 @@ import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Random;
import java.util.Set; import java.util.Set;
import com.sk89q.util.StringUtil; import com.sk89q.util.StringUtil;
import org.omg.CORBA.PRIVATE_MEMBER;
/** /**
* Block types. * Block types.
@ -727,6 +729,7 @@ public enum BlockType {
* @param id * @param id
* @return * @return
*/ */
@Deprecated
public static int getDroppedBlock(int id) { public static int getDroppedBlock(int id) {
Integer dropped = blockDrops.get(id); Integer dropped = blockDrops.get(id);
if (dropped == null) { if (dropped == null) {
@ -735,4 +738,121 @@ public enum BlockType {
return dropped; return dropped;
} }
private static final Random random = new Random();
public static BaseItemStack getBlockDrop(int id, short data) {
switch (id) {
case BlockID.STONE:
return new BaseItemStack(BlockID.COBBLESTONE);
case BlockID.GRASS:
return new BaseItemStack(BlockID.DIRT);
case BlockID.GRAVEL:
if (random.nextDouble() >= 0.9) {
return new BaseItemStack(ItemType.FLINT.getID());
} else {
return new BaseItemStack(id);
}
case BlockID.COAL_ORE:
return new BaseItemStack(ItemType.COAL.getID());
case BlockID.LOG:
return new BaseItemStack(id, 1, data);
case BlockID.LEAVES:
if (random.nextDouble() > 0.95) {
return new BaseItemStack(BlockID.SAPLING, 1, data);
}
case BlockID.LAPIS_LAZULI_ORE:
return new BaseItemStack(ItemType.INK_SACK.getID(), random.nextInt(5) + 4, (short) 4);
case BlockID.BED:
return new BaseItemStack(ItemType.BED_ITEM.getID());
case BlockID.LONG_GRASS:
if (random.nextInt(8) == 0) return new BaseItemStack(ItemType.SEEDS.getID());
case BlockID.CLOTH:
return new BaseItemStack(id, 1, data);
case BlockID.DOUBLE_STEP:
return new BaseItemStack(BlockID.STEP, 2, data);
case BlockID.STEP:
return new BaseItemStack(id, 1, data);
case BlockID.WOODEN_STAIRS:
return new BaseItemStack(BlockID.WOOD);
case BlockID.REDSTONE_WIRE:
return new BaseItemStack(ItemType.REDSTONE_DUST.getID());
case BlockID.DIAMOND_ORE:
return new BaseItemStack(ItemType.DIAMOND.getID());
case BlockID.CROPS:
return new BaseItemStack(ItemType.SEEDS.getID());
case BlockID.SOIL:
return new BaseItemStack(BlockID.DIRT);
case BlockID.BURNING_FURNACE:
return new BaseItemStack(BlockID.FURNACE);
case BlockID.SIGN_POST:
return new BaseItemStack(ItemType.SIGN.getID());
case BlockID.WOODEN_DOOR:
return new BaseItemStack(ItemType.WOODEN_DOOR_ITEM.getID());
case BlockID.COBBLESTONE_STAIRS:
return new BaseItemStack(BlockID.COBBLESTONE);
case BlockID.WALL_SIGN:
return new BaseItemStack(ItemType.SIGN.getID());
case BlockID.IRON_DOOR:
return new BaseItemStack(ItemType.IRON_DOOR_ITEM.getID());
case BlockID.REDSTONE_ORE:
case BlockID.GLOWING_REDSTONE_ORE:
return new BaseItemStack(ItemType.REDSTONE_DUST.getID(), (random.nextInt(2) + 4));
case BlockID.REDSTONE_TORCH_OFF:
return new BaseItemStack(BlockID.REDSTONE_TORCH_ON);
case BlockID.CLAY:
return new BaseItemStack(ItemType.CLAY_BALL.getID(), 4);
case BlockID.REED:
return new BaseItemStack(ItemType.SUGAR_CANE_ITEM.getID());
case BlockID.LIGHTSTONE:
return new BaseItemStack(ItemType.LIGHTSTONE_DUST.getID(), (random.nextInt(3) + 2));
case BlockID.REDSTONE_REPEATER_OFF:
case BlockID.REDSTONE_REPEATER_ON:
return new BaseItemStack(ItemType.REDSTONE_REPEATER.getID());
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:
return null;
}
return new BaseItemStack(id);
}
} }