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


Java BlockState类代码示例

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


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

示例1: performRemoval

import org.spongepowered.api.block.BlockState; //导入依赖的package包/类
private void performRemoval(LookupLine line) {
	World w = Sponge.getServer().getWorld(line.getWorld()).orElse(null);
	if (w == null) return;
	
	if (line.getTarget() instanceof ItemType) {
		
		Optional<TileEntity> te = w.getTileEntity(line.getPos());
		if (te.isPresent() && te.get() instanceof TileEntityCarrier) {
			TileEntityCarrier c = (TileEntityCarrier) te.get();
			Inventory i = c.getInventory();
			
			Inventory slot = i.query(new SlotIndex(line.getSlot()));
			slot.set(ItemStack.of(ItemTypes.NONE, 0));
		}
		
	} else if (line.getTarget() instanceof BlockType) {
		
		BlockState block = BlockState.builder().blockType(BlockTypes.AIR).build();
		w.setBlock(line.getPos(), block, Cause.source(container).build());
		
	}
}
 
开发者ID:Karanum,项目名称:AdamantineShield,代码行数:23,代码来源:RollbackManager.java

示例2: DeviceOff

import org.spongepowered.api.block.BlockState; //导入依赖的package包/类
public DeviceOff(Player player, Location<World> sign) throws ExceptionInInitializerError {
	super(sign);
	if (!player.hasPermission("carrotshop.create.device"))
		throw new ExceptionInInitializerError("You don't have perms to build a device sign");
	Stack<Location<World>> locations = ShopsData.getItemLocations(player);
	if (locations.isEmpty())
		throw new ExceptionInInitializerError("Device signs require a lever");
	BlockState targetBlock = locations.peek().getBlock();
	if (!targetBlock.getType().equals(BlockTypes.LEVER))
		throw new ExceptionInInitializerError("Device signs require a lever");

	lever = locations.peek();

	if (CarrotShop.getEcoService() != null) {
		price = getPrice(sign);
		if (price < 0)
			throw new ExceptionInInitializerError("bad price");
	}

	ShopsData.clearItemLocations(player);
	player.sendMessage(Text.of(TextColors.DARK_GREEN, "You have setup a device sign:"));
	done(player);
	info(player);
}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:25,代码来源:DeviceOff.java

示例3: Toggle

import org.spongepowered.api.block.BlockState; //导入依赖的package包/类
public Toggle(Player player, Location<World> sign) throws ExceptionInInitializerError {
	super(sign);
	if (!player.hasPermission("carrotshop.create.device"))
		throw new ExceptionInInitializerError("You don't have perms to build a device sign");
	Stack<Location<World>> locations = ShopsData.getItemLocations(player);
	if (locations.isEmpty())
		throw new ExceptionInInitializerError("Device signs require a lever");
	BlockState targetBlock = locations.peek().getBlock();
	if (!targetBlock.getType().equals(BlockTypes.LEVER))
		throw new ExceptionInInitializerError("Device signs require a lever");

	lever = locations.peek();

	if (CarrotShop.getEcoService() != null) {
		price = getPrice(sign);
		if (price < 0)
			throw new ExceptionInInitializerError("bad price");
	}

	ShopsData.clearItemLocations(player);
	player.sendMessage(Text.of(TextColors.DARK_GREEN, "You have setup a device sign:"));
	done(player);
	info(player);
}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:25,代码来源:Toggle.java

示例4: DeviceOn

import org.spongepowered.api.block.BlockState; //导入依赖的package包/类
public DeviceOn(Player player, Location<World> sign) throws ExceptionInInitializerError {
	super(sign);
	if (!player.hasPermission("carrotshop.create.device"))
		throw new ExceptionInInitializerError("You don't have perms to build a device sign");
	Stack<Location<World>> locations = ShopsData.getItemLocations(player);
	if (locations.isEmpty())
		throw new ExceptionInInitializerError("Device signs require a lever");
	BlockState targetBlock = locations.peek().getBlock();
	if (!targetBlock.getType().equals(BlockTypes.LEVER))
		throw new ExceptionInInitializerError("Device signs require a lever");

	lever = locations.peek();

	if (CarrotShop.getEcoService() != null) {
		price = getPrice(sign);
		if (price < 0)
			throw new ExceptionInInitializerError("bad price");
	}

	ShopsData.clearItemLocations(player);
	player.sendMessage(Text.of(TextColors.DARK_GREEN, "You have setup a device sign:"));
	done(player);
	info(player);
}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:25,代码来源:DeviceOn.java

示例5: checkPhysicalLobbySign

import org.spongepowered.api.block.BlockState; //导入依赖的package包/类
@Override
protected int checkPhysicalLobbySign(Location3D loc) {
    if (loc.getWorld().isPresent()) {
        Optional<World> world = Sponge.getGame().getServer().getWorld(loc.getWorld().get());

        if (world.isPresent()) {
            BlockState blockState = world.get().getBlock(LocationConverter.floor(loc));

            if (blockState.getType() == BlockTypes.STANDING_SIGN
                    || blockState.getType() == BlockTypes.WALL_SIGN) {
                return 0;
            } else {
                InfernoCore.logWarning("Found lobby sign with location not containing a sign block. Removing...");
                return 2;
            }
        } else {
            InfernoCore.logVerbose("Cannot load world \"" + loc.getWorld().get()
                    + "\" - not loading contained lobby sign");
            return 1;
        }
    } else {
        InfernoCore.logWarning("Found lobby sign in store with invalid location serial. Removing...");
        return 2;
    }
}
 
开发者ID:caseif,项目名称:Inferno,代码行数:26,代码来源:InfernoMinigame.java

示例6: onInteractBlockPrimaryMain

import org.spongepowered.api.block.BlockState; //导入依赖的package包/类
@Listener
public void onInteractBlockPrimaryMain(InteractBlockEvent.Primary event, @Root Player player) {
    Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
    if(itemStackOptional.isPresent()) {

        BlockState blockState = event.getTargetBlock().getState();
        String blockTypeId = blockState.getType().getId();
        String blockStateId = blockState.getId();

        ItemType itemType = itemStackOptional.get().getType();
        String itemId = itemType.getId();

        PermHandler ph = PermHandler.getInstance();

        if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on." + blockTypeId + ".primary",
                "protectionperms.item.use." + itemId + ".on." + blockStateId + ".primary")) {
            event.setCancelled(true);
            player.sendMessage(ChatTypes.ACTION_BAR,
                    Text.of(TextColors.RED, "You don't have permission to primary use " + itemType.getName() + " on " + blockState.getName() + '!'));
        }
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:23,代码来源:PrimaryBlockListener.java

示例7: onInteractBlockSecondaryMain

import org.spongepowered.api.block.BlockState; //导入依赖的package包/类
@Listener
public void onInteractBlockSecondaryMain(InteractBlockEvent.Secondary event, @Root Player player) {
    Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
    if(itemStackOptional.isPresent()) {

        BlockState blockState = event.getTargetBlock().getState();
        String blockTypeId = blockState.getType().getId();
        String blockStateId = blockState.getId();

        ItemType itemType = itemStackOptional.get().getType();
        String itemId = itemType.getId();

        PermHandler ph = PermHandler.getInstance();

        if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on." + blockTypeId + ".secondary",
                "protectionperms.item.use." + itemId + ".on." + blockStateId + ".secondary")) {
            event.setCancelled(true);
            player.sendMessage(ChatTypes.ACTION_BAR,
                    Text.of(TextColors.RED, "You don't have permission to secondary use " + itemType.getName() + " on " + blockState.getName() + '!'));
        }
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:23,代码来源:SecondaryBlockListener.java

示例8: onBlockPlace

import org.spongepowered.api.block.BlockState; //导入依赖的package包/类
@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @Root Player player) {
    List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
    for (Transaction<BlockSnapshot> transaction : transactions) {

        BlockSnapshot snapshot = transaction.getFinal();
        BlockState blockState = snapshot.getState();
        String blockTypeId = blockState.getType().getId();
        String blockStateId = blockState.getId();

        PermHandler ph = PermHandler.getInstance();

        if (!ph.checkPerm(player, "protectionperms.block.place." + blockTypeId,
                "protectionperms.block.place." + blockStateId)) {
            event.setCancelled(true);
            player.sendMessage(ChatTypes.ACTION_BAR,
                    Text.of(TextColors.RED, "You don't have permission to place " + blockState.getName() + '!'));
            break;
        }
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:22,代码来源:PlaceListener.java

示例9: onBlockBreak

import org.spongepowered.api.block.BlockState; //导入依赖的package包/类
@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @Root Player player) {
    List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
    for (Transaction<BlockSnapshot> transaction : transactions) {

        BlockSnapshot snapshot = transaction.getOriginal();
        BlockState blockState = snapshot.getState();
        String blockTypeId = blockState.getType().getId();
        String blockStateId = blockState.getId();

        PermHandler ph = PermHandler.getInstance();

        if (!ph.checkPerm(player, "protectionperms.block.break." + blockTypeId,
                "protectionperms.block.break." + blockStateId)) {
            event.setCancelled(true);
            player.sendMessage(ChatTypes.ACTION_BAR,
                    Text.of(TextColors.RED, "You don't have permission to break " + blockState.getName() + '!'));
            break;
        }
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:22,代码来源:BreakListener.java

示例10: onInteractBlockSecondary

import org.spongepowered.api.block.BlockState; //导入依赖的package包/类
@Listener
public void onInteractBlockSecondary(InteractBlockEvent.Secondary event, @Root Player player) {

    BlockState blockState = event.getTargetBlock().getState();
    String blockTypeId = blockState.getType().getId();
    String blockStateId = blockState.getId();

    PermHandler ph = PermHandler.getInstance();

    if (!ph.checkPerm(player, "protectionperms.block.interact." + blockTypeId + ".secondary",
            "protectionperms.block.interact." + blockStateId + ".secondary")) {
        event.setCancelled(true);
        player.sendMessage(ChatTypes.ACTION_BAR,
                Text.of(TextColors.RED, "You don't have permission to secondary interact with " + blockState.getName() + '!'));
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:17,代码来源:SecondaryListener.java

示例11: onInteractBlockPrimary

import org.spongepowered.api.block.BlockState; //导入依赖的package包/类
@Listener
public void onInteractBlockPrimary(InteractBlockEvent.Primary event, @Root Player player) {

    BlockState blockState = event.getTargetBlock().getState();
    String blockTypeId = blockState.getType().getId();
    String blockStateId = blockState.getId();

    PermHandler ph = PermHandler.getInstance();

    if (!ph.checkPerm(player, "protectionperms.block.interact." + blockTypeId + ".primary",
            "protectionperms.block.interact." + blockStateId + ".primary")) {
        event.setCancelled(true);
        player.sendMessage(ChatTypes.ACTION_BAR,
                Text.of(TextColors.RED, "You don't have permission to primary interact with " + blockState.getName() + '!'));
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:17,代码来源:PrimaryListener.java

示例12: getDefaultObjectMapper

import org.spongepowered.api.block.BlockState; //导入依赖的package包/类
private ObjectMapper getDefaultObjectMapper(boolean xml, boolean details, TreeNode<String, Boolean> perms) {
    if (perms == null) {
        throw new NullPointerException("Permissions may not be null");
    }

    ObjectMapper om = xml ? new XmlMapper() : new ObjectMapper();
    om.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    SimpleModule mod = new SimpleModule();
    for (Map.Entry<Class, BaseSerializer> entry : serializers.entrySet()) {
        mod.addSerializer(entry.getKey(), entry.getValue());
    }
    mod.addDeserializer(ItemStack.class, new ItemStackDeserializer());
    mod.addDeserializer(BlockState.class, new BlockStateDeserializer());
    mod.addDeserializer(ItemStackSnapshot.class, new ItemStackSnapshotDeserializer());
    mod.addDeserializer(Location.class, new LocationDeserializer());
    om.registerModule(mod);

    SimpleFilterProvider filterProvider = new SimpleFilterProvider();
    filterProvider.addFilter(BaseFilter.ID, new BaseFilter(details, perms));
    om.setFilterProvider(filterProvider);

    om.setAnnotationIntrospector(new AnnotationIntrospector(details));

    return om;
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:27,代码来源:SerializeService.java

示例13: getSurrounding

import org.spongepowered.api.block.BlockState; //导入依赖的package包/类
public List<BlockState> getSurrounding(Location<World> location){
    List<BlockState> blockStates = new ArrayList<BlockState>(){
        @Override
        public boolean add(BlockState blockState) {
            if(blockState != null) {
                return super.add(blockState);
            }
            return false;
        }
    };

    if (location.getY() != 256){
        blockStates.add(location.getRelative(Direction.UP).getBlock());
    }
    if (location.getY() != 0){
        blockStates.add(location.getRelative(Direction.DOWN).getBlock());
    }
    for (Direction direction : directions) {
            blockStates.add(location.getRelative(direction).getBlock());
    }
    if (blockStates.size() < 5){
        System.out.println("WARNING FAULTY CODE: " + blockStates + " " + location);
    }
    return blockStates;
}
 
开发者ID:thomas15v,项目名称:NoXray,代码行数:26,代码来源:NetworkBlockContainer.java

示例14: SimpleCustomBlockDefinition

import org.spongepowered.api.block.BlockState; //导入依赖的package包/类
private SimpleCustomBlockDefinition(PluginContainer pluginContainer, String typeId,
                                    @NonNull CorrectToolPredicate correctToolPredicate, double hardness,
                                    @NonNull BlockState effectState, @NonNull DropProvider dropProvider,
                                    String defaultModel, Iterable<String> additionalModels,
                                    Iterable<String> additionalAssets, boolean rotateHorizontally,
                                    boolean generateDamageIndicatorModels, Consumer<SimpleCustomBlock> onUpdate) {
    super(pluginContainer, typeId, defaultModel, additionalModels, effectState, rotateHorizontally, generateDamageIndicatorModels, onUpdate);

    this.assets = ImmutableSet.<String>builder()
            .addAll(getModels().stream()
                    .map(SimpleCustomBlockDefinition::getModelPath)
                    .collect(Collectors.toSet()))
            .addAll(Util.removeNull(additionalAssets)
                    .collect(Collectors.toSet()))
            .build();
    this.correctToolPredicate = correctToolPredicate;
    this.hardness = hardness;
    this.dropProvider = dropProvider;
}
 
开发者ID:Limeth,项目名称:CustomItemLibrary,代码行数:20,代码来源:SimpleCustomBlockDefinition.java

示例15: moveInternalEntities

import org.spongepowered.api.block.BlockState; //导入依赖的package包/类
private void moveInternalEntities() {
    CustomWorld world = WorldManager.toCustomWorld(this.world);
    if (createInternalEntities(world)) {
        if (this.isSpawned) {
            // Re-attach passenger (some strange bug)
            this.block.spawn(WorldManager.SPAWN_CAUSE);
        }
        // positions
        this.block.getStand().setLocation(this.block.getStand().getLocation().setPosition(this.pos));
        this.pickaxeStand.setLocation(this.pickaxeStand.getLocation().setPosition(getPickaxePos()));

        // rotations
        BlockState blockState = this.block.getEntity().get(Keys.FALLING_BLOCK_STATE).get();
        Direction prevDir = blockState.get(Keys.DIRECTION).get();
        if (prevDir != Utils.rotationToDirection(this.rotation.getY())) {
            world.removeEntityFromTracker(this.block.getEntity(), this);
            this.block.setEntity(null, true);
            createInternalEntities(world);
            if (this.isSpawned) {
                this.block.spawn(WorldManager.SPAWN_CAUSE);
            }
        }
        this.pickaxeStand.setRotation(getPickaxeRot());
    }
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:26,代码来源:TurtleEntity.java


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