This commit is contained in:
TomyLobo
2011-11-23 02:29:48 +01:00
parent 1a57f6e95d
commit 7e13b60a51
161 changed files with 1433 additions and 1412 deletions

View File

@ -30,7 +30,7 @@ import com.sk89q.util.StringUtil;
public class FileDialogUtil {
public static File showSaveDialog(String[] exts) {
JFileChooser dialog = new JFileChooser();
if (exts != null) {
dialog.setFileFilter(new ExtensionFilter(exts));
}
@ -40,13 +40,13 @@ public class FileDialogUtil {
if (returnVal == JFileChooser.APPROVE_OPTION) {
return dialog.getSelectedFile();
}
return null;
}
public static File showOpenDialog(String[] exts) {
JFileChooser dialog = new JFileChooser();
if (exts != null) {
dialog.setFileFilter(new ExtensionFilter(exts));
}
@ -56,20 +56,20 @@ public class FileDialogUtil {
if (returnVal == JFileChooser.APPROVE_OPTION) {
return dialog.getSelectedFile();
}
return null;
}
private static class ExtensionFilter extends FileFilter {
private Set<String> exts;
private String desc;
public ExtensionFilter(String[] exts) {
this.exts = new HashSet<String>(Arrays.asList(exts));
desc = StringUtil.joinString(exts, ",");
}
@Override
public boolean accept(File f) {
if (f.isDirectory()) {

View File

@ -92,7 +92,7 @@ public class TargetBlock {
yRotation = yRotation * -1;
double h = (checkDistance * Math.cos(Math.toRadians(yRotation)));
offset = new Vector((h * Math.cos(Math.toRadians(xRotation))),
(checkDistance * Math.sin(Math.toRadians(yRotation))),
(h * Math.sin(Math.toRadians(xRotation))));
@ -113,7 +113,7 @@ public class TargetBlock {
BlockWorldVector lastBlock = null;
while (getNextBlock() != null) {
if (world.getBlockType(getCurrentBlock()) == BlockID.AIR) {
if(searchForLastBlock) {
if (searchForLastBlock) {
lastBlock = getCurrentBlock();
if (lastBlock.getBlockY() <= 0 || lastBlock.getBlockY() >= 127) {
searchForLastBlock = false;
@ -126,7 +126,7 @@ public class TargetBlock {
BlockWorldVector currentBlock = getCurrentBlock();
return (currentBlock != null ? currentBlock : lastBlock);
}
/**
* Returns the block at the sight. Returns null if out of range or if no
* viable target was found
@ -134,8 +134,7 @@ public class TargetBlock {
* @return Block
*/
public BlockWorldVector getTargetBlock() {
while ((getNextBlock() != null)
&& (world.getBlockType(getCurrentBlock()) == 0));
while (getNextBlock() != null && world.getBlockType(getCurrentBlock()) == 0) ;
return getCurrentBlock();
}
@ -146,8 +145,7 @@ public class TargetBlock {
* @return Block
*/
public BlockWorldVector getSolidTargetBlock() {
while ((getNextBlock() != null)
&& BlockType.canPassThrough(world.getBlockType(getCurrentBlock())));
while (getNextBlock() != null && BlockType.canPassThrough(world.getBlockType(getCurrentBlock()))) ;
return getCurrentBlock();
}
@ -160,7 +158,7 @@ public class TargetBlock {
prevPos = targetPos;
do {
curDistance += checkDistance;
targetPosDouble = offset.add(targetPosDouble.getX(),
targetPosDouble.getY(),
targetPosDouble.getZ());
@ -169,7 +167,7 @@ public class TargetBlock {
&& targetPos.getBlockX() == prevPos.getBlockX()
&& targetPos.getBlockY() == prevPos.getBlockY()
&& targetPos.getBlockZ() == prevPos.getBlockZ());
if (curDistance > maxDistance) {
return null;
}
@ -208,4 +206,4 @@ public class TargetBlock {
getAnyTargetBlock();
return WorldVectorFace.getWorldVectorFace(world, getCurrentBlock(), getPreviousBlock());
}
}
}

View File

@ -37,19 +37,19 @@ import com.sk89q.worldedit.blocks.BlockID;
*/
public class TreeGenerator {
public enum TreeType {
TREE("Regular tree", new String[] {"tree", "regular"}),
BIG_TREE("Big tree", new String[] {"big", "bigtree"}),
REDWOOD("Redwood", new String[] {"redwood", "sequoia", "sequoioideae"}),
TALL_REDWOOD("Tall redwood", new String[] {"tallredwood", "tallsequoia", "tallsequoioideae"}),
BIRCH("Birch", new String[] {"birch", "white", "whitebark"}),
PINE("Pine", new String[] {"pine"}),
RANDOM_REDWOOD("Random redwood", new String[] {"randredwood", "randomredwood", "anyredwood"}),
RANDOM("Random", new String[] {"rand", "random"});
TREE("Regular tree", new String[] { "tree", "regular" }),
BIG_TREE("Big tree", new String[] { "big", "bigtree" }),
REDWOOD("Redwood", new String[] { "redwood", "sequoia", "sequoioideae" }),
TALL_REDWOOD("Tall redwood", new String[] { "tallredwood", "tallsequoia", "tallsequoioideae" }),
BIRCH("Birch", new String[] { "birch", "white", "whitebark" }),
PINE("Pine", new String[] { "pine" }),
RANDOM_REDWOOD("Random redwood", new String[] { "randredwood", "randomredwood", "anyredwood" }),
RANDOM("Random", new String[] { "rand", "random" });
/**
* Stores a map of the names for fast access.
*/
private static final Map<String,TreeType> lookup = new HashMap<String,TreeType>();
private static final Map<String, TreeType> lookup = new HashMap<String, TreeType>();
private final String name;
private final String[] lookupKeys;
@ -61,17 +61,17 @@ public class TreeGenerator {
}
}
}
TreeType(String name, String lookupKey) {
this.name = name;
this.lookupKeys = new String[]{ lookupKey };
this.lookupKeys = new String[] { lookupKey };
}
TreeType(String name, String[] lookupKeys) {
this.name = name;
this.lookupKeys = lookupKeys;
}
/**
* Get user-friendly tree type name.
*
@ -80,7 +80,7 @@ public class TreeGenerator {
public String getName() {
return name;
}
/**
* Return type from name. May return null.
*
@ -91,11 +91,11 @@ public class TreeGenerator {
return lookup.get(name.toLowerCase());
}
};
private static Random rand = new Random();
private TreeType type;
/**
* Construct the tree generator with a tree type.
*
@ -104,7 +104,7 @@ public class TreeGenerator {
public TreeGenerator(TreeType type) {
this.type = type;
}
/**
* Generate a tree.
*
@ -117,7 +117,7 @@ public class TreeGenerator {
throws MaxChangedBlocksException {
return generate(type, editSession, pos);
}
/**
* Generate a tree.
*
@ -130,41 +130,41 @@ public class TreeGenerator {
private boolean generate(TreeType type, EditSession editSession, Vector pos)
throws MaxChangedBlocksException {
LocalWorld world = editSession.getWorld();
TreeType[] choices;
TreeType realType;
switch (type) {
case TREE:
return world.generateTree(editSession, pos);
case BIG_TREE:
return world.generateBigTree(editSession, pos);
case BIRCH:
return world.generateBirchTree(editSession, pos);
case REDWOOD:
return world.generateRedwoodTree(editSession, pos);
case TALL_REDWOOD:
return world.generateTallRedwoodTree(editSession, pos);
case PINE:
makePineTree(editSession, pos);
return true;
case RANDOM_REDWOOD:
choices =
case TREE:
return world.generateTree(editSession, pos);
case BIG_TREE:
return world.generateBigTree(editSession, pos);
case BIRCH:
return world.generateBirchTree(editSession, pos);
case REDWOOD:
return world.generateRedwoodTree(editSession, pos);
case TALL_REDWOOD:
return world.generateTallRedwoodTree(editSession, pos);
case PINE:
makePineTree(editSession, pos);
return true;
case RANDOM_REDWOOD:
choices =
new TreeType[] {
TreeType.REDWOOD, TreeType.TALL_REDWOOD
TreeType.REDWOOD, TreeType.TALL_REDWOOD
};
realType = choices[rand.nextInt(choices.length)];
return generate(realType, editSession, pos);
case RANDOM:
choices =
realType = choices[rand.nextInt(choices.length)];
return generate(realType, editSession, pos);
case RANDOM:
choices =
new TreeType[] {
TreeType.TREE, TreeType.BIG_TREE, TreeType.BIRCH,
TreeType.REDWOOD, TreeType.TALL_REDWOOD, TreeType.PINE
TreeType.TREE, TreeType.BIG_TREE, TreeType.BIRCH,
TreeType.REDWOOD, TreeType.TALL_REDWOOD, TreeType.PINE
};
realType = choices[rand.nextInt(choices.length)];
return generate(realType, editSession, pos);
realType = choices[rand.nextInt(choices.length)];
return generate(realType, editSession, pos);
}
return false;
}
@ -226,7 +226,7 @@ public class TreeGenerator {
editSession.setBlockIfAir(basePos.add(0, height, 0), leavesBlock);
}
/**
* Looks up a tree type. May return null if a tree type by that
* name is not found.