Migrate the logic for which pass a block goes into. Also updated it and made it use tags where possible.

This commit is contained in:
Matthew Miller 2018-07-05 17:00:46 +10:00
parent efa09001c2
commit 7db443a69a
8 changed files with 147 additions and 221 deletions

View File

@ -23,7 +23,6 @@ import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
import com.sk89q.worldedit.entity.BaseEntity;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.entity.Entity;
@ -34,26 +33,6 @@ import javax.annotation.Nullable;
*/
public interface BukkitImplAdapter {
/**
* Get the block ID for the given material.
*
* <p>Returns 0 if it is not known or it doesn't exist.</p>
*
* @param material the material
* @return the block ID
*/
int getBlockId(Material material);
/**
* Get the material for the given block ID.
*
* <p>Returns {@link Material#AIR} if it is not known or it doesn't exist.</p>
*
* @param id the block ID
* @return the material
*/
Material getMaterial(int id);
/**
* Get the biome ID for the given biome.
*

View File

@ -74,23 +74,6 @@ public class LazyBlock extends BaseBlock {
this.position = position;
}
/**
* Create a new lazy block.
*
* @param type the block type
* @param data the data value
* @param extent the extent to later load the full block data from
* @param position the position to later load the full block data from
*/
@Deprecated
public LazyBlock(int type, int data, Extent extent, Vector position) {
super(type, data);
checkNotNull(extent);
checkNotNull(position);
this.extent = extent;
this.position = position;
}
@Override
public CompoundTag getNbtData() {
if (!loaded) {

View File

@ -56,24 +56,6 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
@Nullable
private CompoundTag nbtData;
/**
* Construct a block with the given ID and a data value of 0.
*
* @param id ID value
*/
@Deprecated
public BaseBlock(int id) {
try {
this.blockState = LegacyMapper.getInstance().getBlockFromLegacy(id);
if (this.blockState == null) {
this.blockState = BlockTypes.AIR.getDefaultState();
}
} catch (Exception e) {
System.out.println(id);
e.printStackTrace();
}
}
/**
* Construct a block with a state.
*
@ -111,7 +93,15 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
*/
@Deprecated
public BaseBlock(int id, int data) {
this(id);
try {
this.blockState = LegacyMapper.getInstance().getBlockFromLegacy(id, data);
if (this.blockState == null) {
this.blockState = BlockTypes.AIR.getDefaultState();
}
} catch (Exception e) {
System.out.println(id);
e.printStackTrace();
}
}
/**

View File

@ -37,14 +37,12 @@ public final class BlockID {
public static final int DEAD_BUSH = 32; // DEADBUSH
public static final int PISTON_BASE = 33; // PISTON
public static final int PISTON_EXTENSION = 34; // PISTON_HEAD
public static final int PISTON_MOVING_PIECE = 36; // PISTON_EXTENSION
public static final int YELLOW_FLOWER = 37;
public static final int RED_FLOWER = 38;
public static final int BROWN_MUSHROOM = 39;
public static final int RED_MUSHROOM = 40;
public static final int STEP = 44; // STONE_SLAB
public static final int TORCH = 50;
public static final int FIRE = 51;
public static final int OAK_WOOD_STAIRS = 53; // OAK_STAIRS
public static final int CHEST = 54;
public static final int REDSTONE_WIRE = 55;
@ -70,7 +68,6 @@ public final class BlockID {
public static final int FENCE = 85;
public static final int PUMPKIN = 86;
public static final int SLOW_SAND = 88; // SOUL_SAND
public static final int PORTAL = 90;
public static final int JACKOLANTERN = 91; // LIT_PUMPKIN
public static final int CAKE_BLOCK = 92; // CAKE
public static final int REDSTONE_REPEATER_OFF = 93; // UNPOWERED_REPEATER
@ -126,7 +123,6 @@ public final class BlockID {
public static final int DOUBLE_PLANT = 175;
public static final int STANDING_BANNER = 176;
public static final int WALL_BANNER = 177;
public static final int DAYLIGHT_SENSOR_INVERTED = 178;
public static final int STEP2 = 182;
public static final int SPRUCE_DOOR = 193;
public static final int BIRCH_DOOR = 194;

View File

@ -25,9 +25,7 @@ import com.sk89q.worldedit.PlayerDirection;
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* Block types.
@ -39,110 +37,6 @@ public enum BlockType {
;
/**
* HashSet for shouldPlaceLast.
*/
private static final Set<Integer> shouldPlaceLast = new HashSet<>();
static {
shouldPlaceLast.add(BlockID.SAPLING);
shouldPlaceLast.add(BlockID.BED);
shouldPlaceLast.add(BlockID.POWERED_RAIL);
shouldPlaceLast.add(BlockID.DETECTOR_RAIL);
shouldPlaceLast.add(BlockID.LONG_GRASS);
shouldPlaceLast.add(BlockID.DEAD_BUSH);
shouldPlaceLast.add(BlockID.YELLOW_FLOWER);
shouldPlaceLast.add(BlockID.RED_FLOWER);
shouldPlaceLast.add(BlockID.BROWN_MUSHROOM);
shouldPlaceLast.add(BlockID.RED_MUSHROOM);
shouldPlaceLast.add(BlockID.TORCH);
shouldPlaceLast.add(BlockID.FIRE);
shouldPlaceLast.add(BlockID.REDSTONE_WIRE);
shouldPlaceLast.add(BlockID.CROPS);
shouldPlaceLast.add(BlockID.LADDER);
shouldPlaceLast.add(BlockID.MINECART_TRACKS);
shouldPlaceLast.add(BlockID.LEVER);
shouldPlaceLast.add(BlockID.STONE_PRESSURE_PLATE);
shouldPlaceLast.add(BlockID.WOODEN_PRESSURE_PLATE);
shouldPlaceLast.add(BlockID.REDSTONE_TORCH_OFF);
shouldPlaceLast.add(BlockID.REDSTONE_TORCH_ON);
shouldPlaceLast.add(BlockID.STONE_BUTTON);
shouldPlaceLast.add(BlockID.SNOW);
shouldPlaceLast.add(BlockID.PORTAL);
shouldPlaceLast.add(BlockID.REDSTONE_REPEATER_OFF);
shouldPlaceLast.add(BlockID.REDSTONE_REPEATER_ON);
shouldPlaceLast.add(BlockID.TRAP_DOOR);
shouldPlaceLast.add(BlockID.VINE);
shouldPlaceLast.add(BlockID.LILY_PAD);
shouldPlaceLast.add(BlockID.NETHER_WART);
shouldPlaceLast.add(BlockID.PISTON_BASE);
shouldPlaceLast.add(BlockID.PISTON_STICKY_BASE);
shouldPlaceLast.add(BlockID.PISTON_EXTENSION);
shouldPlaceLast.add(BlockID.PISTON_MOVING_PIECE);
shouldPlaceLast.add(BlockID.COCOA_PLANT);
shouldPlaceLast.add(BlockID.TRIPWIRE_HOOK);
shouldPlaceLast.add(BlockID.TRIPWIRE);
shouldPlaceLast.add(BlockID.FLOWER_POT);
shouldPlaceLast.add(BlockID.CARROTS);
shouldPlaceLast.add(BlockID.POTATOES);
shouldPlaceLast.add(BlockID.WOODEN_BUTTON);
shouldPlaceLast.add(BlockID.ANVIL); // becomes relevant with asynchronous placement
shouldPlaceLast.add(BlockID.PRESSURE_PLATE_LIGHT);
shouldPlaceLast.add(BlockID.PRESSURE_PLATE_HEAVY);
shouldPlaceLast.add(BlockID.COMPARATOR_OFF);
shouldPlaceLast.add(BlockID.COMPARATOR_ON);
shouldPlaceLast.add(BlockID.ACTIVATOR_RAIL);
shouldPlaceLast.add(BlockID.IRON_TRAP_DOOR);
shouldPlaceLast.add(BlockID.CARPET);
shouldPlaceLast.add(BlockID.DOUBLE_PLANT);
shouldPlaceLast.add(BlockID.DAYLIGHT_SENSOR_INVERTED);
}
/**
* Checks to see whether a block should be placed last (when reordering
* blocks that are placed).
*
* @param id the block ID
* @return true if the block should be placed last
*/
public static boolean shouldPlaceLast(int id) {
return shouldPlaceLast.contains(id);
}
/**
* HashSet for shouldPlaceLast.
*/
private static final Set<Integer> shouldPlaceFinal = new HashSet<>();
static {
shouldPlaceFinal.add(BlockID.SIGN_POST);
shouldPlaceFinal.add(BlockID.WOODEN_DOOR);
shouldPlaceFinal.add(BlockID.ACACIA_DOOR);
shouldPlaceFinal.add(BlockID.BIRCH_DOOR);
shouldPlaceFinal.add(BlockID.JUNGLE_DOOR);
shouldPlaceFinal.add(BlockID.DARK_OAK_DOOR);
shouldPlaceFinal.add(BlockID.SPRUCE_DOOR);
shouldPlaceFinal.add(BlockID.WALL_SIGN);
shouldPlaceFinal.add(BlockID.IRON_DOOR);
shouldPlaceFinal.add(BlockID.CACTUS);
shouldPlaceFinal.add(BlockID.REED);
shouldPlaceFinal.add(BlockID.CAKE_BLOCK);
shouldPlaceFinal.add(BlockID.PISTON_EXTENSION);
shouldPlaceFinal.add(BlockID.PISTON_MOVING_PIECE);
shouldPlaceFinal.add(BlockID.STANDING_BANNER);
shouldPlaceFinal.add(BlockID.WALL_BANNER);
}
/**
* Checks to see whether a block should be placed in the final queue.
*
* This applies to blocks that can be attached to other blocks that have an attachment.
*
* @param id the type ID of the block
* @return whether the block is in the final queue
*/
public static boolean shouldPlaceFinal(int id) {
return shouldPlaceFinal.contains(id);
}
/**
* HashSet for centralTopLimit.
*/

View File

@ -19,9 +19,14 @@
package com.sk89q.worldedit.blocks;
import com.sk89q.worldedit.blocks.type.BlockCategories;
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
import com.sk89q.worldedit.blocks.type.BlockType;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
/**
* Block-related utility methods.
@ -31,6 +36,121 @@ public final class Blocks {
private Blocks() {
}
/**
* HashSet for shouldPlaceLast.
*/
private static final Set<BlockType> shouldPlaceLast = new HashSet<>();
static {
shouldPlaceLast.addAll(BlockCategories.SAPLINGS.getBlockTypes());
shouldPlaceLast.addAll(BlockCategories.FLOWER_POTS.getBlockTypes());
shouldPlaceLast.addAll(BlockCategories.BUTTONS.getBlockTypes());
shouldPlaceLast.addAll(BlockCategories.ANVIL.getBlockTypes()); // becomes relevant with asynchronous placement
shouldPlaceLast.addAll(BlockCategories.WOODEN_PRESSURE_PLATES.getBlockTypes());
shouldPlaceLast.addAll(BlockCategories.CARPETS.getBlockTypes());
shouldPlaceLast.addAll(BlockCategories.RAILS.getBlockTypes());
shouldPlaceLast.add(BlockTypes.BLACK_BED);
shouldPlaceLast.add(BlockTypes.BLUE_BED);
shouldPlaceLast.add(BlockTypes.BROWN_BED);
shouldPlaceLast.add(BlockTypes.CYAN_BED);
shouldPlaceLast.add(BlockTypes.GRAY_BED);
shouldPlaceLast.add(BlockTypes.GREEN_BED);
shouldPlaceLast.add(BlockTypes.LIGHT_BLUE_BED);
shouldPlaceLast.add(BlockTypes.LIGHT_GRAY_BED);
shouldPlaceLast.add(BlockTypes.LIME_BED);
shouldPlaceLast.add(BlockTypes.MAGENTA_BED);
shouldPlaceLast.add(BlockTypes.ORANGE_BED);
shouldPlaceLast.add(BlockTypes.PINK_BED);
shouldPlaceLast.add(BlockTypes.PURPLE_BED);
shouldPlaceLast.add(BlockTypes.RED_BED);
shouldPlaceLast.add(BlockTypes.WHITE_BED);
shouldPlaceLast.add(BlockTypes.YELLOW_BED);
shouldPlaceLast.add(BlockTypes.GRASS);
shouldPlaceLast.add(BlockTypes.TALL_GRASS);
shouldPlaceLast.add(BlockTypes.ROSE_BUSH);
shouldPlaceLast.add(BlockTypes.DANDELION);
shouldPlaceLast.add(BlockTypes.BROWN_MUSHROOM);
shouldPlaceLast.add(BlockTypes.RED_MUSHROOM);
shouldPlaceLast.add(BlockTypes.FERN);
shouldPlaceLast.add(BlockTypes.LARGE_FERN);
shouldPlaceLast.add(BlockTypes.OXEYE_DAISY);
shouldPlaceLast.add(BlockTypes.AZURE_BLUET);
shouldPlaceLast.add(BlockTypes.TORCH);
shouldPlaceLast.add(BlockTypes.WALL_TORCH);
shouldPlaceLast.add(BlockTypes.FIRE);
shouldPlaceLast.add(BlockTypes.REDSTONE_WIRE);
shouldPlaceLast.add(BlockTypes.CARROTS);
shouldPlaceLast.add(BlockTypes.POTATOES);
shouldPlaceLast.add(BlockTypes.WHEAT);
shouldPlaceLast.add(BlockTypes.BEETROOTS);
shouldPlaceLast.add(BlockTypes.COCOA);
shouldPlaceLast.add(BlockTypes.LADDER);
shouldPlaceLast.add(BlockTypes.LEVER);
shouldPlaceLast.add(BlockTypes.REDSTONE_TORCH);
shouldPlaceLast.add(BlockTypes.REDSTONE_WALL_TORCH);
shouldPlaceLast.add(BlockTypes.SNOW);
shouldPlaceLast.add(BlockTypes.PORTAL);
shouldPlaceLast.add(BlockTypes.END_PORTAL);
shouldPlaceLast.add(BlockTypes.REPEATER);
shouldPlaceLast.add(BlockTypes.VINE);
shouldPlaceLast.add(BlockTypes.LILY_PAD);
shouldPlaceLast.add(BlockTypes.NETHER_WART);
shouldPlaceLast.add(BlockTypes.PISTON);
shouldPlaceLast.add(BlockTypes.STICKY_PISTON);
shouldPlaceLast.add(BlockTypes.TRIPWIRE_HOOK);
shouldPlaceLast.add(BlockTypes.TRIPWIRE);
shouldPlaceLast.add(BlockTypes.STONE_PRESSURE_PLATE);
shouldPlaceLast.add(BlockTypes.HEAVY_WEIGHTED_PRESSURE_PLATE);
shouldPlaceLast.add(BlockTypes.LIGHT_WEIGHTED_PRESSURE_PLATE);
shouldPlaceLast.add(BlockTypes.COMPARATOR);
shouldPlaceLast.add(BlockTypes.IRON_TRAPDOOR);
shouldPlaceLast.add(BlockTypes.ACACIA_TRAPDOOR);
shouldPlaceLast.add(BlockTypes.BIRCH_TRAPDOOR);
shouldPlaceLast.add(BlockTypes.DARK_OAK_TRAPDOOR);
shouldPlaceLast.add(BlockTypes.JUNGLE_TRAPDOOR);
shouldPlaceLast.add(BlockTypes.OAK_TRAPDOOR);
shouldPlaceLast.add(BlockTypes.SPRUCE_TRAPDOOR);
shouldPlaceLast.add(BlockTypes.DAYLIGHT_DETECTOR);
}
/**
* Checks to see whether a block should be placed last (when reordering
* blocks that are placed).
*
* @param type the block type
* @return true if the block should be placed last
*/
public static boolean shouldPlaceLast(BlockType type) {
return shouldPlaceLast.contains(type);
}
/**
* HashSet for shouldPlaceLast.
*/
private static final Set<BlockType> shouldPlaceFinal = new HashSet<>();
static {
shouldPlaceFinal.addAll(BlockCategories.DOORS.getBlockTypes());
shouldPlaceFinal.addAll(BlockCategories.BANNERS.getBlockTypes());
shouldPlaceFinal.add(BlockTypes.SIGN);
shouldPlaceFinal.add(BlockTypes.WALL_SIGN);
shouldPlaceFinal.add(BlockTypes.CACTUS);
shouldPlaceFinal.add(BlockTypes.SUGAR_CANE);
shouldPlaceFinal.add(BlockTypes.CAKE);
shouldPlaceFinal.add(BlockTypes.PISTON_HEAD);
shouldPlaceFinal.add(BlockTypes.MOVING_PISTON);
}
/**
* Checks to see whether a block should be placed in the final queue.
*
* This applies to blocks that can be attached to other blocks that have an attachment.
*
* @param type the type of the block
* @return whether the block is in the final queue
*/
public static boolean shouldPlaceFinal(BlockType type) {
return shouldPlaceFinal.contains(type);
}
/**
* Checks whether a given block is in a list of base blocks.
*

View File

@ -24,9 +24,10 @@ import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.PlayerDirection;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.blocks.Blocks;
import com.sk89q.worldedit.blocks.type.BlockCategories;
import com.sk89q.worldedit.blocks.type.BlockState;
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
@ -89,27 +90,27 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
@Override
public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException {
BaseBlock lazyBlock = getLazyBlock(location);
BlockState existing = getBlock(location);
if (!enabled) {
return super.setBlock(location, block);
}
if (BlockType.shouldPlaceLast(block.getBlockType().getLegacyId())) {
if (Blocks.shouldPlaceLast(block.getBlockType())) {
// Place torches, etc. last
stage2.put(location.toBlockVector(), block);
return !(lazyBlock.getBlockType() == block.getBlockType()); // TODO && lazyBlock.getData() == block.getData());
} else if (BlockType.shouldPlaceFinal(block.getBlockType().getLegacyId())) {
return !existing.equalsFuzzy(block);
} else if (Blocks.shouldPlaceFinal(block.getBlockType())) {
// Place signs, reed, etc even later
stage3.put(location.toBlockVector(), block);
return !(lazyBlock.getBlockType() == block.getBlockType()); // TODO && lazyBlock.getData() == block.getData());
} else if (BlockType.shouldPlaceLast(lazyBlock.getBlockType().getLegacyId())) {
return !existing.equalsFuzzy(block);
} else if (Blocks.shouldPlaceLast(existing.getBlockType())) {
// Destroy torches, etc. first
super.setBlock(location, BlockTypes.AIR.getDefaultState());
return super.setBlock(location, block);
} else {
stage1.put(location.toBlockVector(), block);
return !(lazyBlock.getBlockType() == block.getBlockType()); // TODO && lazyBlock.getData() == block.getData());
return !existing.equalsFuzzy(block);
}
}
@ -149,19 +150,10 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
assert (blockTypes.containsKey(current));
final BlockStateHolder baseBlock = blockTypes.get(current);
final int type = baseBlock.getBlockType().getLegacyId();
final BlockStateHolder blockStateHolder = blockTypes.get(current);
// final int data = baseBlock.getData();
switch (type) {
case BlockID.WOODEN_DOOR:
case BlockID.ACACIA_DOOR:
case BlockID.BIRCH_DOOR:
case BlockID.JUNGLE_DOOR:
case BlockID.DARK_OAK_DOOR:
case BlockID.SPRUCE_DOOR:
case BlockID.IRON_DOOR:
if (BlockCategories.DOORS.contains(blockStateHolder.getBlockType())) {
// TODO if ((data & 0x8) == 0) {
// // Deal with lower door halves being attached to the floor AND the upper half
// BlockVector upperBlock = current.add(0, 1, 0).toBlockVector();
@ -169,22 +161,14 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
// walked.addFirst(upperBlock);
// }
// }
break;
case BlockID.MINECART_TRACKS:
case BlockID.POWERED_RAIL:
case BlockID.DETECTOR_RAIL:
case BlockID.ACTIVATOR_RAIL:
// Here, rails are hardcoded to be attached to the block below them.
// They're also attached to the block they're ascending towards via BlockType.getAttachment.
BlockVector lowerBlock = current.add(0, -1, 0).toBlockVector();
if (blocks.contains(lowerBlock) && !walked.contains(lowerBlock)) {
walked.addFirst(lowerBlock);
}
break;
} else if (BlockCategories.RAILS.contains(blockStateHolder.getBlockType())) {
BlockVector lowerBlock = current.add(0, -1, 0).toBlockVector();
if (blocks.contains(lowerBlock) && !walked.contains(lowerBlock)) {
walked.addFirst(lowerBlock);
}
}
final PlayerDirection attachment = BlockType.getAttachment(type, 0); // TODO
final PlayerDirection attachment = BlockType.getAttachment(blockStateHolder.getBlockType().getLegacyId(), 0); // TODO
if (attachment == null) {
// Block is not attached to anything => we can place it
break;

View File

@ -37,22 +37,6 @@ import org.spongepowered.api.world.biome.BiomeType;
*/
public interface SpongeImplAdapter {
/**
* Resolves the numerical ID from this {@link ItemType}
*
* @param type The itemtype
* @return The numerical ID
*/
int resolve(ItemType type);
/**
* Resolves the numerical ID from this {@link BlockType}
*
* @param type The blocktype
* @return The numerical ID
*/
int resolve(BlockType type);
/**
* Resolves the numerical ID from this {@link BiomeType}
*
@ -61,10 +45,6 @@ public interface SpongeImplAdapter {
*/
int resolve(BiomeType type);
ItemType resolveItem(int intID);
BlockType resolveBlock(int intID);
BiomeType resolveBiome(int intID);
BaseEntity createBaseEntity(Entity entity);