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


Java BlockType类代码示例

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


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

示例1: performRemoval

import org.spongepowered.api.block.BlockType; //导入依赖的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: getCatalogType

import org.spongepowered.api.block.BlockType; //导入依赖的package包/类
private static CatalogType getCatalogType(String id, LookupType lookupType) throws CommandException {
	switch (lookupType) {
		case BLOCK_LOOKUP:
			Optional<BlockType> block = Sponge.getRegistry().getType(BlockType.class, id);
			if (block.isPresent())
				return block.get();
			throw new CommandException(Text.of(TextColors.RED, "Unknown block id: " + id));
		case ITEM_LOOKUP:
			Optional<ItemType> item = Sponge.getRegistry().getType(ItemType.class, id);
			if (item.isPresent())
				return item.get();
			throw new CommandException(Text.of(TextColors.RED, "Unknown item id: " + id));
		default:
			throw new CommandException(Text.of(TextColors.RED, "Could not determine lookup type!"));
	}
}
 
开发者ID:Karanum,项目名称:AdamantineShield,代码行数:17,代码来源:FilterParser.java

示例3: onLiquidFlow

import org.spongepowered.api.block.BlockType; //导入依赖的package包/类
@Listener(order = Order.POST)
public void onLiquidFlow(ChangeBlockEvent.Pre e) {
	if (e.getLocations().isEmpty()) return;
			
	Location<World> loc = e.getLocations().get(0);
	BlockSnapshot snapshot = loc.getExtent().createSnapshot(loc.getBlockPosition());
	
	Optional<MatterProperty> matter = snapshot.getState().getProperty(MatterProperty.class);
	if (matter.isPresent() && matter.get().getValue() == Matter.LIQUID) {
		String name = "Water";
		BlockType type = snapshot.getState().getType();
		if (type == BlockTypes.LAVA || type == BlockTypes.FLOWING_LAVA)
			name = "Lava";
		db.addToQueue(new BlockQueueEntry(snapshot, ActionType.FLOW, name, new Date().getTime()));
	}
}
 
开发者ID:Karanum,项目名称:AdamantineShield,代码行数:17,代码来源:LiquidFlowListener.java

示例4: findPartnerBlock

import org.spongepowered.api.block.BlockType; //导入依赖的package包/类
/**
 * Find a matching partner block. Must be the same type
 * and in one of the four cardinal directions.
 *
 * @param location Location of source block.
 * @return Optional Location of partner.
 */
public static Optional<Location<World>> findPartnerBlock(Location<World> location) {
    BlockType type = location.getBlockType();

    Location<World> north = location.getRelative(Direction.NORTH);
    if (north.getBlockType().equals(type)) {
        return Optional.of(north);
    }

    Location<World> west = location.getRelative(Direction.WEST);
    if (west.getBlockType().equals(type)) {
        return Optional.of(west);
    }

    Location<World> south = location.getRelative(Direction.SOUTH);
    if (south.getBlockType().equals(type)) {
        return Optional.of(south);
    }

    Location<World> east = location.getRelative(Direction.EAST);
    if (east.getBlockType().equals(type)) {
        return Optional.of(east);
    }

    return Optional.empty();
}
 
开发者ID:prism,项目名称:Keys,代码行数:33,代码来源:WorldUtil.java

示例5: getColor

import org.spongepowered.api.block.BlockType; //导入依赖的package包/类
private TextColor getColor(BlockType type) {
    TextColor color = TextColors.WHITE;

    if (type.equals(BlockTypes.IRON_ORE)) {
        color = TextColors.GRAY;
    }
    else if (type.equals(BlockTypes.LAPIS_ORE)) {
        color = TextColors.BLUE;
    }
    else if (type.equals(BlockTypes.GOLD_ORE)) {
        color = TextColors.YELLOW;
    }
    else if (type.equals(BlockTypes.EMERALD_ORE)) {
        color = TextColors.GREEN;
    }
    else if (type.equals(BlockTypes.DIAMOND_ORE)) {
        color = TextColors.AQUA;
    }

    return color;
}
 
开发者ID:prism,项目名称:OreAlerts,代码行数:22,代码来源:ChangeBlockBreakListener.java

示例6: Config

import org.spongepowered.api.block.BlockType; //导入依赖的package包/类
public Config(BetterKits instance) throws Exception {
	//load defaults
	URL defaultsInJarURL = CommonUtils.class.getResource("config.yml");
	YAMLConfigurationLoader defaultsLoader = YAMLConfigurationLoader.builder().setURL(defaultsInJarURL).build();
	ConfigurationNode defaults = defaultsLoader.load();

	//load config & merge defaults
	ConfigurationNode rootNode = instance.getConfigManager().load();
	rootNode.mergeValuesFrom(defaults);
	instance.getConfigManager().save(rootNode);
	
	for (String blockType : rootNode.getNode("AllowedChests").getList(TypeToken.of(String.class))) {
		Optional<BlockType> optType = Sponge.getRegistry().getType(BlockType.class, blockType);
		if (optType.isPresent()) {
			allowedChests.add(optType.get());
		} else {
			instance.logger().warn("BlockType "+blockType+" is not valid.");
		}
	}
	
	starterKitName = rootNode.getNode("StarterKit").getString("starter");
}
 
开发者ID:KaiKikuchi,项目名称:BetterKits,代码行数:23,代码来源:Config.java

示例7: onPreBlockChange

import org.spongepowered.api.block.BlockType; //导入依赖的package包/类
@Listener
public void onPreBlockChange(final ChangeBlockEvent.Pre event, @First LocatableBlock block) {
    final BlockType type = block.getBlockState().getType();

    if (type.equals(BlockTypes.PISTON) || type.equals(BlockTypes.STICKY_PISTON) || type.equals(BlockTypes.PISTON_EXTENSION) || type
        .equals(BlockTypes.PISTON_HEAD)) {
        //noinspection OptionalGetWithoutIsPresent
        final Location<World> location = block.getLocation().getBlockRelative(block.get(Keys.DIRECTION).get());

        final LockManager lockManager = Latch.getLockManager();

        if (lockManager.getLock(location).isPresent() || (lockManager.getLock(location.getBlockRelative(Direction.UP)).isPresent() && lockManager
            .isProtectBelowBlocks(location.getBlockRelative(Direction.UP).getBlockType()))) {
            event.setCancelled(true);
        }
    }
}
 
开发者ID:ichorpowered,项目名称:latch,代码行数:18,代码来源:ChangeBlockListener.java

示例8: getPistonCause

import org.spongepowered.api.block.BlockType; //导入依赖的package包/类
private static BlockSnapshot getPistonCause(Cause cause) {
    List<BlockSnapshot> blockCauses = cause.allOf(BlockSnapshot.class);
    for (BlockSnapshot blockCause : blockCauses) {
        BlockType type = blockCause.getState().getType();
        if (type == BlockTypes.PISTON || type == BlockTypes.STICKY_PISTON) {
            return blockCause;
        }
        if (type == BlockTypes.PISTON_EXTENSION
                && blockCause.getState().get(Keys.PISTON_TYPE).get() == PistonTypes.STICKY) {
            // For some reason, when a sticky piston is retracting, the cause is the extension
            // block
            return blockCause;
        }
    }
    return null;
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:17,代码来源:CustomBlockEventListeners.java

示例9: addTopLine

import org.spongepowered.api.block.BlockType; //导入依赖的package包/类
public void addTopLine(World world, int y, BlockType cornerMaterial, BlockType accentMaterial) {
    BlockSnapshot topVisualBlock1 =
            snapshotBuilder.from(new Location<World>(world, this.smallx, y, this.bigz)).blockState(cornerMaterial.getDefaultState()).build();
    newElements.add(new Transaction<BlockSnapshot>(topVisualBlock1.getLocation().get().createSnapshot(), topVisualBlock1));
    this.corners.add(topVisualBlock1.getPosition());
    BlockSnapshot topVisualBlock2 =
            snapshotBuilder.from(new Location<World>(world, this.smallx + 1, y, this.bigz)).blockState(accentMaterial.getDefaultState()).build();
    newElements.add(new Transaction<BlockSnapshot>(topVisualBlock2.getLocation().get().createSnapshot(), topVisualBlock2));
    BlockSnapshot topVisualBlock3 =
            snapshotBuilder.from(new Location<World>(world, this.bigx - 1, y, this.bigz)).blockState(accentMaterial.getDefaultState()).build();
    newElements.add(new Transaction<BlockSnapshot>(topVisualBlock3.getLocation().get().createSnapshot(), topVisualBlock3));

    if (STEP != 0) {
        for (int x = this.smallx + STEP; x < this.bigx - STEP / 2; x += STEP) {
            if ((y != 0 && x >= this.smallx && x <= this.bigx) || (x > this.minx && x < this.maxx)) {
                BlockSnapshot visualBlock =
                        snapshotBuilder.from(new Location<World>(world, x, y, this.bigz)).blockState(accentMaterial.getDefaultState()).build();
                newElements.add(new Transaction<BlockSnapshot>(visualBlock.getLocation().get().createSnapshot(), visualBlock));
            }
        }
    }
}
 
开发者ID:MinecraftPortCentral,项目名称:GriefPrevention,代码行数:23,代码来源:Visualization.java

示例10: addBottomLine

import org.spongepowered.api.block.BlockType; //导入依赖的package包/类
public void addBottomLine(World world, int y, BlockType cornerMaterial, BlockType accentMaterial) {
    BlockSnapshot bottomVisualBlock1 =
            this.snapshotBuilder.from(new Location<World>(world, this.smallx + 1, y, this.smallz)).blockState(accentMaterial.getDefaultState()).build();
    this.newElements.add(new Transaction<BlockSnapshot>(bottomVisualBlock1.getLocation().get().createSnapshot(), bottomVisualBlock1));
    this.corners.add(bottomVisualBlock1.getPosition());
    BlockSnapshot bottomVisualBlock2 =
            this.snapshotBuilder.from(new Location<World>(world, this.bigx - 1, y, this.smallz)).blockState(accentMaterial.getDefaultState()).build();
    this.newElements.add(new Transaction<BlockSnapshot>(bottomVisualBlock2.getLocation().get().createSnapshot(), bottomVisualBlock2));

    if (STEP != 0) {
        for (int x = this.smallx + STEP; x < this.bigx - STEP / 2; x += STEP) {
            if ((y != 0 && x >= this.smallx && x <= this.bigx) || (x > this.minx && x < this.maxx)) {
                BlockSnapshot visualBlock =
                        this.snapshotBuilder.from(new Location<World>(world, x, y, this.smallz)).blockState(accentMaterial.getDefaultState()).build();
                newElements.add(new Transaction<BlockSnapshot>(visualBlock.getLocation().get().createSnapshot(), visualBlock));
            }
        }
    }
}
 
开发者ID:MinecraftPortCentral,项目名称:GriefPrevention,代码行数:20,代码来源:Visualization.java

示例11: addRightLine

import org.spongepowered.api.block.BlockType; //导入依赖的package包/类
public void addRightLine(World world, int y, BlockType cornerMaterial, BlockType accentMaterial) {
    BlockSnapshot rightVisualBlock1 =
            snapshotBuilder.from(new Location<World>(world, this.bigx, y, this.smallz)).blockState(cornerMaterial.getDefaultState()).build();
    newElements.add(new Transaction<BlockSnapshot>(rightVisualBlock1.getLocation().get().createSnapshot(), rightVisualBlock1));
    this.corners.add(rightVisualBlock1.getPosition());
    BlockSnapshot rightVisualBlock2 =
            snapshotBuilder.from(new Location<World>(world, this.bigx, y, this.smallz + 1)).blockState(accentMaterial.getDefaultState()).build();
    newElements.add(new Transaction<BlockSnapshot>(rightVisualBlock2.getLocation().get().createSnapshot(), rightVisualBlock2));
    if (STEP != 0) {
        for (int z = this.smallz + STEP; z < this.bigz - STEP / 2; z += STEP) {
            if ((y != 0 && z >= this.smallz && z <= this.bigz) || (z > this.minz && z < this.maxz)) {
                BlockSnapshot visualBlock =
                        snapshotBuilder.from(new Location<World>(world, this.bigx, y, z)).blockState(accentMaterial.getDefaultState()).build();
                newElements.add(new Transaction<BlockSnapshot>(visualBlock.getLocation().get().createSnapshot(), visualBlock));
            }
        }
    }
    BlockSnapshot rightVisualBlock3 =
            snapshotBuilder.from(new Location<World>(world, this.bigx, y, this.bigz - 1)).blockState(accentMaterial.getDefaultState()).build();
    newElements.add(new Transaction<BlockSnapshot>(rightVisualBlock3.getLocation().get().createSnapshot(), rightVisualBlock3));
    BlockSnapshot rightVisualBlock4 =
            snapshotBuilder.from(new Location<World>(world, this.bigx, y, this.bigz)).blockState(cornerMaterial.getDefaultState()).build();
    newElements.add(new Transaction<BlockSnapshot>(rightVisualBlock4.getLocation().get().createSnapshot(), rightVisualBlock4));
    this.corners.add(rightVisualBlock4.getPosition());
}
 
开发者ID:MinecraftPortCentral,项目名称:GriefPrevention,代码行数:26,代码来源:Visualization.java

示例12: cleanup

import org.spongepowered.api.block.BlockType; //导入依赖的package包/类
public int cleanup() {
  Optional<World> optWorld = Sponge.getServer().getWorld(worldName);

  int total = 0;

  if (optWorld.isPresent()) {
    World world = optWorld.get();
    for (CachedRegion region : regionList) {
      List<RegionPoint> toRemove = new ArrayList<>();
      for (RegionPoint point : region.getFullPoints()) {
        BlockType type = world.getBlockType(point.toInt());
        if (type != CustomBlockTypes.REGION_MASTER && type != CustomBlockTypes.REGION_MARKER) {
          ++total;
          toRemove.add(point);
        }
      }
      region.remPoint(toRemove);
    }
  }

  return total;
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:23,代码来源:RegionManager.java

示例13: onBlockBreak

import org.spongepowered.api.block.BlockType; //导入依赖的package包/类
@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @First(typeFilter = Player.class) Player player) {
	if (event.isCancelled()) {
		return;
	}

	IActiveCharacter character = characterService.getCharacter(player.getUniqueId());
	for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
		BlockType type = transaction.getFinal().getState().getType();
		Double d = experienceService.getMinningExperiences(type);
		if (d != null) {
			characterService.addExperiences(character, d, ExperienceSource.MINING);
		} else {
			d = experienceService.getLoggingExperiences(type);
			if (d != null) {
				characterService.addExperiences(character, d, ExperienceSource.LOGGING);
			}
		}
	}
}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:21,代码来源:BasicListener.java

示例14: setLocalBlock

import org.spongepowered.api.block.BlockType; //导入依赖的package包/类
@Override
public void setLocalBlock(WarLocation location, WarBlock block) {
    Optional<Player> player = getPlayer();
    if (player.isPresent()) {
        BlockState state;
        BlockType type;
        String blockName = block.getBlockName();
        // attempt to make blocks from Bukkit variant usable.
        if (!blockName.contains(":")) {
            blockName = "minecraft:" + blockName.toLowerCase();
        }
        Optional<BlockType> typeo = plugin.getGame().getRegistry().getType(BlockType.class, blockName);
        if (!typeo.isPresent()) {
            throw new IllegalStateException("Failed to get block type for block " + block.getBlockName());
        }
        type = typeo.get();
        state = BlockState.builder().blockType(type).build();
        if (block.getData() == null && !block.getSerialized().isEmpty()) {
            DataContainer container = plugin.getTranslator().translateFrom(block.getSerialized());
            state = BlockState.builder().blockType(type).build(container).orElse(state);
        }
        player.get().sendBlockChange(location.getBlockX(), location.getBlockY(), location.getBlockZ(), state);
    }
}
 
开发者ID:cmastudios,项目名称:war-sponge,代码行数:25,代码来源:SpongeWarPlayer.java

示例15: changeBlock

import org.spongepowered.api.block.BlockType; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public void changeBlock(Boolean physics, BlockLoc block, BlockType type, byte data, Player player, ItemStack item)
{
  BlockBreakEvent breakEvent = new BlockBreakEvent(block, player);
  Bukkit.getPluginManager().callEvent(breakEvent);
  block.getWorld().playSound(block.getLocation(), SoundUtil.getSound(block.getType()), 0.2F, 1.0F);

  block.setTypeId(mat.getId(), physics.booleanValue());
  block.setData(data, physics.booleanValue());

  block.getWorld().playSound(block.getLocation(), SoundUtil.getSound(block.getType()), 1.0F, 1.0F);

  BlockPlaceEvent placeEvent = new BlockPlaceEvent(block, block.getState(), block, item, player, true);
  Bukkit.getPluginManager().callEvent(placeEvent);

  if (!physics.booleanValue())
  {
    updateBlockChange(block);
  }
}
 
开发者ID:Zingalicious,项目名称:ToolmanSponge,代码行数:21,代码来源:AbstractTool.java


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