本文整理汇总了Java中org.spongepowered.api.block.BlockSnapshot.NONE属性的典型用法代码示例。如果您正苦于以下问题:Java BlockSnapshot.NONE属性的具体用法?Java BlockSnapshot.NONE怎么用?Java BlockSnapshot.NONE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.spongepowered.api.block.BlockSnapshot
的用法示例。
在下文中一共展示了BlockSnapshot.NONE属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDoubleBlockLocation
/**
* Compare block with surrounding blocks - returning one with the same type if they're associated using CONNECTED_DIRECTIONS or PORTION_TYPE data
*
* @param block The BlockSnapshot of the block we're checking for a double of
* @return The potential location of a double block
*/
public static Optional<Location<World>> getDoubleBlockLocation(BlockSnapshot block) {
if (block != BlockSnapshot.NONE && block.getLocation().isPresent()) {
//Get all directions we need to evaluate -- doors don't have CONNECTED_DIRECTIONS just PORTION_TYPEs
Set<Direction> directionsToInvestigate = block.get(Keys.CONNECTED_DIRECTIONS).isPresent() ? new HashSet<>(block.get(Keys.CONNECTED_DIRECTIONS).get()) : new HashSet<>();
block.getLocation().get().getExtent().getTileEntity(block.getLocation().get().getBlockPosition())
.ifPresent(tileEntity1 -> directionsToInvestigate.addAll(tileEntity1.get(Keys.CONNECTED_DIRECTIONS).orElse(ImmutableSet.of())));
block.get(Keys.PORTION_TYPE)
.map(p -> p == PortionTypes.BOTTOM ? directionsToInvestigate.add(Direction.UP) : directionsToInvestigate.add(Direction.DOWN));
for (Direction direction : directionsToInvestigate) {
if (block.getLocation().get().getBlockRelative(direction).getBlock().getType() == block.getState().getType()) {
return Optional.of(block.getLocation().get().getBlockRelative(direction));
}
}
}
return Optional.empty();
}
示例2: onInteract
/***
* A method to listen to right click block interaction events
* @param event the event object
* @param player the player who fired it
*/
@Listener
public void onInteract(InteractBlockEvent.Secondary.MainHand event, @Root Player player) {
if (!player.hasPermission(Permissions.PLAYER_SELECT_REGION))
return;
Optional<ItemStack> item = player.getItemInHand(HandTypes.MAIN_HAND);
if (item.isPresent() && item.get().getItem().equals(ItemTypes.BLAZE_ROD) && event.getTargetBlock() != BlockSnapshot.NONE) {
get(player).setPos2(event.getTargetBlock().getPosition());
player.sendMessage(Text.of(TextColors.LIGHT_PURPLE, "Position 2 set to " + event.getTargetBlock().getPosition()));
event.setCancelled(true);
}
}
示例3: onBlockInteract
@Listener
public void onBlockInteract(InteractBlockEvent event, @First Player player) {
HandType hand = Utils.getEventHand(event);
BlockSnapshot blockSnapshot = event.getTargetBlock();
if (blockSnapshot == BlockSnapshot.NONE) {
return;
}
CustomWorld world = WorldManager.toCustomWorld(player.getWorld());
Vector3i pos = blockSnapshot.getPosition();
BlockNature block = world.getBlock(pos);
if (block == null) {
return;
}
Direction side = event.getTargetSide();
Vector3d point = event.getInteractionPoint().orElse(null);
boolean allowInteract = !event.isCancelled();
if (event instanceof InteractBlockEvent.Primary) {
allowInteract = block.onBlockHit(world, pos, player, hand, side, point);
} else if (event instanceof InteractBlockEvent.Secondary) {
if (player.getItemInHand(hand).isPresent() && player.get(Keys.IS_SNEAKING).get()) {
// Pass on the item click without telling the block
allowInteract = true;
} else {
allowInteract = block.onBlockActivated(world, pos, player, hand, side, point);
}
}
event.setCancelled(!allowInteract);
}
示例4: onPlayerInteractInventoryOpen
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteractInventoryOpen(InteractInventoryEvent.Open event, @First Player player) {
if (!GPFlags.INTERACT_INVENTORY || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
return;
}
GPTimings.PLAYER_INTERACT_INVENTORY_OPEN_EVENT.startTimingIfSync();
final Cause cause = event.getCause();
final EventContext context = cause.getContext();
final BlockSnapshot blockSnapshot = context.get(EventContextKeys.BLOCK_HIT).orElse(BlockSnapshot.NONE);
if (blockSnapshot == BlockSnapshot.NONE) {
GPTimings.PLAYER_INTERACT_INVENTORY_OPEN_EVENT.stopTimingIfSync();
return;
}
final Location<World> location = blockSnapshot.getLocation().get();
final GPClaim claim = this.dataStore.getClaimAt(location);
final GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
if (playerData.lastInteractItemBlockResult == Tristate.TRUE) {
GPTimings.PLAYER_INTERACT_INVENTORY_OPEN_EVENT.stopTimingIfSync();
return;
}
final Tristate result = GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.INVENTORY_OPEN, player, blockSnapshot, player, TrustType.CONTAINER, true);
if (result == Tristate.FALSE) {
Text message = GriefPreventionPlugin.instance.messageData.permissionInventoryOpen
.apply(ImmutableMap.of(
"owner", claim.getOwnerName(),
"block", blockSnapshot.getState().getType().getId())).build();
GriefPreventionPlugin.sendClaimDenyMessage(claim, player, message);
((EntityPlayerMP) player).closeScreen();
event.setCancelled(true);
}
GPTimings.PLAYER_INTERACT_INVENTORY_OPEN_EVENT.stopTimingIfSync();
}