本文整理汇总了Java中org.spongepowered.api.util.Direction类的典型用法代码示例。如果您正苦于以下问题:Java Direction类的具体用法?Java Direction怎么用?Java Direction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Direction类属于org.spongepowered.api.util包,在下文中一共展示了Direction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isSignAndShop
import org.spongepowered.api.util.Direction; //导入依赖的package包/类
private boolean isSignAndShop(Location<World> loc, Direction dir, boolean wall) {
if (loc.getRelative(dir).getBlockType() == (wall ? BlockTypes.WALL_SIGN : BlockTypes.STANDING_SIGN)) {
if (wall) {
Location<World> sign = loc.getRelative(dir);
if (sign.supports(Keys.DIRECTION)) {
Optional<Direction> direction = sign.get(Keys.DIRECTION);
if (direction.isPresent()) {
if (direction.get() != dir)
return false;
}
}
}
Optional<List<Shop>> shops = ShopsData.getShops(loc.getRelative(dir));
if (shops.isPresent())
return true;
}
return false;
}
示例2: findPartnerBlock
import org.spongepowered.api.util.Direction; //导入依赖的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();
}
示例3: getDoubleBlockLocation
import org.spongepowered.api.util.Direction; //导入依赖的package包/类
/**
* 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();
}
示例4: onPreBlockChange
import org.spongepowered.api.util.Direction; //导入依赖的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);
}
}
}
示例5: getSurrounding
import org.spongepowered.api.util.Direction; //导入依赖的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;
}
示例6: addTarget
import org.spongepowered.api.util.Direction; //导入依赖的package包/类
public void addTarget(BlockSnapshot pistonBlock, EnhancedCustomBlock block, BlockData blockData,
Vector3i blockPos) {
Direction pistonFacing = pistonBlock.getState().get(Keys.DIRECTION).get();
boolean isRetracting;
if (pistonBlock.getState().getType() == BlockTypes.PISTON_EXTENSION) {
// Followed up from sticky piston - retraction has cause of the piston extension
// See CustomBlockEventListeners#getPistonCause
isRetracting = true;
} else {
isRetracting = pistonBlock.getState().get(Keys.EXTENDED).get();
}
Vector3i destPos;
if (isRetracting) {
destPos = blockPos.sub(pistonFacing.asBlockOffset());
} else {
destPos = blockPos.add(pistonFacing.asBlockOffset());
}
this.locations.put(destPos, new Tuple<>(blockPos, new ImmutablePair<>(block, blockData)));
}
示例7: moveInternalEntities
import org.spongepowered.api.util.Direction; //导入依赖的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());
}
}
示例8: getPickaxeRot
import org.spongepowered.api.util.Direction; //导入依赖的package包/类
private Vector3d getPickaxeRot() {
Direction facing = Utils.rotationToDirection(this.rotation.getY());
if (facing == Direction.NORTH) {
return new Vector3d(0, 180, 0);
}
if (facing == Direction.EAST) {
return new Vector3d(0, 270, 0);
}
if (facing == Direction.SOUTH) {
return Vector3d.ZERO;
}
if (facing == Direction.WEST) {
return new Vector3d(0, 90, 0);
}
return this.rotation;
}
示例9: getPickaxePos
import org.spongepowered.api.util.Direction; //导入依赖的package包/类
private Vector3d getPickaxePos() {
Direction facing = Utils.rotationToDirection(this.rotation.getY());
if (facing == Direction.NORTH) {
return this.pos.add(0.17, -0.7, 0.4);
}
if (facing == Direction.EAST) {
return this.pos.add(-0.4, -0.7, 0.17);
}
if (facing == Direction.SOUTH) {
return this.pos.add(-0.15, -0.7, -0.4);
}
if (facing == Direction.WEST) {
return this.pos.add(0.4, -0.7, -0.15);
}
return this.pos;
}
示例10: continueTravel
import org.spongepowered.api.util.Direction; //导入依赖的package包/类
@Override
public void continueTravel(PipeTileData data) {
if (this.itemStand == null || this.itemStand.isRemoved()) {
spawnItem(data.getWorld().getWorld());
}
if (this.itemStand == null) {
return;
}
if (!this.finish) {
if (this.dest == Direction.NONE || !this.reachedCenter) {
addPos(this.from.getOpposite().asOffset().mul(this.speed));
updateProgress(data.getPosition(), this.from.getOpposite(), true);
this.reachedCenter = this.finish;
if (this.dest != Direction.NONE) {
// We where heading somewhere, resume
this.finish = false;
}
} else {
addPos(this.dest.asOffset().mul(this.speed));
updateProgress(data.getPosition(), this.dest, false);
}
}
}
示例11: findDestination
import org.spongepowered.api.util.Direction; //导入依赖的package包/类
private Direction findDestination(Direction exclude) {
if (this.connections.isEmpty()) {
return Direction.NONE;
}
Iterator<Direction> itr = this.connections.keySet().iterator();
Direction known = Direction.NONE;
Random rand = new Random();
while (itr.hasNext()) {
Direction next = itr.next();
if (next != exclude) {
known = next;
if (rand.nextBoolean()) {
return known;
}
}
}
return known;
}
示例12: onItemUse
import org.spongepowered.api.util.Direction; //导入依赖的package包/类
@Override
public boolean onItemUse(ItemStack itemStack, Player player, HandType currHand, BlockSnapshot clickedBlock,
Direction side, Vector3d hitPoint) {
CustomWorld world = WorldManager.toCustomWorld(player.getWorld());
Vector3d pos;
if (hitPoint == null) {
pos = clickedBlock.getPosition().add(side.asBlockOffset()).toDouble().add(0.5, 0, 0.5);
} else {
pos = clickedBlock.getPosition().toDouble().add(hitPoint);
}
TurtleEntity turtle = new TurtleEntity(player.getWorld());
turtle.setPosition(pos);
Vector3d r = player.getHeadRotation();
turtle.setRotation(new Vector3d(r.getX(), r.getY() + 180, r.getZ()));
if (world.spawnEntity(turtle)) {
if (player.gameMode().get() != GameModes.CREATIVE) {
itemStack.setQuantity(itemStack.getQuantity() - 1);
if (itemStack.getQuantity() == 0) {
itemStack = null;
}
player.setItemInHand(currHand, itemStack);
}
}
return false;
}
示例13: PipeBlock
import org.spongepowered.api.util.Direction; //导入依赖的package包/类
public PipeBlock() {
this.pane = ItemStack.of(ItemTypes.STAINED_GLASS_PANE, 1);
Vector3d rotX = new Vector3d(90, 0, 0);
Vector3d rotY = new Vector3d(0, 90, 0);
this.entityStruct = new MultiEntityStructure.Builder()
.define(Direction.DOWN.name(), EntityTypes.ARMOR_STAND,
armorStandOffset(true, Axis.Z, new Vector3f(0.5, 0.2, 0.5)),
ArmorStand.class, stand -> setupArmorStand(stand, rotX))
.define(Direction.UP.name(), EntityTypes.ARMOR_STAND,
armorStandOffset(true, Axis.Z, new Vector3f(0.5, 0.7375, 0.5)),
ArmorStand.class, stand -> setupArmorStand(stand, rotX))
.define(Direction.NORTH.name(), EntityTypes.ARMOR_STAND,
armorStandOffset(false, Axis.Z, new Vector3f(0.5, 0.2, 0.2)),
ArmorStand.class, stand -> setupArmorStand(stand, null))
.define(Direction.SOUTH.name(), EntityTypes.ARMOR_STAND,
armorStandOffset(false, Axis.Z, new Vector3f(0.5, 0.2, 0.8)),
ArmorStand.class, stand -> setupArmorStand(stand, null))
.define(Direction.EAST.name(), EntityTypes.ARMOR_STAND,
armorStandOffset(false, Axis.X, new Vector3f(0.8, 0.2, 0.5)),
ArmorStand.class, stand -> setupArmorStand(stand, rotY))
.define(Direction.WEST.name(), EntityTypes.ARMOR_STAND,
armorStandOffset(false, Axis.X, new Vector3f(0.2, 0.2, 0.5)),
ArmorStand.class, stand -> setupArmorStand(stand, rotY))
.build();
}
示例14: onBlockNotify
import org.spongepowered.api.util.Direction; //导入依赖的package包/类
@Listener
public void onBlockNotify(NotifyNeighborBlockEvent event, @First BlockSnapshot notifySource) {
Optional<Location<World>> loc = notifySource.getLocation();
if (!loc.isPresent()) {
return;
}
Vector3i origin = loc.get().getBlockPosition();
CustomWorld world = WorldManager.toCustomWorld(loc.get().getExtent());
for (Iterator<Entry<Direction, BlockState>> iterator = event.getNeighbors().entrySet().iterator(); iterator
.hasNext();) {
Direction side = iterator.next().getKey();
Vector3i notifyPos = origin.add(side.asBlockOffset());
BlockNature block = world.getBlock(notifyPos);
if (block != null) {
boolean allow =
block.onNeighborNotify(world, notifyPos, notifySource.getPosition(), side.getOpposite());
if (!allow) {
iterator.remove();
}
}
}
}
示例15: chunkLoadPostProcess
import org.spongepowered.api.util.Direction; //导入依赖的package包/类
private static void chunkLoadPostProcess(Chunk chunk) {
if (chunk != null) {
WorldServer world = (WorldServer) chunk.getWorld();
world.getChunkProvider().id2ChunkMap.put(ChunkPos.asLong(chunk.x, chunk.z), chunk);
org.spongepowered.api.world.Chunk spongeChunk = (org.spongepowered.api.world.Chunk) chunk;
for (Direction direction : CARDINAL_DIRECTIONS) {
Vector3i neighborPosition = spongeChunk.getPosition().add(direction.asBlockOffset());
IMixinChunkProviderServer spongeChunkProvider = (IMixinChunkProviderServer) world.getChunkProvider();
net.minecraft.world.chunk.Chunk neighbor = spongeChunkProvider.getLoadedChunkWithoutMarkingActive
(neighborPosition.getX(), neighborPosition.getZ());
if (neighbor != null) {
int neighborIndex = directionToIndex(direction);
int oppositeNeighborIndex = directionToIndex(direction.getOpposite());
((IMixinChunk) spongeChunk).setNeighborChunk(neighborIndex, neighbor);
((IMixinChunk) neighbor).setNeighborChunk(oppositeNeighborIndex, (net.minecraft.world.chunk.Chunk)(Object) chunk);
}
}
chunk.populate(world.getChunkProvider(), world.getChunkProvider().chunkGenerator);
}
}