mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-13 14:58:35 +00:00
Setup a legacy mapper system. The file does not exist yet.
This commit is contained in:
@ -27,7 +27,7 @@ import com.sk89q.worldedit.blocks.type.BlockStateHolder;
|
||||
import com.sk89q.worldedit.blocks.type.BlockType;
|
||||
import com.sk89q.worldedit.blocks.type.BlockTypes;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.world.registry.BundledBlockData;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
import com.sk89q.worldedit.world.registry.state.State;
|
||||
import com.sk89q.worldedit.world.registry.state.value.StateValue;
|
||||
|
||||
@ -52,9 +52,6 @@ import javax.annotation.Nullable;
|
||||
*/
|
||||
public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
|
||||
|
||||
// Instances of this class should be _as small as possible_ because there will
|
||||
// be millions of instances of this object.
|
||||
|
||||
private BlockState blockState;
|
||||
@Nullable
|
||||
private CompoundTag nbtData;
|
||||
@ -67,10 +64,12 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
|
||||
@Deprecated
|
||||
public BaseBlock(int id) {
|
||||
try {
|
||||
this.blockState = BlockTypes.getBlockType(BundledBlockData.getInstance().fromLegacyId(id)).getDefaultState();
|
||||
this.blockState = LegacyMapper.getInstance().getBlockFromLegacy(id);
|
||||
if (this.blockState == null) {
|
||||
this.blockState = BlockTypes.AIR.getDefaultState();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println(id);
|
||||
System.out.println(BundledBlockData.getInstance().fromLegacyId(id));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -134,16 +133,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
|
||||
* @param other the other block
|
||||
*/
|
||||
public BaseBlock(BaseBlock other) {
|
||||
this(other.getState(), other.getNbtData());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the block state
|
||||
*
|
||||
* @return The block state
|
||||
*/
|
||||
public BlockState getState() {
|
||||
return this.blockState;
|
||||
this(other.toImmutableState(), other.getNbtData());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -240,7 +230,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
|
||||
|
||||
final BaseBlock otherBlock = (BaseBlock) o;
|
||||
|
||||
return this.getState().equals(otherBlock.getState()) && Objects.equals(getNbtData(), otherBlock.getNbtData());
|
||||
return this.toImmutableState().equals(otherBlock.toImmutableState()) && Objects.equals(getNbtData(), otherBlock.getNbtData());
|
||||
|
||||
}
|
||||
|
||||
@ -252,12 +242,17 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
|
||||
*/
|
||||
@Override
|
||||
public boolean equalsFuzzy(BlockStateHolder o) {
|
||||
return this.getState().equalsFuzzy(o);
|
||||
return this.toImmutableState().equalsFuzzy(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState toImmutableState() {
|
||||
return this.blockState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int ret = getState().hashCode() << 3;
|
||||
int ret = toImmutableState().hashCode() << 3;
|
||||
if (hasNbtData()) {
|
||||
ret += getNbtData().hashCode();
|
||||
}
|
||||
@ -266,7 +261,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Block{State: " + this.getState().toString() + ", NBT: " + String.valueOf(getNbtData()) + "}";
|
||||
return "Block{State: " + this.toImmutableState().toString() + ", NBT: " + String.valueOf(getNbtData()) + "}";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.blocks.type.ItemType;
|
||||
import com.sk89q.worldedit.blocks.type.ItemTypes;
|
||||
import com.sk89q.worldedit.world.NbtValued;
|
||||
import com.sk89q.worldedit.world.registry.BundledItemData;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@ -46,7 +46,11 @@ public class BaseItem implements NbtValued {
|
||||
*/
|
||||
@Deprecated
|
||||
public BaseItem(int id) {
|
||||
this(ItemTypes.getItemType(BundledItemData.getInstance().fromLegacyId(id)));
|
||||
ItemType type = LegacyMapper.getInstance().getItemFromLegacy(id);
|
||||
if (type == null) {
|
||||
type = ItemTypes.AIR;
|
||||
}
|
||||
this.itemType = type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -855,246 +855,188 @@ public final class BlockData {
|
||||
* @return the new data value for the block
|
||||
*/
|
||||
public static int cycle(int type, int data, int increment) {
|
||||
if (increment != -1 && increment != 1) {
|
||||
throw new IllegalArgumentException("Increment must be 1 or -1.");
|
||||
}
|
||||
|
||||
int store;
|
||||
switch (type) {
|
||||
|
||||
// special case here, going to use "forward" for type and "backward" for orientation
|
||||
case BlockID.LOG:
|
||||
case BlockID.LOG2:
|
||||
if (increment == -1) {
|
||||
store = data & 0x3; // copy bottom (type) bits
|
||||
return mod((data & ~0x3) + 4, 16) | store; // switch orientation with top bits and reapply bottom bits;
|
||||
} else {
|
||||
store = data & ~0x3; // copy top (orientation) bits
|
||||
return mod((data & 0x3) + 1, 4) | store; // switch type with bottom bits and reapply top bits
|
||||
}
|
||||
|
||||
// <del>same here</del> - screw you unit tests
|
||||
/*case BlockID.QUARTZ_BLOCK:
|
||||
if (increment == -1 && data > 2) {
|
||||
switch (data) {
|
||||
case 2: return 3;
|
||||
case 3: return 4;
|
||||
case 4: return 2;
|
||||
}
|
||||
} else if (increment == 1) {
|
||||
switch (data) {
|
||||
case 0:
|
||||
return 1;
|
||||
case 1:
|
||||
return 2;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return -1;
|
||||
}*/
|
||||
|
||||
case BlockID.LONG_GRASS:
|
||||
case BlockID.SANDSTONE:
|
||||
case BlockID.DIRT:
|
||||
if (data > 2) return -1;
|
||||
return mod((data + increment), 3);
|
||||
|
||||
case BlockID.TORCH:
|
||||
case BlockID.REDSTONE_TORCH_ON:
|
||||
case BlockID.REDSTONE_TORCH_OFF:
|
||||
if (data < 1 || data > 4) return -1;
|
||||
return mod((data - 1 + increment), 4) + 1;
|
||||
|
||||
case BlockID.OAK_WOOD_STAIRS:
|
||||
case BlockID.COBBLESTONE_STAIRS:
|
||||
case BlockID.BRICK_STAIRS:
|
||||
case BlockID.STONE_BRICK_STAIRS:
|
||||
case BlockID.NETHER_BRICK_STAIRS:
|
||||
case BlockID.SANDSTONE_STAIRS:
|
||||
case BlockID.SPRUCE_WOOD_STAIRS:
|
||||
case BlockID.BIRCH_WOOD_STAIRS:
|
||||
case BlockID.JUNGLE_WOOD_STAIRS:
|
||||
case BlockID.QUARTZ_STAIRS:
|
||||
case BlockID.ACACIA_STAIRS:
|
||||
case BlockID.DARK_OAK_STAIRS:
|
||||
if (data > 7) return -1;
|
||||
return mod((data + increment), 8);
|
||||
|
||||
case BlockID.STONE_BRICK:
|
||||
case BlockID.QUARTZ_BLOCK:
|
||||
case BlockID.PUMPKIN:
|
||||
case BlockID.JACKOLANTERN:
|
||||
case BlockID.NETHER_WART:
|
||||
case BlockID.CAULDRON:
|
||||
case BlockID.WOODEN_STEP:
|
||||
case BlockID.DOUBLE_WOODEN_STEP:
|
||||
case BlockID.HAY_BLOCK:
|
||||
if (data > 3) return -1;
|
||||
return mod((data + increment), 4);
|
||||
|
||||
case BlockID.STEP:
|
||||
case BlockID.DOUBLE_STEP:
|
||||
case BlockID.CAKE_BLOCK:
|
||||
case BlockID.PISTON_BASE:
|
||||
case BlockID.PISTON_STICKY_BASE:
|
||||
case BlockID.SILVERFISH_BLOCK:
|
||||
if (data > 5) return -1;
|
||||
return mod((data + increment), 6);
|
||||
|
||||
case BlockID.DOUBLE_PLANT:
|
||||
store = data & 0x8; // top half flag
|
||||
data &= ~0x8;
|
||||
if (data > 5) return -1;
|
||||
return mod((data + increment), 6) | store;
|
||||
|
||||
case BlockID.CROPS:
|
||||
case BlockID.PUMPKIN_STEM:
|
||||
case BlockID.MELON_STEM:
|
||||
if (data > 6) return -1;
|
||||
return mod((data + increment), 7);
|
||||
|
||||
case BlockID.SOIL:
|
||||
case BlockID.RED_FLOWER:
|
||||
if (data > 8) return -1;
|
||||
return mod((data + increment), 9);
|
||||
|
||||
case BlockID.RED_MUSHROOM_CAP:
|
||||
case BlockID.BROWN_MUSHROOM_CAP:
|
||||
if (data > 10) return -1;
|
||||
return mod((data + increment), 11);
|
||||
|
||||
case BlockID.CACTUS:
|
||||
case BlockID.REED:
|
||||
case BlockID.SIGN_POST:
|
||||
case BlockID.VINE:
|
||||
case BlockID.SNOW:
|
||||
case BlockID.COCOA_PLANT:
|
||||
if (data > 15) return -1;
|
||||
return mod((data + increment), 16);
|
||||
|
||||
case BlockID.FURNACE:
|
||||
case BlockID.BURNING_FURNACE:
|
||||
case BlockID.WALL_SIGN:
|
||||
case BlockID.LADDER:
|
||||
case BlockID.CHEST:
|
||||
case BlockID.ENDER_CHEST:
|
||||
case BlockID.TRAPPED_CHEST:
|
||||
case BlockID.HOPPER:
|
||||
int extra = data & 0x8;
|
||||
int withoutFlags = data & ~0x8;
|
||||
if (withoutFlags < 2 || withoutFlags > 5) return -1;
|
||||
return (mod((withoutFlags - 2 + increment), 4) + 2) | extra;
|
||||
|
||||
case BlockID.DISPENSER:
|
||||
case BlockID.DROPPER:
|
||||
store = data & 0x8;
|
||||
data &= ~0x8;
|
||||
if (data > 5) return -1;
|
||||
return mod((data + increment), 6) | store;
|
||||
|
||||
case BlockID.REDSTONE_REPEATER_OFF:
|
||||
case BlockID.REDSTONE_REPEATER_ON:
|
||||
case BlockID.COMPARATOR_OFF:
|
||||
case BlockID.COMPARATOR_ON:
|
||||
case BlockID.TRAP_DOOR:
|
||||
case BlockID.FENCE_GATE:
|
||||
case BlockID.LEAVES:
|
||||
case BlockID.LEAVES2:
|
||||
if (data > 7) return -1;
|
||||
store = data & ~0x3;
|
||||
return mod(((data & 0x3) + increment), 4) | store;
|
||||
|
||||
case BlockID.MINECART_TRACKS:
|
||||
if (data < 6 || data > 9) return -1;
|
||||
return mod((data - 6 + increment), 4) + 6;
|
||||
|
||||
case BlockID.SAPLING:
|
||||
if ((data & 0x3) == 3 || data > 15) return -1;
|
||||
store = data & ~0x3;
|
||||
return mod(((data & 0x3) + increment), 3) | store;
|
||||
|
||||
case BlockID.FLOWER_POT:
|
||||
if (data > 13) return -1;
|
||||
return mod((data + increment), 14);
|
||||
|
||||
case BlockID.CLOTH:
|
||||
case BlockID.STAINED_CLAY:
|
||||
case BlockID.CARPET:
|
||||
case BlockID.STAINED_GLASS:
|
||||
case BlockID.STAINED_GLASS_PANE:
|
||||
if (increment == 1) {
|
||||
data = nextClothColor(data);
|
||||
} else if (increment == -1) {
|
||||
data = prevClothColor(data);
|
||||
}
|
||||
return data;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data value for the next color of cloth in the rainbow. This
|
||||
* should not be used if you want to just increment the data value.
|
||||
*
|
||||
* @param data the data value
|
||||
* @return the next data value
|
||||
*/
|
||||
public static int nextClothColor(int data) {
|
||||
switch (data) {
|
||||
case ClothColor.ID.WHITE: return ClothColor.ID.LIGHT_GRAY;
|
||||
case ClothColor.ID.LIGHT_GRAY: return ClothColor.ID.GRAY;
|
||||
case ClothColor.ID.GRAY: return ClothColor.ID.BLACK;
|
||||
case ClothColor.ID.BLACK: return ClothColor.ID.BROWN;
|
||||
case ClothColor.ID.BROWN: return ClothColor.ID.RED;
|
||||
case ClothColor.ID.RED: return ClothColor.ID.ORANGE;
|
||||
case ClothColor.ID.ORANGE: return ClothColor.ID.YELLOW;
|
||||
case ClothColor.ID.YELLOW: return ClothColor.ID.LIGHT_GREEN;
|
||||
case ClothColor.ID.LIGHT_GREEN: return ClothColor.ID.DARK_GREEN;
|
||||
case ClothColor.ID.DARK_GREEN: return ClothColor.ID.CYAN;
|
||||
case ClothColor.ID.CYAN: return ClothColor.ID.LIGHT_BLUE;
|
||||
case ClothColor.ID.LIGHT_BLUE: return ClothColor.ID.BLUE;
|
||||
case ClothColor.ID.BLUE: return ClothColor.ID.PURPLE;
|
||||
case ClothColor.ID.PURPLE: return ClothColor.ID.MAGENTA;
|
||||
case ClothColor.ID.MAGENTA: return ClothColor.ID.PINK;
|
||||
case ClothColor.ID.PINK: return ClothColor.ID.WHITE;
|
||||
}
|
||||
|
||||
return ClothColor.ID.WHITE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data value for the previous ext color of cloth in the rainbow.
|
||||
* This should not be used if you want to just increment the data value.
|
||||
*
|
||||
* @param data the data value
|
||||
* @return the new data value
|
||||
*/
|
||||
public static int prevClothColor(int data) {
|
||||
switch (data) {
|
||||
case ClothColor.ID.LIGHT_GRAY: return ClothColor.ID.WHITE;
|
||||
case ClothColor.ID.GRAY: return ClothColor.ID.LIGHT_GRAY;
|
||||
case ClothColor.ID.BLACK: return ClothColor.ID.GRAY;
|
||||
case ClothColor.ID.BROWN: return ClothColor.ID.BLACK;
|
||||
case ClothColor.ID.RED: return ClothColor.ID.BROWN;
|
||||
case ClothColor.ID.ORANGE: return ClothColor.ID.RED;
|
||||
case ClothColor.ID.YELLOW: return ClothColor.ID.ORANGE;
|
||||
case ClothColor.ID.LIGHT_GREEN: return ClothColor.ID.YELLOW;
|
||||
case ClothColor.ID.DARK_GREEN: return ClothColor.ID.LIGHT_GREEN;
|
||||
case ClothColor.ID.CYAN: return ClothColor.ID.DARK_GREEN;
|
||||
case ClothColor.ID.LIGHT_BLUE: return ClothColor.ID.CYAN;
|
||||
case ClothColor.ID.BLUE: return ClothColor.ID.LIGHT_BLUE;
|
||||
case ClothColor.ID.PURPLE: return ClothColor.ID.BLUE;
|
||||
case ClothColor.ID.MAGENTA: return ClothColor.ID.PURPLE;
|
||||
case ClothColor.ID.PINK: return ClothColor.ID.MAGENTA;
|
||||
case ClothColor.ID.WHITE: return ClothColor.ID.PINK;
|
||||
}
|
||||
|
||||
return ClothColor.ID.WHITE;
|
||||
return data + increment;
|
||||
// TODO Fix
|
||||
// if (increment != -1 && increment != 1) {
|
||||
// throw new IllegalArgumentException("Increment must be 1 or -1.");
|
||||
// }
|
||||
//
|
||||
// int store;
|
||||
// switch (type) {
|
||||
//
|
||||
// // special case here, going to use "forward" for type and "backward" for orientation
|
||||
// case BlockID.LOG:
|
||||
// case BlockID.LOG2:
|
||||
// if (increment == -1) {
|
||||
// store = data & 0x3; // copy bottom (type) bits
|
||||
// return mod((data & ~0x3) + 4, 16) | store; // switch orientation with top bits and reapply bottom bits;
|
||||
// } else {
|
||||
// store = data & ~0x3; // copy top (orientation) bits
|
||||
// return mod((data & 0x3) + 1, 4) | store; // switch type with bottom bits and reapply top bits
|
||||
// }
|
||||
//
|
||||
// // <del>same here</del> - screw you unit tests
|
||||
// /*case BlockID.QUARTZ_BLOCK:
|
||||
// if (increment == -1 && data > 2) {
|
||||
// switch (data) {
|
||||
// case 2: return 3;
|
||||
// case 3: return 4;
|
||||
// case 4: return 2;
|
||||
// }
|
||||
// } else if (increment == 1) {
|
||||
// switch (data) {
|
||||
// case 0:
|
||||
// return 1;
|
||||
// case 1:
|
||||
// return 2;
|
||||
// case 2:
|
||||
// case 3:
|
||||
// case 4:
|
||||
// return 0;
|
||||
// }
|
||||
// } else {
|
||||
// return -1;
|
||||
// }*/
|
||||
//
|
||||
// case BlockID.LONG_GRASS:
|
||||
// case BlockID.SANDSTONE:
|
||||
// case BlockID.DIRT:
|
||||
// if (data > 2) return -1;
|
||||
// return mod((data + increment), 3);
|
||||
//
|
||||
// case BlockID.TORCH:
|
||||
// case BlockID.REDSTONE_TORCH_ON:
|
||||
// case BlockID.REDSTONE_TORCH_OFF:
|
||||
// if (data < 1 || data > 4) return -1;
|
||||
// return mod((data - 1 + increment), 4) + 1;
|
||||
//
|
||||
// case BlockID.OAK_WOOD_STAIRS:
|
||||
// case BlockID.COBBLESTONE_STAIRS:
|
||||
// case BlockID.BRICK_STAIRS:
|
||||
// case BlockID.STONE_BRICK_STAIRS:
|
||||
// case BlockID.NETHER_BRICK_STAIRS:
|
||||
// case BlockID.SANDSTONE_STAIRS:
|
||||
// case BlockID.SPRUCE_WOOD_STAIRS:
|
||||
// case BlockID.BIRCH_WOOD_STAIRS:
|
||||
// case BlockID.JUNGLE_WOOD_STAIRS:
|
||||
// case BlockID.QUARTZ_STAIRS:
|
||||
// case BlockID.ACACIA_STAIRS:
|
||||
// case BlockID.DARK_OAK_STAIRS:
|
||||
// if (data > 7) return -1;
|
||||
// return mod((data + increment), 8);
|
||||
//
|
||||
// case BlockID.STONE_BRICK:
|
||||
// case BlockID.QUARTZ_BLOCK:
|
||||
// case BlockID.PUMPKIN:
|
||||
// case BlockID.JACKOLANTERN:
|
||||
// case BlockID.NETHER_WART:
|
||||
// case BlockID.CAULDRON:
|
||||
// case BlockID.WOODEN_STEP:
|
||||
// case BlockID.DOUBLE_WOODEN_STEP:
|
||||
// case BlockID.HAY_BLOCK:
|
||||
// if (data > 3) return -1;
|
||||
// return mod((data + increment), 4);
|
||||
//
|
||||
// case BlockID.STEP:
|
||||
// case BlockID.DOUBLE_STEP:
|
||||
// case BlockID.CAKE_BLOCK:
|
||||
// case BlockID.PISTON_BASE:
|
||||
// case BlockID.PISTON_STICKY_BASE:
|
||||
// case BlockID.SILVERFISH_BLOCK:
|
||||
// if (data > 5) return -1;
|
||||
// return mod((data + increment), 6);
|
||||
//
|
||||
// case BlockID.DOUBLE_PLANT:
|
||||
// store = data & 0x8; // top half flag
|
||||
// data &= ~0x8;
|
||||
// if (data > 5) return -1;
|
||||
// return mod((data + increment), 6) | store;
|
||||
//
|
||||
// case BlockID.CROPS:
|
||||
// case BlockID.PUMPKIN_STEM:
|
||||
// case BlockID.MELON_STEM:
|
||||
// if (data > 6) return -1;
|
||||
// return mod((data + increment), 7);
|
||||
//
|
||||
// case BlockID.SOIL:
|
||||
// case BlockID.RED_FLOWER:
|
||||
// if (data > 8) return -1;
|
||||
// return mod((data + increment), 9);
|
||||
//
|
||||
// case BlockID.RED_MUSHROOM_CAP:
|
||||
// case BlockID.BROWN_MUSHROOM_CAP:
|
||||
// if (data > 10) return -1;
|
||||
// return mod((data + increment), 11);
|
||||
//
|
||||
// case BlockID.CACTUS:
|
||||
// case BlockID.REED:
|
||||
// case BlockID.SIGN_POST:
|
||||
// case BlockID.VINE:
|
||||
// case BlockID.SNOW:
|
||||
// case BlockID.COCOA_PLANT:
|
||||
// if (data > 15) return -1;
|
||||
// return mod((data + increment), 16);
|
||||
//
|
||||
// case BlockID.FURNACE:
|
||||
// case BlockID.BURNING_FURNACE:
|
||||
// case BlockID.WALL_SIGN:
|
||||
// case BlockID.LADDER:
|
||||
// case BlockID.CHEST:
|
||||
// case BlockID.ENDER_CHEST:
|
||||
// case BlockID.TRAPPED_CHEST:
|
||||
// case BlockID.HOPPER:
|
||||
// int extra = data & 0x8;
|
||||
// int withoutFlags = data & ~0x8;
|
||||
// if (withoutFlags < 2 || withoutFlags > 5) return -1;
|
||||
// return (mod((withoutFlags - 2 + increment), 4) + 2) | extra;
|
||||
//
|
||||
// case BlockID.DISPENSER:
|
||||
// case BlockID.DROPPER:
|
||||
// store = data & 0x8;
|
||||
// data &= ~0x8;
|
||||
// if (data > 5) return -1;
|
||||
// return mod((data + increment), 6) | store;
|
||||
//
|
||||
// case BlockID.REDSTONE_REPEATER_OFF:
|
||||
// case BlockID.REDSTONE_REPEATER_ON:
|
||||
// case BlockID.COMPARATOR_OFF:
|
||||
// case BlockID.COMPARATOR_ON:
|
||||
// case BlockID.TRAP_DOOR:
|
||||
// case BlockID.FENCE_GATE:
|
||||
// case BlockID.LEAVES:
|
||||
// case BlockID.LEAVES2:
|
||||
// if (data > 7) return -1;
|
||||
// store = data & ~0x3;
|
||||
// return mod(((data & 0x3) + increment), 4) | store;
|
||||
//
|
||||
// case BlockID.MINECART_TRACKS:
|
||||
// if (data < 6 || data > 9) return -1;
|
||||
// return mod((data - 6 + increment), 4) + 6;
|
||||
//
|
||||
// case BlockID.SAPLING:
|
||||
// if ((data & 0x3) == 3 || data > 15) return -1;
|
||||
// store = data & ~0x3;
|
||||
// return mod(((data & 0x3) + increment), 3) | store;
|
||||
//
|
||||
// case BlockID.FLOWER_POT:
|
||||
// if (data > 13) return -1;
|
||||
// return mod((data + increment), 14);
|
||||
//
|
||||
// case BlockID.CLOTH:
|
||||
// case BlockID.STAINED_CLAY:
|
||||
// case BlockID.CARPET:
|
||||
// case BlockID.STAINED_GLASS:
|
||||
// case BlockID.STAINED_GLASS_PANE:
|
||||
// if (increment == 1) {
|
||||
// data = nextClothColor(data);
|
||||
// } else if (increment == -1) {
|
||||
// data = prevClothColor(data);
|
||||
// }
|
||||
// return data;
|
||||
//
|
||||
// default:
|
||||
// return -1;
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1194,25 +1194,6 @@ public enum BlockType {
|
||||
return isNaturalTerrainBlock.contains(-16*id-data) || isNaturalTerrainBlock.contains(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the block type is naturally occurring
|
||||
*
|
||||
* @param block the block
|
||||
* @return true if the block type is naturally occurring
|
||||
*/
|
||||
public static boolean isNaturalTerrainBlock(BaseBlock block) {
|
||||
return isNaturalTerrainBlock(block.getId(), block.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the block type is naturally occurring
|
||||
*
|
||||
* @return true if the block type is naturally occurring
|
||||
*/
|
||||
public boolean isNaturalTerrainBlock() {
|
||||
return isNaturalTerrainBlock.contains(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* HashSet for emitsLight.
|
||||
*/
|
||||
|
@ -31,61 +31,32 @@ import java.util.EnumSet;
|
||||
*/
|
||||
public enum ClothColor {
|
||||
|
||||
WHITE(ID.WHITE, "White", "white"),
|
||||
ORANGE(ID.ORANGE, "Orange", "orange"),
|
||||
MAGENTA(ID.MAGENTA, "Magenta", "magenta"),
|
||||
LIGHT_BLUE(ID.LIGHT_BLUE, "Light blue", "lightblue"),
|
||||
YELLOW(ID.YELLOW, "Yellow", "yellow"),
|
||||
LIGHT_GREEN(ID.LIGHT_GREEN, "Light green", "lightgreen"),
|
||||
PINK(ID.PINK, "Pink", new String[] { "pink", "lightred" }),
|
||||
GRAY(ID.GRAY, "Gray", new String[] { "grey", "gray" }),
|
||||
LIGHT_GRAY(ID.LIGHT_GRAY, "Light gray", new String[] { "lightgrey", "lightgray" }),
|
||||
CYAN(ID.CYAN, "Cyan", new String[] { "cyan", "turquoise" }),
|
||||
PURPLE(ID.PURPLE, "Purple", new String[] { "purple", "violet" }),
|
||||
BLUE(ID.BLUE, "Blue", "blue"),
|
||||
BROWN(ID.BROWN, "Brown", new String[] { "brown", "cocoa", "coffee" }),
|
||||
DARK_GREEN(ID.DARK_GREEN, "Dark green", new String[] { "green", "darkgreen", "cactusgreen", "cactigreen" }),
|
||||
RED(ID.RED, "Red", "red"),
|
||||
BLACK(ID.BLACK, "Black", "black");
|
||||
|
||||
public static final class ID {
|
||||
public static final int WHITE = 0;
|
||||
public static final int ORANGE = 1;
|
||||
public static final int MAGENTA = 2;
|
||||
public static final int LIGHT_BLUE = 3;
|
||||
public static final int YELLOW = 4;
|
||||
public static final int LIGHT_GREEN = 5;
|
||||
public static final int PINK = 6;
|
||||
public static final int GRAY = 7;
|
||||
public static final int LIGHT_GRAY = 8;
|
||||
public static final int CYAN = 9;
|
||||
public static final int PURPLE = 10;
|
||||
public static final int BLUE = 11;
|
||||
public static final int BROWN = 12;
|
||||
public static final int DARK_GREEN = 13;
|
||||
public static final int RED = 14;
|
||||
public static final int BLACK = 15;
|
||||
|
||||
private ID() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores a map of the IDs for fast access.
|
||||
*/
|
||||
private static final Map<Integer, ClothColor> ids = new HashMap<>();
|
||||
WHITE("White", "white"),
|
||||
ORANGE("Orange", "orange"),
|
||||
MAGENTA("Magenta", "magenta"),
|
||||
LIGHT_BLUE("Light blue", "lightblue"),
|
||||
YELLOW("Yellow", "yellow"),
|
||||
LIGHT_GREEN("Light green", "lightgreen"),
|
||||
PINK("Pink", "pink", "lightred"),
|
||||
GRAY("Gray", "grey", "gray"),
|
||||
LIGHT_GRAY("Light gray", "lightgrey", "lightgray"),
|
||||
CYAN("Cyan", "cyan", "turquoise"),
|
||||
PURPLE("Purple", "purple", "violet"),
|
||||
BLUE("Blue", "blue"),
|
||||
BROWN("Brown", "brown", "cocoa", "coffee"),
|
||||
DARK_GREEN("Dark green", "green", "darkgreen", "cactusgreen", "cactigreen"),
|
||||
RED("Red", "red"),
|
||||
BLACK("Black", "black");
|
||||
/**
|
||||
* Stores a map of the names for fast access.
|
||||
*/
|
||||
private static final Map<String, ClothColor> lookup = new HashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final String name;
|
||||
private final String[] lookupKeys;
|
||||
|
||||
static {
|
||||
for (ClothColor type : EnumSet.allOf(ClothColor.class)) {
|
||||
ids.put(type.id, type);
|
||||
for (String key : type.lookupKeys) {
|
||||
lookup.put(key, type);
|
||||
}
|
||||
@ -96,40 +67,14 @@ public enum ClothColor {
|
||||
/**
|
||||
* Construct the type.
|
||||
*
|
||||
* @param id the ID of the color
|
||||
* @param name the name of the color
|
||||
* @param lookupKey a name to refer to the color by
|
||||
* @param lookupKeys a name to refer to the color by
|
||||
*/
|
||||
ClothColor(int id, String name, String lookupKey) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.lookupKeys = new String[] { lookupKey };
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the type.
|
||||
*
|
||||
* @param id the ID of the color
|
||||
* @param name the name of the color
|
||||
* @param lookupKeys an array of lookup keys
|
||||
*/
|
||||
ClothColor(int id, String name, String[] lookupKeys) {
|
||||
this.id = id;
|
||||
ClothColor(String name, String ... lookupKeys) {
|
||||
this.name = name;
|
||||
this.lookupKeys = lookupKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return type from ID. May return null.
|
||||
*
|
||||
* @param id the ID
|
||||
* @return a color or null
|
||||
*/
|
||||
@Nullable
|
||||
public static ClothColor fromID(int id) {
|
||||
return ids.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return type from name. May return null.
|
||||
*
|
||||
@ -141,15 +86,6 @@ public enum ClothColor {
|
||||
return lookup.get(name.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item numeric ID.
|
||||
*
|
||||
* @return the ID
|
||||
*/
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user-friendly item name.
|
||||
*
|
||||
|
@ -141,6 +141,11 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState toImmutableState() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method used for creating the initial BlockState.
|
||||
*
|
||||
|
@ -64,4 +64,11 @@ public interface BlockStateHolder<T extends BlockStateHolder> {
|
||||
* @return true if equal
|
||||
*/
|
||||
boolean equalsFuzzy(BlockStateHolder o);
|
||||
|
||||
/**
|
||||
* Returns an immutable BlockState from this BlockStateHolder.
|
||||
*
|
||||
* @return A BlockState
|
||||
*/
|
||||
BlockState toImmutableState();
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
package com.sk89q.worldedit.blocks.type;
|
||||
|
||||
import com.sk89q.worldedit.world.registry.BundledBlockData;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@ -85,9 +86,9 @@ public class BlockType {
|
||||
*/
|
||||
@Deprecated
|
||||
public int getLegacyId() {
|
||||
Integer id = BundledBlockData.getInstance().toLegacyId(this.id);
|
||||
int[] id = LegacyMapper.getInstance().getLegacyFromBlock(this.getDefaultState());
|
||||
if (id != null) {
|
||||
return id;
|
||||
return id[0];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
@ -19,8 +19,8 @@
|
||||
|
||||
package com.sk89q.worldedit.blocks.type;
|
||||
|
||||
import com.sk89q.worldedit.world.registry.BundledBlockData;
|
||||
import com.sk89q.worldedit.world.registry.BundledItemData;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
|
||||
public class ItemType {
|
||||
|
||||
@ -61,9 +61,9 @@ public class ItemType {
|
||||
*/
|
||||
@Deprecated
|
||||
public int getLegacyId() {
|
||||
Integer id = BundledItemData.getInstance().toLegacyId(this.id);
|
||||
if (id != null) {
|
||||
return id;
|
||||
int ids[] = LegacyMapper.getInstance().getLegacyFromItem(this);
|
||||
if (ids != null) {
|
||||
return ids[0];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user