Search in sources :

Example 21 with BaseBlock

use of com.sk89q.worldedit.world.block.BaseBlock in project FastAsyncWorldEdit by IntellectualSites.

the class RandomStatePatternParser method parseFromInput.

@Override
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
    if (!input.startsWith("*")) {
        return null;
    }
    boolean wasFuzzy = context.isPreferringWildcard();
    context.setPreferringWildcard(true);
    BaseBlock block = worldEdit.getBlockFactory().parseFromInput(input.substring(1), context);
    context.setPreferringWildcard(wasFuzzy);
    if (block.getStates().size() == block.getBlockType().getPropertyMap().size()) {
        // they requested random with *, but didn't leave any states empty - simplify
        return block;
    } else if (block.toImmutableState() instanceof FuzzyBlockState) {
        return new RandomStatePattern((FuzzyBlockState) block.toImmutableState());
    } else {
        // only should happen if parseLogic changes
        return null;
    }
}
Also used : RandomStatePattern(com.sk89q.worldedit.function.pattern.RandomStatePattern) FuzzyBlockState(com.sk89q.worldedit.world.block.FuzzyBlockState) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock)

Example 22 with BaseBlock

use of com.sk89q.worldedit.world.block.BaseBlock in project FastAsyncWorldEdit by IntellectualSites.

the class Int2BaseBlockMap method containsValue.

@Override
public boolean containsValue(Object v) {
    BaseBlock block = (BaseBlock) v;
    int internalId = optimizedInternalId(block);
    if (!BlockStateIdAccess.isValidInternalId(internalId)) {
        return uncommonMap.containsValue(block);
    }
    return commonMap.containsValue(internalId);
}
Also used : BaseBlock(com.sk89q.worldedit.world.block.BaseBlock)

Example 23 with BaseBlock

use of com.sk89q.worldedit.world.block.BaseBlock in project FastAsyncWorldEdit by IntellectualSites.

the class Int2BaseBlockMap method put.

@Override
public BaseBlock put(int key, BaseBlock value) {
    int internalId = optimizedInternalId(value);
    if (!BlockStateIdAccess.isValidInternalId(internalId)) {
        BaseBlock old = uncommonMap.put(key, value);
        if (old == null) {
            // ensure common doesn't have the entry too
            int oldId = commonMap.remove(key);
            return assumeAsBlock(oldId);
        }
        return old;
    }
    int oldId = commonMap.put(key, internalId);
    return assumeAsBlock(oldId);
}
Also used : BaseBlock(com.sk89q.worldedit.world.block.BaseBlock)

Example 24 with BaseBlock

use of com.sk89q.worldedit.world.block.BaseBlock in project FastAsyncWorldEdit by IntellectualSites.

the class ForgePlayer method sendFakeBlock.

@Override
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
    World world = getWorld();
    if (!(world instanceof ForgeWorld)) {
        return;
    }
    BlockPos loc = ForgeAdapter.toBlockPos(pos);
    if (block == null) {
        final SChangeBlockPacket packetOut = new SChangeBlockPacket(((ForgeWorld) world).getWorld(), loc);
        player.connection.sendPacket(packetOut);
    } else {
        final SChangeBlockPacket packetOut = new SChangeBlockPacket();
        PacketBuffer buf = new PacketBuffer(Unpooled.buffer());
        buf.writeBlockPos(loc);
        buf.writeVarInt(Block.getStateId(ForgeAdapter.adapt(block.toImmutableState())));
        try {
            packetOut.readPacketData(buf);
        } catch (IOException e) {
            return;
        }
        player.connection.sendPacket(packetOut);
        if (block instanceof BaseBlock && block.getBlockType().equals(BlockTypes.STRUCTURE_BLOCK)) {
            final BaseBlock baseBlock = (BaseBlock) block;
            final CompoundTag nbtData = baseBlock.getNbtData();
            if (nbtData != null) {
                player.connection.sendPacket(new SUpdateTileEntityPacket(new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()), STRUCTURE_BLOCK_PACKET_ID, NBTConverter.toNative(nbtData)));
            }
        }
    }
}
Also used : SChangeBlockPacket(net.minecraft.network.play.server.SChangeBlockPacket) SUpdateTileEntityPacket(net.minecraft.network.play.server.SUpdateTileEntityPacket) BlockPos(net.minecraft.util.math.BlockPos) IOException(java.io.IOException) World(com.sk89q.worldedit.world.World) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) PacketBuffer(net.minecraft.network.PacketBuffer) CompoundTag(com.sk89q.jnbt.CompoundTag)

Example 25 with BaseBlock

use of com.sk89q.worldedit.world.block.BaseBlock in project FastAsyncWorldEdit by IntellectualSites.

the class WaterloggedRemover method applyBlock.

@Override
public BaseBlock applyBlock(BlockVector3 position) {
    BaseBlock block = getExtent().getFullBlock(position);
    // FAWE start - remap
    BlockState newState = remap[block.getOrdinal()];
    if (newState != null) {
        return newState.toBaseBlock(block.getNbtData());
    }
    // FAWE end
    return BlockTypes.AIR.getDefaultState().toBaseBlock();
}
Also used : BlockState(com.sk89q.worldedit.world.block.BlockState) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock)

Aggregations

BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)50 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)22 BlockState (com.sk89q.worldedit.world.block.BlockState)10 CompoundTag (com.sk89q.jnbt.CompoundTag)9 HashMap (java.util.HashMap)7 Tag (com.sk89q.jnbt.Tag)6 Location (com.sk89q.worldedit.util.Location)6 World (com.sk89q.worldedit.world.World)6 BlockType (com.sk89q.worldedit.world.block.BlockType)6 IOException (java.io.IOException)6 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)5 ListTag (com.sk89q.jnbt.ListTag)5 StringTag (com.sk89q.jnbt.StringTag)5 WorldEditException (com.sk89q.worldedit.WorldEditException)5 ArrayList (java.util.ArrayList)5 IntTag (com.sk89q.jnbt.IntTag)4 BaseEntity (com.sk89q.worldedit.entity.BaseEntity)4 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)4 Region (com.sk89q.worldedit.regions.Region)4 NamedTag (com.sk89q.jnbt.NamedTag)3