Search in sources :

Example 1 with BlockFace

use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.

the class BlockDispenser method getDispensePosition.

public Vector3 getDispensePosition() {
    BlockFace facing = getFacing();
    double x = this.getX() + 0.7 * facing.getXOffset();
    double y = this.getY() + 0.7 * facing.getYOffset();
    double z = this.getZ() + 0.7 * facing.getZOffset();
    return new Vector3(x, y, z);
}
Also used : BlockFace(cn.nukkit.math.BlockFace) Vector3(cn.nukkit.math.Vector3)

Example 2 with BlockFace

use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.

the class BlockRail method place.

// Information from http://minecraft.gamepedia.com/Rail
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    Block down = this.down();
    if (down == null || down.isTransparent()) {
        return false;
    }
    Map<BlockRail, BlockFace> railsAround = this.checkRailsAroundAffected();
    List<BlockRail> rails = new ArrayList<>(railsAround.keySet());
    List<BlockFace> faces = new ArrayList<>(railsAround.values());
    if (railsAround.size() == 1) {
        BlockRail other = rails.get(0);
        this.setDamage(this.connect(other, railsAround.get(other)).metadata());
    } else if (railsAround.size() == 4) {
        if (this.isAbstract()) {
            this.setDamage(this.connect(rails.get(faces.indexOf(SOUTH)), SOUTH, rails.get(faces.indexOf(EAST)), EAST).metadata());
        } else {
            this.setDamage(this.connect(rails.get(faces.indexOf(EAST)), EAST, rails.get(faces.indexOf(WEST)), WEST).metadata());
        }
    } else if (!railsAround.isEmpty()) {
        if (this.isAbstract()) {
            if (railsAround.size() == 2) {
                BlockRail rail1 = rails.get(0);
                BlockRail rail2 = rails.get(1);
                this.setDamage(this.connect(rail1, railsAround.get(rail1), rail2, railsAround.get(rail2)).metadata());
            } else {
                List<BlockFace> cd = Stream.of(CURVED_SOUTH_EAST, CURVED_NORTH_EAST, CURVED_SOUTH_WEST).filter(o -> o.connectingDirections().stream().allMatch(faces::contains)).findFirst().get().connectingDirections();
                BlockFace f1 = cd.get(0);
                BlockFace f2 = cd.get(1);
                this.setDamage(this.connect(rails.get(faces.indexOf(f1)), f1, rails.get(faces.indexOf(f2)), f2).metadata());
            }
        } else {
            BlockFace f = faces.stream().sorted((f1, f2) -> (f1.getIndex() < f2.getIndex()) ? 1 : ((x == y) ? 0 : -1)).findFirst().get();
            BlockFace fo = f.getOpposite();
            if (faces.contains(fo)) {
                // Opposite connectable
                this.setDamage(this.connect(rails.get(faces.indexOf(f)), f, rails.get(faces.indexOf(fo)), fo).metadata());
            } else {
                this.setDamage(this.connect(rails.get(faces.indexOf(f)), f).metadata());
            }
        }
    }
    this.level.setBlock(this, this, true, true);
    if (!isAbstract()) {
        level.scheduleUpdate(this, this, 0);
    }
    return true;
}
Also used : SOUTH(cn.nukkit.math.BlockFace.SOUTH) ItemTool(cn.nukkit.item.ItemTool) java.util(java.util) BlockFace(cn.nukkit.math.BlockFace) NORTH(cn.nukkit.math.BlockFace.NORTH) Level(cn.nukkit.level.Level) AxisAlignedBB(cn.nukkit.math.AxisAlignedBB) EAST(cn.nukkit.math.BlockFace.EAST) BlockColor(cn.nukkit.utils.BlockColor) Rail(cn.nukkit.utils.Rail) Collectors(java.util.stream.Collectors) WEST(cn.nukkit.math.BlockFace.WEST) Orientation(cn.nukkit.utils.Rail.Orientation) Stream(java.util.stream.Stream) Player(cn.nukkit.Player) Item(cn.nukkit.item.Item) BlockFace(cn.nukkit.math.BlockFace)

Example 3 with BlockFace

use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.

the class BlockRedstoneComparator method calculateInputStrength.

protected int calculateInputStrength() {
    int power = super.calculateInputStrength();
    BlockFace face = getFacing();
    Block block = this.getSide(face);
    if (block.hasComparatorInputOverride()) {
        power = block.getComparatorInputOverride();
    } else if (power < 15 && block.isNormalBlock()) {
        block = block.getSide(face);
        if (block.hasComparatorInputOverride()) {
            power = block.getComparatorInputOverride();
        }
    }
    return power;
}
Also used : BlockFace(cn.nukkit.math.BlockFace)

Example 4 with BlockFace

use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.

the class BlockLever method onActivate.

@Override
public boolean onActivate(Item item, Player player) {
    this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, isPowerOn() ? 15 : 0, isPowerOn() ? 0 : 15));
    this.setDamage(this.getDamage() ^ 0x08);
    this.getLevel().setBlock(this, this, false, true);
    // TODO: coorect pitcj
    this.getLevel().addSound(this, Sound.RANDOM_CLICK);
    LeverOrientation orientation = LeverOrientation.byMetadata(this.isPowerOn() ? this.getDamage() ^ 0x08 : this.getDamage());
    BlockFace face = orientation.getFacing();
    // this.level.updateAroundRedstone(this, null);
    this.level.updateAroundRedstone(this.getLocation().getSide(face.getOpposite()), isPowerOn() ? face : null);
    return true;
}
Also used : BlockFace(cn.nukkit.math.BlockFace) BlockRedstoneEvent(cn.nukkit.event.block.BlockRedstoneEvent)

Example 5 with BlockFace

use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.

the class BlockLever method onBreak.

@Override
public boolean onBreak(Item item) {
    this.getLevel().setBlock(this, new BlockAir(), true, true);
    if (isPowerOn()) {
        BlockFace face = LeverOrientation.byMetadata(this.isPowerOn() ? this.getDamage() ^ 0x08 : this.getDamage()).getFacing();
        this.level.updateAround(this.getLocation().getSide(face.getOpposite()));
    }
    return true;
}
Also used : BlockFace(cn.nukkit.math.BlockFace)

Aggregations

BlockFace (cn.nukkit.math.BlockFace)29 Vector3 (cn.nukkit.math.Vector3)16 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)3 BlockRedstoneEvent (cn.nukkit.event.block.BlockRedstoneEvent)2 Player (cn.nukkit.Player)1 Block (cn.nukkit.block.Block)1 BlockAir (cn.nukkit.block.BlockAir)1 BlockLiquid (cn.nukkit.block.BlockLiquid)1 BlockWater (cn.nukkit.block.BlockWater)1 BlockEntity (cn.nukkit.blockentity.BlockEntity)1 BlockEntityChest (cn.nukkit.blockentity.BlockEntityChest)1 BlockEntityHopper (cn.nukkit.blockentity.BlockEntityHopper)1 Entity (cn.nukkit.entity.Entity)1 BlockFromToEvent (cn.nukkit.event.block.BlockFromToEvent)1 PlayerBucketEmptyEvent (cn.nukkit.event.player.PlayerBucketEmptyEvent)1 PlayerBucketFillEvent (cn.nukkit.event.player.PlayerBucketFillEvent)1 Item (cn.nukkit.item.Item)1 ItemTool (cn.nukkit.item.ItemTool)1 Level (cn.nukkit.level.Level)1 Position (cn.nukkit.level.Position)1