当前位置: 首页>>代码示例>>Java>>正文


Java BlockChangeFlag类代码示例

本文整理汇总了Java中org.spongepowered.api.world.BlockChangeFlag的典型用法代码示例。如果您正苦于以下问题:Java BlockChangeFlag类的具体用法?Java BlockChangeFlag怎么用?Java BlockChangeFlag使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BlockChangeFlag类属于org.spongepowered.api.world包,在下文中一共展示了BlockChangeFlag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.spongepowered.api.world.BlockChangeFlag; //导入依赖的package包/类
@Override
public void execute(CommandQueue queue, CommandEntry entry) {
    ListTag locs = ListTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
    BlockTypeTag type = BlockTypeTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
    boolean phys = true;
    if (entry.namedArgs.containsKey("physics")) {
        phys = BooleanTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "physics")).getInternal();
    }
    if (queue.shouldShowGood()) {
        queue.outGood("Changing location(s) " + ColorSet.emphasis + locs.debug() + ColorSet.good
                + " to type " + ColorSet.emphasis + type.debug() + ColorSet.good
                + " with physics " + ColorSet.emphasis + (phys ? "on" : "off"));
    }
    for (AbstractTagObject ato : locs.getInternal()) {
        LocationTag loc = LocationTag.getFor(queue.error, ato);
        loc.getInternal().world.setBlockType(loc.getInternal().toVector3i(), type.getInternal(),
                phys ? BlockChangeFlag.ALL : BlockChangeFlag.NONE);
    }
    // TODO: "Cause" argument!
}
 
开发者ID:DenizenScript,项目名称:Denizen2Sponge,代码行数:21,代码来源:SetBlockCommand.java

示例2: restore

import org.spongepowered.api.world.BlockChangeFlag; //导入依赖的package包/类
@Override
public boolean restore(boolean force, BlockChangeFlag flag) {
    if (this.location == null) {
        throw new IllegalStateException("This BlockSnapshot doesn't have a location.");
    }
    Location<World> loc = this.getLocation().orElse(null);
    if (loc == null || (!force && loc.getBlockType() != this.state.getType())) {
        return false;
    }
    loc.setBlock(this.state, flag);
    final World world = loc.getExtent();
    world.setCreator(this.location.position, this.creator.orElse(null));
    world.setNotifier(this.location.position, this.notifier.orElse(null));
    if (this.tileEntityData != null) {
        final TileEntity tileEntity = loc.getTileEntity().orElse(null);
        if (tileEntity != null) {
            //noinspection unchecked
            this.tileEntityData.forEach((key, value) -> tileEntity.offer((Key) key, value));
        }
    }
    return true;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:23,代码来源:LanternBlockSnapshot.java

示例3: onRemove

import org.spongepowered.api.world.BlockChangeFlag; //导入依赖的package包/类
@Override
public void onRemove() {
	super.onRemove();
	Location<World> location = getConsumer().getEntity().getLocation();
	BlockState build = BlockState.builder().blockType(BlockTypes.AIR).build();

	for (Vector3i vector3i : vector3is) {
		BlockState block = location.getExtent().getBlock(vector3i);
		if (block.getType() == BlockTypes.WEB) {
			location.getExtent().setBlock(
					vector3i,
					build,
					BlockChangeFlag.NONE
			);
		}
	}
}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:18,代码来源:WebEffect.java

示例4: replaceWith

import org.spongepowered.api.world.BlockChangeFlag; //导入依赖的package包/类
/**
 * Removes the {@link CustomBlock} and replaces it with a vanilla {@link BlockState}.
 *
 * @param replacement The {@link BlockState} to replace the block with
 * @param flag How the world should be updated
 * @param cause The cause
 * @return Whether the block has been successfully replaced
 */
default boolean replaceWith(BlockState replacement, BlockChangeFlag flag, Cause cause) {
    Location<World> location = getBlock().getLocation()
            .orElseThrow(() -> new IllegalStateException("Could not access the location of this block."));
    CustomItemServiceImpl service = CustomItemLibrary.getInstance().getService();
    Block block = getBlock();

    service.unregisterBlockAsLoaded(block);
    service.removeArmorStandsAt(block);

    return location.setBlock(replacement, flag, cause);
}
 
开发者ID:Limeth,项目名称:CustomItemLibrary,代码行数:20,代码来源:CustomBlock.java

示例5: onBlockHit

import org.spongepowered.api.world.BlockChangeFlag; //导入依赖的package包/类
@Override
public boolean onBlockHit(CustomWorld world, Vector3i pos, Player player, HandType currHand, Direction side,
        Vector3d clickPoint) {
    Cause breakCause = Cause.builder()
            .named("plugin", Industrialization.toContainer())
            .named(NamedCause.SOURCE, player)
            .build();
    world.getWorld().setBlockType(pos, BlockTypes.AIR, BlockChangeFlag.ALL, breakCause);
    // Sponge broke and doesn't fire the event (SpongeCommon#998)
    BlockSnapshot from = world.getWorld().createSnapshot(pos);
    BlockSnapshot to = from.withState(BlockTypes.AIR.getDefaultState());
    List<Transaction<BlockSnapshot>> tr = Lists.newArrayList(new Transaction<>(from, to));
    Sponge.getEventManager().post(SpongeEventFactory.createChangeBlockEventBreak(breakCause, tr));
    return false;
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:16,代码来源:PipeBlock.java

示例6: onApply

import org.spongepowered.api.world.BlockChangeFlag; //导入依赖的package包/类
@Override
public void onApply() {
	super.onApply();
	Location<World> location = getConsumer().getEntity().getLocation();
	Vector3d position = location.getPosition();
	int floorY = position.getFloorY();
	BlockState build = BlockState.builder().blockType(BlockTypes.WEB).build();
	int b = 0;
	for (int i = -1; i <= 1; i++) {
		for (int x = -1; x <= 1; x++) {
			Vector3i vector3i = new Vector3i(
					position.getFloorX() + i,
					floorY,
					position.getFloorZ() + x);
			vector3is[b] = vector3i;
			b++;
			if (location.getExtent().getBlock(vector3i).getType() == BlockTypes.AIR) {
				location.getExtent().setBlock(
						vector3i,
						build,
						BlockChangeFlag.NONE
				);

			}
		}
	}
}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:28,代码来源:WebEffect.java

示例7: deserializeBlock

import org.spongepowered.api.world.BlockChangeFlag; //导入依赖的package包/类
private void deserializeBlock(String serial) throws IOException {
    BlockSnapshot bs = SerializationHelper.deserialize(BlockSnapshot.class, serial);
    bs.restore(true, BlockChangeFlag.NONE);
}
 
开发者ID:caseif,项目名称:Inferno,代码行数:5,代码来源:InfernoRollbackAgent.java

示例8: placeBlock

import org.spongepowered.api.world.BlockChangeFlag; //导入依赖的package包/类
/**
 * Constructs a custom block and places it in the world.
 *
 * @param block The block location
 * @param cause The cause
 * @return The wrapped block
 */
default T placeBlock(Block block, BlockChangeFlag flag, Cause cause) {
    Location<World> location = block.getLocation()
            .orElseThrow(() -> new IllegalStateException("Could not access the location of the provided block."));
    World world = location.getExtent();

    // Remove the previous custom block
    CustomItemLibrary.getInstance().getService().removeArmorStandsAt(block);

    location.setBlockType(CustomBlock.BLOCK_TYPE_CUSTOM, flag, cause);

    ArmorStand armorStand = createDummyArmorStand(block);
    Vector3d rotation = Vector3d.ZERO;

    if(isRotateHorizontally()) {
        Optional<Player> player = cause.first(Player.class);

        if(player.isPresent()) {
            Vector3d headRotation = player.get().getHeadRotation();
            double angle = Math.floorMod(180 + (int) Math.floor(headRotation.getY()), 360);
            angle += 45;
            angle = Math.floorMod((int) Math.floor(angle), 360);
            angle = (int) (angle / 90);
            angle = angle * 90;
            rotation = Vector3d.from(0, angle, 0);
        }
    }

    armorStand.offer(createDefaultCustomFeatureData());
    armorStand.offer(new CustomBlockData());
    armorStand.setRotation(rotation);

    world.spawnEntity(armorStand, cause);

    T result = customizeBlock(block, armorStand, cause);

    result.setModel(getDefaultModel());
    CustomItemLibrary.getInstance().getService().registerBlockAsLoaded(result);

    return result;
}
 
开发者ID:Limeth,项目名称:CustomItemLibrary,代码行数:48,代码来源:CustomBlockDefinition.java

示例9: plantTree

import org.spongepowered.api.world.BlockChangeFlag; //导入依赖的package包/类
private void plantTree(ExplosionEvent.Pre event) {
    Location explosionLocation = event.getExplosion().getLocation();
    int x = (int) explosionLocation.getX();
    int y = (int) explosionLocation.getY();
    int z = (int) explosionLocation.getZ();

    //Evaluating the tree type, based on biome
    World world = event.getTargetWorld();
    BiomeType biome = world.getBiome(x, z);
    BiomeGenerationSettings biomeSettings = world.getWorldGenerator().getBiomeSettings(biome);
    List<Forest> forestPopulators = biomeSettings.getPopulators(Forest.class);

    PopulatorObject populator;
    try {
        //There may be multiple tree types in one Biome. Get one per weighted random
        populator = forestPopulators.isEmpty() ? fallbackTreePopulator : forestPopulators.get(0).getTypes().get(random).get(0);
    } catch (Exception e) {
        populator = fallbackTreePopulator;
    }

    //if the explosion happened on level 0, set it to 1, so we can place a dirt block below
    if (y == 0) {
        y = 1;
    }

    Vector3i pos = new Vector3i(x, y, z);
    Vector3i below = new Vector3i(x, y - 1, z);

    Cause genericCause = Cause.of(NamedCause.owner(container));


    //set Dirt block below if possible (Trees cannot be placed without)
    BlockState blockBelow = world.containsBlock(below) ? world.getBlock(below) : null;
    if (blockBelow != null) {
        BlockState blockState = BlockState.builder().blockType(BlockTypes.DIRT).build();

        world.setBlock(below, blockState, genericCause);
    }

    //Remove Grass, redstone, etc.
    BlockState blockOnPosition = world.getBlock(pos);

    Optional<PassableProperty> passableProperty_Op = blockOnPosition.getProperty(PassableProperty.class);
    boolean blockPassable = passableProperty_Op.isPresent() && passableProperty_Op.get().getValue();

    boolean passableBlockRemoved = false;
    if (blockPassable) {
        world.setBlock(pos, BlockState.builder().blockType(BlockTypes.AIR).build(), BlockChangeFlag.NEIGHBOR, genericCause);
        passableBlockRemoved = true;
    }

    boolean treePlaced = false;
    //is the tree placeable?
    if (populator.canPlaceAt(world, x, y, z)) {
        //Place the tree
        populator.placeObject(world, random, x, y, z);
        treePlaced = true;
    } else if (passableBlockRemoved) {
        //Reset passable Block
        world.setBlock(pos, blockOnPosition, genericCause);

    }

    //Replace block below with original Block (unless the tree was placed in mid-air or water)
    if (blockBelow != null && !(treePlaced && (blockBelow.getType() == BlockTypes.AIR ||
            blockBelow.getType() == BlockTypes.WATER ||
            blockBelow.getType() == BlockTypes.FLOWING_WATER))) {
        world.setBlock(below, blockBelow, genericCause);
    }
}
 
开发者ID:Felfio,项目名称:treepers-sponge,代码行数:71,代码来源:Treepers.java

示例10: map

import org.spongepowered.api.world.BlockChangeFlag; //导入依赖的package包/类
private void map(String id, BlockChangeFlag value) {
    this.mappings.put(id, value);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:4,代码来源:BlockChangeFlagRegistryModule.java

示例11: setBlock

import org.spongepowered.api.world.BlockChangeFlag; //导入依赖的package包/类
@Override
public boolean setBlock(int x, int y, int z, BlockState block, BlockChangeFlag flag) {
    checkRange(x, y, z);
    return this.extent.setBlock(x, y, z, block, flag);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:6,代码来源:SoftBufferExtentViewDownsize.java

示例12: restoreSnapshot

import org.spongepowered.api.world.BlockChangeFlag; //导入依赖的package包/类
@Override
public boolean restoreSnapshot(BlockSnapshot snapshot, boolean force, BlockChangeFlag flag) {
    final Vector3i position = snapshot.getPosition();
    checkRange(position);
    return this.extent.restoreSnapshot(snapshot, force, flag);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:7,代码来源:SoftBufferExtentViewDownsize.java

示例13: restoreSnapshot

import org.spongepowered.api.world.BlockChangeFlag; //导入依赖的package包/类
@Override
public boolean restoreSnapshot(int x, int y, int z, BlockSnapshot snapshot, boolean force, BlockChangeFlag flag) {
    checkRange(x, y, z);
    return this.extent.restoreSnapshot(x, y, z, snapshot, force, flag);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:6,代码来源:ExtentViewDownsize.java

示例14: restoreSnapshot

import org.spongepowered.api.world.BlockChangeFlag; //导入依赖的package包/类
@Override
default boolean restoreSnapshot(BlockSnapshot snapshot, boolean force, BlockChangeFlag flag) {
    final Location<World> location = checkNotNull(snapshot, "snapshot").getLocation().orElse(null);
    checkArgument(location != null, "location is not present in snapshot");
    return restoreSnapshot(location.getBlockPosition(), snapshot, force, flag);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:7,代码来源:AbstractExtent.java

示例15: andFlag

import org.spongepowered.api.world.BlockChangeFlag; //导入依赖的package包/类
@Override
public LanternBlockChangeFlag andFlag(BlockChangeFlag flag) {
    checkNotNull(flag, "flag");
    return andFlag(((LanternBlockChangeFlag) flag).flags);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:6,代码来源:LanternBlockChangeFlag.java


注:本文中的org.spongepowered.api.world.BlockChangeFlag类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。