本文整理汇总了Java中org.spongepowered.api.world.Location.setBlock方法的典型用法代码示例。如果您正苦于以下问题:Java Location.setBlock方法的具体用法?Java Location.setBlock怎么用?Java Location.setBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.world.Location
的用法示例。
在下文中一共展示了Location.setBlock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: replaceWith
import org.spongepowered.api.world.Location; //导入方法依赖的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);
}
示例2: open
import org.spongepowered.api.world.Location; //导入方法依赖的package包/类
@Override
public void open(Player player, Manager manager) {
PlayerOpenCrateEvent open_event = new PlayerOpenCrateEvent(player, manager);
Sponge.getEventManager().post(open_event);
if (open_event.isCancelled()) return;
Location<World> location = player.getLocation();
Vector3i position = player.getLocation().getBlockPosition();
World world = location.getExtent();
int loc_x = position.getX();
int loc_y = position.getY();
int loc_z = position.getZ();
HashMap<Location<World>, BlockState> original_block_states = new HashMap<Location<World>, BlockState>();
for (int x = -2; x <= 2; x++) {
for (int y = -1; y <= 3; y++) {
for (int z = -2; z <= 2; z++) {
Location loc = new Location<World>(
world, loc_x + x, loc_y + y, loc_z + z);
BlockState loc_state = loc.getBlock();
original_block_states.put(loc, loc_state);
location.setBlockType(BlockTypes.AIR, BlockChangeFlags.NONE);
}
}
}
for (int x = -2; x <= 2; x++) {
for (int z = -2; z <= 2; z++) {
new Location<World>(world, loc_x + x, loc_y - 1, loc_z + z).
setBlockType(floor_block_type, BlockChangeFlags.NONE);
if (z == 2 || z == -2 || x == 2 || x == -2) {
new Location<World>(world, loc_x + x, loc_y , loc_z + z).
setBlockType(fence_block_type, BlockChangeFlags.NONE);
}
}
}
HashSet<HologramsService.Hologram> holograms = new HashSet<HologramsService.Hologram>();
Location<World> loc1 = new Location<World>(world, loc_x + 2, loc_y, loc_z);
loc1.setBlock(BlockState.builder().
blockType(crate_block_type).
add(Keys.DIRECTION, Direction.WEST).
build(),
BlockChangeFlags.NONE);
Location<World> loc2 = new Location<World>(world, loc_x - 2, loc_y, loc_z);
loc2.setBlock(BlockState.builder().
blockType(crate_block_type).
add(Keys.DIRECTION, Direction.EAST).
build(),
BlockChangeFlags.NONE);
Location<World> loc3 = new Location<World>(world, loc_x, loc_y, loc_z + 2);
loc3.setBlock(BlockState.builder().
blockType(crate_block_type).
add(Keys.DIRECTION, Direction.NORTH).
build(),
BlockChangeFlags.NONE);
Location<World> loc4 = new Location<World>(world, loc_x, loc_y, loc_z - 2);
loc4.setBlock(BlockState.builder().
blockType(crate_block_type).
add(Keys.DIRECTION, Direction.SOUTH).
build(),
BlockChangeFlags.NONE);
Utils.tryCreateHologram(loc1, hologram).ifPresent(holograms::add);
Utils.tryCreateHologram(loc2, hologram).ifPresent(holograms::add);
Utils.tryCreateHologram(loc3, hologram).ifPresent(holograms::add);
Utils.tryCreateHologram(loc4, hologram).ifPresent(holograms::add);
getOpenSound().ifPresent(sound -> player.playSound(sound, player.getLocation().getPosition(), 1.));
PLAYERS_OPENING_ANIMATION1.put(player, new Information(this, manager,
new HashMap<Location<World>, Boolean>(){{
put(loc1, false);
put(loc2, false);
put(loc3, false);
put(loc4, false);
}}, original_block_states, holograms));
}