Fixed some bugs and cleanup some code.

This commit is contained in:
Matthew Miller
2018-08-13 22:18:12 +10:00
parent f96487a2d1
commit e0e7778536
22 changed files with 92 additions and 394 deletions

View File

@ -1,92 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.blocks;
import com.sk89q.worldedit.world.block.BlockTypes;
/**
* List of block IDs.
*
* {@deprecated Please use {@link BlockTypes }}
*/
@Deprecated
public final class BlockID {
static final int SAPLING = 6;
static final int POWERED_RAIL = 27; // GOLDEN_RAIL
static final int DETECTOR_RAIL = 28;
static final int LONG_GRASS = 31; // TALLGRASS
static final int DEAD_BUSH = 32; // DEADBUSH
static final int PISTON_EXTENSION = 34; // PISTON_HEAD
static final int YELLOW_FLOWER = 37;
static final int RED_FLOWER = 38;
static final int BROWN_MUSHROOM = 39;
static final int RED_MUSHROOM = 40;
static final int TORCH = 50;
static final int REDSTONE_WIRE = 55;
static final int CROPS = 59; // WHEAT
static final int SIGN_POST = 63; // STANDING_SIGN
static final int WOODEN_DOOR = 64; // WOODEN_DOOR
static final int LADDER = 65;
static final int MINECART_TRACKS = 66; // RAIL
static final int WALL_SIGN = 68;
static final int LEVER = 69;
static final int STONE_PRESSURE_PLATE = 70;
static final int IRON_DOOR = 71;
static final int WOODEN_PRESSURE_PLATE = 72;
static final int REDSTONE_TORCH_OFF = 75; // UNLIT_REDSTONE_TORCH
static final int REDSTONE_TORCH_ON = 76; // LIT_REDSTONE_TORCH
static final int STONE_BUTTON = 77;
static final int CACTUS = 81;
static final int REED = 83; // REEDS
static final int CAKE_BLOCK = 92; // CAKE
static final int REDSTONE_REPEATER_OFF = 93; // UNPOWERED_REPEATER
static final int REDSTONE_REPEATER_ON = 94; // POWERED_REPEATER
static final int TRAP_DOOR = 96; // TRAPDOOR
static final int PUMPKIN_STEM = 104;
static final int MELON_STEM = 105;
static final int VINE = 106;
static final int NETHER_WART = 115;
static final int COCOA_PLANT = 127; // COCOA
static final int TRIPWIRE_HOOK = 131;
static final int TRIPWIRE = 132;
static final int FLOWER_POT = 140;
static final int CARROTS = 141;
static final int POTATOES = 142;
static final int WOODEN_BUTTON = 143;
static final int ANVIL = 145;
static final int PRESSURE_PLATE_LIGHT = 147; // LIGHT_WEIGHTED_PRESSURE_PLATE
static final int PRESSURE_PLATE_HEAVY = 148; // HEAVY_WEIGHTED_PRESSURE_PLATE
static final int COMPARATOR_OFF = 149; // UNPOWERED_COMPARATOR
static final int COMPARATOR_ON = 150; // COMPARATOR
static final int ACTIVATOR_RAIL = 157;
static final int IRON_TRAP_DOOR = 167;
static final int CARPET = 171;
static final int DOUBLE_PLANT = 175;
static final int STANDING_BANNER = 176;
static final int WALL_BANNER = 177;
static final int SPRUCE_DOOR = 193;
static final int BIRCH_DOOR = 194;
static final int JUNGLE_DOOR = 195;
static final int ACACIA_DOOR = 196;
static final int DARK_OAK_DOOR = 197;
private BlockID() {
}
}

View File

@ -1,158 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.blocks;
import com.sk89q.worldedit.PlayerDirection;
import java.util.HashMap;
import java.util.Map;
/**
* Block types.
*
* {@deprecated Please use {@link com.sk89q.worldedit.world.block.BlockType }}
*/
@Deprecated
public enum BlockType {
;
private static final Map<Integer, PlayerDirection> dataAttachments = new HashMap<>();
private static final Map<Integer, PlayerDirection> nonDataAttachments = new HashMap<>();
static {
nonDataAttachments.put(BlockID.SAPLING, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.LONG_GRASS, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.DEAD_BUSH, PlayerDirection.DOWN);
for (int offset = 0; offset < 16; offset += 8) {
dataAttachments.put(typeDataKey(BlockID.PISTON_EXTENSION, offset + 0), PlayerDirection.UP);
dataAttachments.put(typeDataKey(BlockID.PISTON_EXTENSION, offset + 1), PlayerDirection.DOWN);
addCardinals(BlockID.PISTON_EXTENSION, offset + 2, offset + 5, offset + 3, offset + 4);
}
nonDataAttachments.put(BlockID.YELLOW_FLOWER, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.RED_FLOWER, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.BROWN_MUSHROOM, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.RED_MUSHROOM, PlayerDirection.DOWN);
for (int blockId : new int[] { BlockID.TORCH, BlockID.REDSTONE_TORCH_ON, BlockID.REDSTONE_TORCH_OFF }) {
dataAttachments.put(typeDataKey(blockId, 0), PlayerDirection.DOWN);
dataAttachments.put(typeDataKey(blockId, 5), PlayerDirection.DOWN); // According to the minecraft wiki, this one is history. Keeping both, for now...
addCardinals(blockId, 4, 1, 3, 2);
}
nonDataAttachments.put(BlockID.REDSTONE_WIRE, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.CROPS, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.SIGN_POST, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.WOODEN_DOOR, PlayerDirection.DOWN);
addCardinals(BlockID.LADDER, 2, 5, 3, 4);
addCardinals(BlockID.WALL_SIGN, 2, 5, 3, 4);
for (int offset = 0; offset < 16; offset += 8) {
addCardinals(BlockID.LEVER, offset + 4, offset + 1, offset + 3, offset + 2);
dataAttachments.put(typeDataKey(BlockID.LEVER, offset + 5), PlayerDirection.DOWN);
dataAttachments.put(typeDataKey(BlockID.LEVER, offset + 6), PlayerDirection.DOWN);
dataAttachments.put(typeDataKey(BlockID.LEVER, offset + 7), PlayerDirection.UP);
dataAttachments.put(typeDataKey(BlockID.LEVER, offset + 0), PlayerDirection.UP);
}
nonDataAttachments.put(BlockID.STONE_PRESSURE_PLATE, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.IRON_DOOR, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.WOODEN_PRESSURE_PLATE, PlayerDirection.DOWN);
// redstone torches: see torches
for (int offset = 0; offset < 16; offset += 8) {
addCardinals(BlockID.STONE_BUTTON, offset + 4, offset + 1, offset + 3, offset + 2);
addCardinals(BlockID.WOODEN_BUTTON, offset + 4, offset + 1, offset + 3, offset + 2);
}
dataAttachments.put(typeDataKey(BlockID.STONE_BUTTON, 0), PlayerDirection.UP);
dataAttachments.put(typeDataKey(BlockID.STONE_BUTTON, 5), PlayerDirection.DOWN);
dataAttachments.put(typeDataKey(BlockID.WOODEN_BUTTON, 0), PlayerDirection.UP);
dataAttachments.put(typeDataKey(BlockID.WOODEN_BUTTON, 5), PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.CACTUS, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.REED, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.CAKE_BLOCK, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.REDSTONE_REPEATER_OFF, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.REDSTONE_REPEATER_ON, PlayerDirection.DOWN);
for (int offset = 0; offset < 16; offset += 4) {
addCardinals(BlockID.TRAP_DOOR, offset + 0, offset + 3, offset + 1, offset + 2);
addCardinals(BlockID.IRON_TRAP_DOOR, offset + 0, offset + 3, offset + 1, offset + 2);
}
nonDataAttachments.put(BlockID.PUMPKIN_STEM, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.MELON_STEM, PlayerDirection.DOWN);
// vines are complicated, but I'll list the single-attachment variants anyway
dataAttachments.put(typeDataKey(BlockID.VINE, 0), PlayerDirection.UP);
addCardinals(BlockID.VINE, 1, 2, 4, 8);
nonDataAttachments.put(BlockID.NETHER_WART, PlayerDirection.DOWN);
for (int offset = 0; offset < 16; offset += 4) {
addCardinals(BlockID.COCOA_PLANT, offset + 0, offset + 1, offset + 2, offset + 3);
}
for (int offset = 0; offset < 16; offset += 4) {
addCardinals(BlockID.TRIPWIRE_HOOK, offset + 2, offset + 3, offset + 0, offset + 1);
}
nonDataAttachments.put(BlockID.TRIPWIRE, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.FLOWER_POT, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.CARROTS, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.POTATOES, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.ANVIL, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.PRESSURE_PLATE_LIGHT, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.PRESSURE_PLATE_HEAVY, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.COMPARATOR_OFF, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.COMPARATOR_ON, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.CARPET, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.DOUBLE_PLANT, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.STANDING_BANNER, PlayerDirection.DOWN);
addCardinals(BlockID.WALL_BANNER, 4, 2, 5, 3);
nonDataAttachments.put(BlockID.SPRUCE_DOOR, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.BIRCH_DOOR, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.JUNGLE_DOOR, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.ACACIA_DOOR, PlayerDirection.DOWN);
nonDataAttachments.put(BlockID.DARK_OAK_DOOR, PlayerDirection.DOWN);
// Rails are hardcoded to be attached to the block below them.
// In addition to that, let's attach ascending rails to the block they're ascending towards.
for (int offset = 0; offset < 16; offset += 8) {
addCardinals(BlockID.POWERED_RAIL, offset + 3, offset + 4, offset + 2, offset + 5);
addCardinals(BlockID.DETECTOR_RAIL, offset + 3, offset + 4, offset + 2, offset + 5);
addCardinals(BlockID.MINECART_TRACKS, offset + 3, offset + 4, offset + 2, offset + 5);
addCardinals(BlockID.ACTIVATOR_RAIL, offset + 3, offset + 4, offset + 2, offset + 5);
}
}
/**
* Returns the direction to the block(B) this block(A) is attached to.
* Attached means that if block B is destroyed, block A will pop off.
*
* @param type the block id of block A
* @param data the data value of block A
* @return direction to block B
*/
public static PlayerDirection getAttachment(int type, int data) {
PlayerDirection direction = nonDataAttachments.get(type);
if (direction != null) return direction;
return dataAttachments.get(typeDataKey(type, data));
}
private static int typeDataKey(int type, int data) {
return (type << 4) | (data & 0xf);
}
private static void addCardinals(int type, int west, int north, int east, int south) {
dataAttachments.put(typeDataKey(type, west), PlayerDirection.WEST);
dataAttachments.put(typeDataKey(type, north), PlayerDirection.NORTH);
dataAttachments.put(typeDataKey(type, east), PlayerDirection.EAST);
dataAttachments.put(typeDataKey(type, south), PlayerDirection.SOUTH);
}
}