default String getAsString() { if (getStates().isEmpty()) { return this.getBlockType().getId(); } else { String properties = getStates().entrySet().stream().map(entry -> entry.getKey().getName() + "=" + entry.getValue().toString().toLowerCase()).collect(Collectors.joining( ",")); return this.getBlockType().getId() + "[" + properties + "]"; } } }
/** * Checks whether a given block is in a list of base blocks. * * @param collection the collection * @param o the block * @return true if the collection contains the given block */ public static <B extends BlockStateHolder<B>> boolean containsFuzzy(Collection<? extends BlockStateHolder<?>> collection, B o) { // Allow masked data in the searchBlocks to match various types for (BlockStateHolder<?> b : collection) { if (b.equalsFuzzy(o)) { return true; } } return false; }
@Nullable @Override public BlockData apply(@Nullable String input) { return Bukkit.createBlockData(block.getAsString()); } }).clone();
@Override public <B extends BlockStateHolder<B>> boolean isAffectedBlock(B block) { return block.getBlockType() == BlockTypes.SIGN || block.getBlockType() == BlockTypes.WALL_SIGN; }
@Override public boolean equalsFuzzy(BlockStateHolder<?> o) { if (this == o) { // Added a reference equality check for return true; } if (!getBlockType().equals(o.getBlockType())) { return false; } Set<Property<?>> differingProperties = new HashSet<>(); for (Object state : o.getStates().keySet()) { if (getState((Property<?>) state) == null) { differingProperties.add((Property<?>) state); } } for (Property<?> property : getStates().keySet()) { if (o.getState(property) == null) { differingProperties.add(property); } } for (Property<?> property : getStates().keySet()) { if (differingProperties.contains(property)) { continue; } if (!Objects.equals(getState(property), o.getState(property))) { return false; } } return true; }
List<? extends Property<?>> properties = block.getBlockType().getProperties(); Direction value = (Direction) block.getState(property); if (value != null) { Vector3 newValue = getNewStateValue(dirProp.getValues(), transform, value.toVector()); if (newValue != null) { result = result.with(dirProp, Direction.findClosest(newValue, Direction.Flag.ALL)); switch ((String) block.getState(property)) { case "x": value = Direction.EAST; result = result.with(enumProp, axis); if (property.getName().equals("rotation")) { if (intProp.getValues().size() == 16) { Optional<Direction> direction = Direction.fromRotationIndex(block.getState(intProp)); int horizontalFlags = Direction.Flag.CARDINAL | Direction.Flag.ORDINAL | Direction.Flag.SECONDARY_ORDINAL; if (direction.isPresent()) { OptionalInt newRotation = Direction.findClosest(vec, horizontalFlags).toRotationIndex(); if (newRotation.isPresent()) { result = result.with(intProp, newRotation.getAsInt()); .filter(prop -> prop instanceof BooleanProperty) .filter(prop -> directionNames.contains(prop.getName())) .filter(property -> (Boolean) block.getState(property)) .map(Property::getName) .map(String::toUpperCase)
BlockState existing = getExtent().getBlock(position); if (!block.getBlockType().equals(existing.getBlockType())) { if (!block.getBlockType().getMaterial().isAir()) { try { blockBag.fetchPlacedBlock(block.toImmutableState()); } catch (UnplaceableBlockException e) { return false; } catch (BlockBagException e) { if (!missingBlocks.containsKey(block.getBlockType())) { missingBlocks.put(block.getBlockType(), 1); } else { missingBlocks.put(block.getBlockType(), missingBlocks.get(block.getBlockType()) + 1);
@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 <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 location, T block) throws WorldEditException { if (super.setBlock(location, block)) { if (lastFullBlock != null && lastFullBlock.position.equals(location)) { this.lastFullBlock = new CachedBlock<>(location, block.toBaseBlock()); } if (lastBlock != null && lastBlock.position.equals(location)) { this.lastBlock = new CachedBlock<>(location, block.toImmutableState()); } return true; } return false; }
/** * Set the block that is returned. * * @param block the block */ public void setBlock(BlockStateHolder<?> block) { checkNotNull(block); this.block = block.toBaseBlock(); }
/** * Gets the stage priority of the block. * * @param block The block * @return The priority */ private <B extends BlockStateHolder<B>> PlacementPriority getPlacementPriority(B block) { return priorityMap.getOrDefault(block.getBlockType(), PlacementPriority.FIRST); }
/** * Create a new block change. * * @param position the position * @param previous the previous block * @param current the current block */ public <BP extends BlockStateHolder<BP>, BC extends BlockStateHolder<BC>> BlockChange(BlockVector3 position, BP previous, BC current) { checkNotNull(position); checkNotNull(previous); checkNotNull(current); this.position = position; this.previous = previous.toBaseBlock(); this.current = current.toBaseBlock(); }
@SuppressWarnings("WeakerAccess") protected BlockState getBlockState(BlockStateHolder<?> block) { if (block instanceof com.sk89q.worldedit.world.block.BlockState) { BlockState state = Sponge.getRegistry().getType(BlockType.class, block.getBlockType().getId()).orElse(BlockTypes.AIR).getDefaultState(); for (Map.Entry<Property<?>, Object> entry : block.getStates().entrySet()) { // TODO Convert across states } return state; } else { throw new UnsupportedOperationException("Missing Sponge adapter for WorldEdit!"); } }
/** * Checks whether the BlockStateHolder is contained within * this category. * * @param blockStateHolder The blockstateholder * @return If it's a part of this category */ public <B extends BlockStateHolder<B>> boolean contains(B blockStateHolder) { return this.getAll().contains(blockStateHolder.getBlockType()); } }
public <B extends BlockStateHolder<B>> void add(BlockVector3 location, B block) { add(new LocatedBlock(location, block.toBaseBlock())); }
/** * Create a Bukkit BlockData from a WorldEdit BlockStateHolder * * @param block The WorldEdit BlockStateHolder * @return The Bukkit BlockData */ public static <B extends BlockStateHolder<B>> BlockData adapt(B block) { checkNotNull(block); return blockDataCache.computeIfAbsent(block.getAsString(), new Function<String, BlockData>() { @Nullable @Override public BlockData apply(@Nullable String input) { return Bukkit.createBlockData(block.getAsString()); } }).clone(); }
BlockPos pos = new BlockPos(x, y, z); IBlockState old = chunk.getBlockState(pos); Block mcBlock = Block.getBlockFromName(block.getBlockType().getId()); IBlockState newState = mcBlock.getDefaultState(); Map<Property<?>, Object> states = block.getStates(); newState = applyProperties(mcBlock.getBlockState(), newState, states); IBlockState successState = chunk.setBlockState(pos, newState);
@Override public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException { final int y = location.getBlockY(); final BlockType type = block.getBlockType(); if (y < 0 || y > world.getMaxY()) { return false; } // No invalid blocks if (type == null) { return false; } return super.setBlock(location, block); }
@Override public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException { // Update minimum if (min == null) { min = location; } else { min = min.getMinimum(location); } // Update maximum if (max == null) { max = location; } else { max = max.getMaximum(location); } if (mask.test(location)) { buffer.put(location, block.toBaseBlock()); return true; } else { return getExtent().setBlock(location, block); } }
@Override public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException { if (toolUse && block.getBlockType().getMaterial().isAir()) { world.simulateBlockMine(location); return true; } else { return super.setBlock(location, block); } }