Cleanup. Cycler uses BaseBlock instead of BlockData directly. Fixed a few BlockType method inaccuracies.

This commit is contained in:
Wizjany 2011-10-04 17:13:41 -04:00
parent 9e877740aa
commit 68fe0d3438
4 changed files with 50 additions and 27 deletions

View File

@ -90,21 +90,37 @@ public class BaseBlock {
* @return if air
*/
public boolean isAir() {
return type == 0;
return type == BlockID.AIR;
}
/**
* Rotate this block 90 degrees.
*/
public void rotate90() {
data = (byte) BlockData.rotate90(type, data);
public int rotate90() {
int newData = BlockData.rotate90(type, data);
this.data = (byte) newData;
return data;
}
/**
* Rotate this block -90 degrees.
*/
public void rotate90Reverse() {
data = (byte) BlockData.rotate90Reverse(type, data);
public int rotate90Reverse() {
int newData = BlockData.rotate90Reverse(type, data);
this.data = (byte) newData;
return newData;
}
/**
* Cycle the damage value of the block forward or backward
*
* @param increment 1 for forward, -1 for backward
* @return new data value
*/
public int cycleData(int increment) {
int newData = BlockData.cycle(this.type, this.data, increment);
this.data = (byte) newData;
return newData;
}
/**

View File

@ -110,6 +110,7 @@ public final class BlockData {
case BlockID.LADDER:
case BlockID.WALL_SIGN:
case BlockID.CHEST:
case BlockID.FURNACE:
case BlockID.BURNING_FURNACE:
case BlockID.DISPENSER:
@ -268,6 +269,7 @@ public final class BlockData {
case BlockID.LADDER:
case BlockID.WALL_SIGN:
case BlockID.CHEST:
case BlockID.FURNACE:
case BlockID.BURNING_FURNACE:
case BlockID.DISPENSER:
@ -453,6 +455,7 @@ public final class BlockData {
case BlockID.LADDER:
case BlockID.WALL_SIGN:
case BlockID.CHEST:
case BlockID.FURNACE:
case BlockID.BURNING_FURNACE:
case BlockID.DISPENSER:

View File

@ -397,7 +397,6 @@ public enum BlockType {
usesData.add(BlockID.LOG);
usesData.add(BlockID.LEAVES);
usesData.add(BlockID.DISPENSER);
usesData.add(BlockID.NOTE_BLOCK);
usesData.add(BlockID.BED);
usesData.add(BlockID.POWERED_RAIL);
usesData.add(BlockID.DETECTOR_RAIL);
@ -409,7 +408,9 @@ public enum BlockType {
usesData.add(BlockID.DOUBLE_STEP);
usesData.add(BlockID.STEP);
usesData.add(BlockID.TORCH);
usesData.add(BlockID.FIRE);
usesData.add(BlockID.WOODEN_STAIRS);
usesData.add(BlockID.CHEST);
usesData.add(BlockID.REDSTONE_WIRE);
usesData.add(BlockID.CROPS);
usesData.add(BlockID.SOIL);
@ -430,6 +431,8 @@ public enum BlockType {
usesData.add(BlockID.STONE_BUTTON);
usesData.add(BlockID.SNOW);
usesData.add(BlockID.CACTUS);
usesData.add(BlockID.REED);
usesData.add(BlockID.JUKEBOX);
usesData.add(BlockID.PUMPKIN);
usesData.add(BlockID.JACKOLANTERN);
usesData.add(BlockID.CAKE_BLOCK);

View File

@ -20,7 +20,7 @@
package com.sk89q.worldedit.tools;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BlockData;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* A mode that cycles the data values of supported blocks.
@ -49,12 +49,13 @@ public class BlockDataCyler implements DoubleActionBlockTool {
}
int increment = forward ? 1 : -1;
data = BlockData.cycle(type, data, increment);
data = (new BaseBlock(type, data)).cycleData(increment);
if (data < 0) {
player.printError("That block's data cannot be cycled!");
return true;
}
} else {
world.setBlockData(clicked, data);
}
return true;
}