@Override public String toString() { return getId(); }
private static BlockType register(final String id, Function<BlockState, BlockState> values) { return register(new BlockType(id, values)); }
@Override public BlockState getBlock(BlockVector3 position) { return BlockTypes.AIR.getDefaultState(); }
structureTag.put("ignoreEntities", new ByteTag((byte) 1)); structureTag.put("showboundingbox", new ByteTag((byte) 1)); structureTag.put("id", new StringTag(BlockTypes.STRUCTURE_BLOCK.getId())); return BlockTypes.STRUCTURE_BLOCK.getDefaultState().toBaseBlock(new CompoundTag(structureTag));
private void recurseHollow(Region region, BlockVector3 origin, Set<BlockVector3> outside) { final LinkedList<BlockVector3> queue = new LinkedList<>(); queue.addLast(origin); while (!queue.isEmpty()) { final BlockVector3 current = queue.removeFirst(); final BlockState block = getBlock(current); if (block.getBlockType().getMaterial().isMovementBlocker()) { continue; } if (!outside.add(current)) { continue; } if (!region.contains(current)) { continue; } for (BlockVector3 recurseDirection : recurseDirections) { queue.addLast(current.add(recurseDirection)); } } }
@Override public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws WorldEditException { BlockType existing = getExtent().getBlock(position).getBlockType(); if (existing.getMaterial().hasContainer()) { world.clearContainerBlockContents(position); // Clear the container block so that it doesn't drop items } else if (existing == BlockTypes.ICE) { world.setBlock(position, BlockTypes.AIR.getDefaultState()); // Ice turns until water so this has to be done first } return super.setBlock(position, block); }
@Override public void storeBlock(BlockState blockState, int amount) throws BlockBagException { if (blockState.getBlockType().getMaterial().isAir()) { throw new IllegalArgumentException("Can't store air block"); if (!blockState.getBlockType().hasItemType()) { throw new IllegalArgumentException("This block cannot be stored"); items[freeSlot] = BukkitAdapter.adapt(new BaseItemStack(blockState.getBlockType().getItemType(), amount)); return;
@Override public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) { World world = (World) clicked.getExtent(); BlockVector3 blockPoint = clicked.toVector().toBlockPoint(); final BlockType blockType = world.getBlock(blockPoint).getBlockType(); if (blockType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) { return true; } try (EditSession editSession = session.createEditSession(player)) { editSession.getSurvivalExtent().setToolUse(config.superPickaxeDrop); editSession.setBlock(blockPoint, BlockTypes.AIR.getDefaultState()); } catch (MaxChangedBlocksException e) { player.printError("Max blocks change limit reached."); } world.playEffect(clicked.toVector(), 2001, blockType.getLegacyId()); return true; }
@SuppressWarnings("deprecation") public void play() { playEffect(position, 2001, blockType.getLegacyId()); }
/** * Flush a block bag's changes to a player. * * @param actor the actor * @param editSession the edit session */ public void flushBlockBag(Actor actor, EditSession editSession) { BlockBag blockBag = editSession.getBlockBag(); if (blockBag != null) { blockBag.flushChanges(); } Map<BlockType, Integer> missingBlocks = editSession.popMissingBlocks(); if (!missingBlocks.isEmpty()) { StringBuilder str = new StringBuilder(); str.append("Missing these blocks: "); int size = missingBlocks.size(); int i = 0; for (Map.Entry<BlockType, Integer> blockTypeIntegerEntry : missingBlocks.entrySet()) { str.append((blockTypeIntegerEntry.getKey()).getName()); str.append(" [Amt: ").append(blockTypeIntegerEntry.getValue()).append("]"); ++i; if (i != size) { str.append(", "); } } actor.printError(str.toString()); } }
Property<Object> propertyKey = (Property<Object>) state.getBlockType().getPropertyMap().get(parts[0]); if (propertyKey == null) { throw new NoMatchException("Unknown state " + parts[0] + " for block " + state.getBlockType().getName());
List<? extends Property<?>> properties = block.getBlockType().getProperties(); result = result.with(block.getBlockType().getProperty(directionName), directionalProperties.contains(directionName));
/** * Adds a property to the fuzzy BlockState * * @param property The property * @param value The value * @param <V> The property type * @return The builder, for chaining */ public <V> Builder withProperty(Property<V> property, V value) { checkNotNull(property); checkNotNull(value); checkNotNull(type, "The type must be set before the properties!"); type.getProperty(property.getName()); // Verify the property is valid for this type values.put(property, value); return this; }
/** * Gets whether this block type has an item representation. * * @return If it has an item */ public boolean hasItemType() { return getItemType() != null; }
public TargetMatcher fromInput(String input) throws TargetMatcherParseException { input = input.toLowerCase().trim(); BlockType blockType = BlockTypes.get(input); if (blockType != null) { if (blockType.hasItemType()) { return new ItemBlockMatcher(blockType); } else { return new BlockMatcher(blockType); } } else { ItemType itemType = ItemTypes.get(input); if (itemType == null) { throw new TargetMatcherParseException("Unknown block or item name: " + input); } return new ItemMatcher(itemType); } } }
state = blockType.getDefaultState(); } else { FuzzyBlockState.Builder fuzzyBuilder = FuzzyBlockState.builder(); Actor actor = context.requireActor(); if (actor != null && !actor.hasPermission("worldedit.anyblock") && worldEdit.getConfiguration().disallowedBlocks.contains(blockType.getId())) { throw new DisallowedUsageException("You are not allowed to use '" + input + "'");
/** * Stores a block as if it was mined. * * @param blockState the block state * @throws BlockBagException on error */ public void storeDroppedBlock(BlockState blockState) throws BlockBagException { BlockState dropped = blockState; // TODO BlockType.getBlockBagItem(id, data); if (dropped == null) return; if (dropped.getBlockType().getMaterial().isAir()) return; storeBlock(dropped); }
@Override public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException { if (!enabled) { return super.setBlock(location, block); } BlockState existing = getBlock(location); PlacementPriority priority = getPlacementPriority(block); PlacementPriority srcPriority = getPlacementPriority(existing); if (srcPriority != PlacementPriority.FIRST) { BaseBlock replacement = (block.getBlockType().getMaterial().isAir() ? block : BlockTypes.AIR.getDefaultState()).toBaseBlock(); switch (srcPriority) { case FINAL: stages.get(PlacementPriority.CLEAR_FINAL).add(location, replacement); break; case LATE: stages.get(PlacementPriority.CLEAR_LATE).add(location, replacement); break; case LAST: stages.get(PlacementPriority.CLEAR_LAST).add(location, replacement); break; } if (block.getBlockType().getMaterial().isAir()) { return !existing.equalsFuzzy(block); } } stages.get(priority).add(location, block); return !existing.equalsFuzzy(block); }
@Override public int getBlockType(double x, double y, double z) { return editSession.getBlock(toWorld(x, y, z)).getBlockType().getLegacyId(); }