Java Code Examples for cn.nukkit.math.BlockFace#UP
The following examples show how to use
cn.nukkit.math.BlockFace#UP .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockFlowerPot.java From Jupiter with GNU General Public License v3.0 | 6 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { if (face != BlockFace.UP) return false; CompoundTag nbt = new CompoundTag() .putString("id", BlockEntity.FLOWER_POT) .putInt("x", (int) this.x) .putInt("y", (int) this.y) .putInt("z", (int) this.z) .putShort("item", 0) .putInt("data", 0); if (item.hasCustomBlockData()) { for (Tag aTag : item.getCustomBlockData().getAllTags()) { nbt.put(aTag.getName(), aTag); } } new BlockEntityFlowerPot(getLevel().getChunk((int) block.x >> 4, (int) block.z >> 4), nbt); this.getLevel().setBlock(block, this, true, true); return true; }
Example 2
Source File: BlockPistonBase.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public static boolean canPush(Block block, BlockFace face, boolean destroyBlocks) { if (!block.canBePushed()) { return false; } else if (block.getY() >= 0 && (face != BlockFace.DOWN || block.getY() != 0)) { if (block.getY() <= 255 && (face != BlockFace.UP || block.getY() != 255)) { if (!(block instanceof BlockPistonBase)) { if (block instanceof BlockFlowable) { return destroyBlocks; } } else if (((BlockPistonBase) block).isExtended()) { return false; } return true; } else { return false; } } else { return false; } }
Example 3
Source File: BlockDoor.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { if (face == BlockFace.UP) { Block blockUp = this.up(); Block blockDown = this.down(); if (!blockUp.canBeReplaced() || blockDown.isTransparent()) { return false; } int[] faces = {1, 2, 3, 0}; int direction = faces[player != null ? player.getDirection().getHorizontalIndex() : 0]; Block left = this.getSide(player.getDirection().rotateYCCW()); Block right = this.getSide(player.getDirection().rotateY()); int metaUp = 0x08; if (left.getId() == this.getId() || (!right.isTransparent() && left.isTransparent())) { //Door hinge metaUp |= 0x01; } this.setDamage(direction); this.getLevel().setBlock(block, this, true, true); //Bottom this.getLevel().setBlock(blockUp, Block.get(this.getId(), metaUp), true); //Top if (!this.isOpen() && this.level.isBlockPowered(this)) { this.toggle(null); } return true; } return false; }
Example 4
Source File: ItemBoat.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { if (face != BlockFace.UP) return false; EntityBoat boat = (EntityBoat) Entity.createEntity("Boat", level.getChunk(block.getFloorX() >> 4, block.getFloorZ() >> 4), new CompoundTag("") .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", block.getX() + 0.5)) .add(new DoubleTag("", block.getY() - (target instanceof BlockWater ? 0.0625 : 0))) .add(new DoubleTag("", block.getZ() + 0.5))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", (float) ((player.yaw + 90f) % 360))) .add(new FloatTag("", 0))) .putByte("woodID", this.getDamage()) ); if (boat == null) { return false; } if (player.isSurvival()) { Item item = player.getInventory().getItemInHand(); item.setCount(item.getCount() - 1); player.getInventory().setItemInHand(item); } boat.spawnToAll(); return true; }
Example 5
Source File: BlockTorch.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public BlockFace getBlockFace(int meta) { switch (meta) { case 1: return BlockFace.EAST; case 2: return BlockFace.WEST; case 3: return BlockFace.SOUTH; case 4: return BlockFace.NORTH; default: return BlockFace.UP; } }
Example 6
Source File: BlockTrapdoor.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { if ((!target.isTransparent() || target.getId() == SLAB)) { BlockFace facing; boolean top; if (face.getAxis().isHorizontal() || player == null) { facing = face; top = fy > 0.5; } else { facing = player.getDirection().getOpposite(); top = face != BlockFace.UP; } int faceBit = getMetaFromFacing(facing); this.meta |= faceBit; if (top) { this.meta |= 0x08; } this.getLevel().setBlock(block, this, true, true); return true; } return false; }
Example 7
Source File: BlockRedstoneWire.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public int getWeakPower(BlockFace side) { if (!this.canProvidePower) { return 0; } else { int power = this.getDamage(); if (power == 0) { return 0; } else if (side == BlockFace.UP) { return power; } else { EnumSet<BlockFace> enumset = EnumSet.noneOf(BlockFace.class); for (BlockFace face : Plane.HORIZONTAL) { if (this.isPowerSourceAt(face)) { enumset.add(face); } } if (side.getAxis().isHorizontal() && enumset.isEmpty()) { return power; } else if (enumset.contains(side) && !enumset.contains(side.rotateYCCW()) && !enumset.contains(side.rotateY())) { return power; } else { return 0; } } } }
Example 8
Source File: BlockHopper.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { BlockFace facing = face.getOpposite(); if (facing == BlockFace.UP) { facing = BlockFace.DOWN; } this.setDamage(facing.getIndex()); boolean powered = this.level.isBlockPowered(this); if (powered == this.isEnabled()) { this.setEnabled(!powered); } this.level.setBlock(this, this); CompoundTag nbt = new CompoundTag() .putList(new ListTag<>("Items")) .putString("id", BlockEntity.HOPPER) .putInt("x", (int) this.x) .putInt("y", (int) this.y) .putInt("z", (int) this.z); new BlockEntityHopper(this.level.getChunk(this.getFloorX() >> 4, this.getFloorZ() >> 4), nbt); return true; }
Example 9
Source File: BlockDoor.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { if (this.y > 254) return false; if (face == BlockFace.UP) { Block blockUp = this.up(); Block blockDown = this.down(); if (!blockUp.canBeReplaced() || blockDown.isTransparent()) { return false; } int[] faces = {1, 2, 3, 0}; int direction = faces[player != null ? player.getDirection().getHorizontalIndex() : 0]; Block left = this.getSide(player.getDirection().rotateYCCW()); Block right = this.getSide(player.getDirection().rotateY()); int metaUp = DOOR_TOP_BIT; if (left.getId() == this.getId() || (!right.isTransparent() && left.isTransparent())) { //Door hinge metaUp |= DOOR_HINGE_BIT; } this.setDamage(direction); this.getLevel().setBlock(block, this, true, false); //Bottom this.getLevel().setBlock(blockUp, Block.get(this.getId(), metaUp), true, true); //Top if (!this.isOpen() && this.level.isBlockPowered(this.getLocation())) { this.toggle(null); metaUp |= DOOR_POWERED_BIT; this.getLevel().setBlockDataAt(blockUp.getFloorX(), blockUp.getFloorY(), blockUp.getFloorZ(), metaUp); } return true; } return false; }
Example 10
Source File: BlockRedstoneWire.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public int getWeakPower(BlockFace side) { if (!this.canProvidePower) { return 0; } else { int power = this.getDamage(); if (power == 0) { return 0; } else if (side == BlockFace.UP) { return power; } else { EnumSet<BlockFace> enumset = EnumSet.noneOf(BlockFace.class); for (BlockFace face : Plane.HORIZONTAL) { if (this.isPowerSourceAt(face)) { enumset.add(face); } } if (side.getAxis().isHorizontal() && enumset.isEmpty()) { return power; } else if (enumset.contains(side) && !enumset.contains(side.rotateYCCW()) && !enumset.contains(side.rotateY())) { return power; } else { return 0; } } } }
Example 11
Source File: BlockBanner.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { if (face != BlockFace.DOWN) { if (face == BlockFace.UP) { this.setDamage(NukkitMath.floorDouble(((player.yaw + 180) * 16 / 360) + 0.5) & 0x0f); this.getLevel().setBlock(block, this, true); } else { this.setDamage(face.getIndex()); this.getLevel().setBlock(block, Block.get(BlockID.WALL_BANNER, this.getDamage()), true); } CompoundTag nbt = BlockEntity.getDefaultCompound(this, BlockEntity.BANNER) .putInt("Base", item.getDamage() & 0xf); Tag type = item.getNamedTagEntry("Type"); if (type instanceof IntTag) { nbt.put("Type", type); } Tag patterns = item.getNamedTagEntry("Patterns"); if (patterns instanceof ListTag) { nbt.put("Patterns", patterns); } BlockEntityBanner banner = (BlockEntityBanner) BlockEntity.createBlockEntity(BlockEntity.BANNER, this.getChunk(), nbt); return banner != null; } return false; }
Example 12
Source File: BlockRedstoneWire.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public int getWeakPower(BlockFace side) { if (!this.canProvidePower) { return 0; } else { int power = this.meta; if (power == 0) { return 0; } else if (side == BlockFace.UP) { return power; } else { EnumSet<BlockFace> enumset = EnumSet.noneOf(BlockFace.class); for (BlockFace face : Plane.HORIZONTAL) { if (this.isPowerSourceAt(face)) { enumset.add(face); } } if (side.getAxis().isHorizontal() && enumset.isEmpty()) { return power; } else if (enumset.contains(side) && !enumset.contains(side.rotateYCCW()) && !enumset.contains(side.rotateY())) { return power; } else { return 0; } } } }
Example 13
Source File: BlockStairs.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { int[] faces = new int[]{0, 2, 1, 3}; this.meta = (faces[player.getDirection().getHorizontalIndex()] & 0x03); if ((fy > 0.5 && face != BlockFace.UP) || face == BlockFace.DOWN) { this.meta |= 0x04; //Upside-down stairs } this.getLevel().setBlock(block, this, true, true); return true; }
Example 14
Source File: ItemBoat.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { if (face != BlockFace.UP) return false; EntityBoat boat = new EntityBoat( level.getChunk(block.getFloorX() >> 4, block.getFloorZ() >> 4), new CompoundTag("") .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", block.getX() + 0.5)) .add(new DoubleTag("", block.getY() - 0.0625)) .add(new DoubleTag("", block.getZ() + 0.5))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", (float) ((player.yaw + 90f) % 360))) .add(new FloatTag("", 0))) .putByte("woodID", this.getDamage()) ); if (player.isSurvival()) { Item item = player.getInventory().getItemInHand(); item.setCount(item.getCount() - 1); player.getInventory().setItemInHand(item); } boat.spawnToAll(); return true; }
Example 15
Source File: BlockPressurePlateBase.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public int getStrongPower(BlockFace side) { return side == BlockFace.UP ? this.getRedstonePower() : 0; }
Example 16
Source File: BlockRailDetector.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public int getStrongPower(BlockFace side) { return isActive() ? 0 : (side == BlockFace.UP ? 15 : 0); }
Example 17
Source File: BlockTrappedChest.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public int getStrongPower(BlockFace side) { return side == BlockFace.UP ? this.getWeakPower(side) : 0; }
Example 18
Source File: BlockSlab.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { this.setDamage(this.getDamage() & 0x07); if (face == BlockFace.DOWN) { if (target instanceof BlockSlab && (target.getDamage() & 0x08) == 0x08 && (target.getDamage() & 0x07) == (this.getDamage() & 0x07)) { this.getLevel().setBlock(target, Block.get(doubleSlab, this.getDamage()), true); return true; } else if (block instanceof BlockSlab && (block.getDamage() & 0x07) == (this.getDamage() & 0x07)) { this.getLevel().setBlock(block, Block.get(doubleSlab, this.getDamage()), true); return true; } else { this.setDamage(this.getDamage() | 0x08); } } else if (face == BlockFace.UP) { if (target instanceof BlockSlab && (target.getDamage() & 0x08) == 0 && (target.getDamage() & 0x07) == (this.getDamage() & 0x07)) { this.getLevel().setBlock(target, Block.get(doubleSlab, this.getDamage()), true); return true; } else if (block instanceof BlockSlab && (block.getDamage() & 0x07) == (this.getDamage() & 0x07)) { this.getLevel().setBlock(block, Block.get(doubleSlab, this.getDamage()), true); return true; } //TODO: check for collision } else { if (block instanceof BlockSlab) { if ((block.getDamage() & 0x07) == (this.getDamage() & 0x07)) { this.getLevel().setBlock(block, Block.get(doubleSlab, this.getDamage()), true); return true; } return false; } else { if (fy > 0.5) { this.setDamage(this.getDamage() | 0x08); } } } if (block instanceof BlockSlab && (target.getDamage() & 0x07) != (this.getDamage() & 0x07)) { return false; } this.getLevel().setBlock(block, this, true, true); return true; }
Example 19
Source File: BlockIterator.java From Nukkit with GNU General Public License v3.0 | 4 votes |
private BlockFace getYFace(Vector3 direction) { return ((direction.y) > 0) ? BlockFace.UP : BlockFace.DOWN; }
Example 20
Source File: BlockTrappedChest.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public int getStrongPower(BlockFace side) { return side == BlockFace.UP ? this.getWeakPower(side) : 0; }