use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.
the class BlockRedstoneDiode method calculateInputStrength.
protected int calculateInputStrength() {
BlockFace face = getFacing();
Vector3 pos = this.getLocation().getSide(face);
int power = this.level.getRedstonePower(pos, face);
if (power >= 15) {
return power;
} else {
Block block = this.level.getBlock(pos);
return Math.max(power, block.getId() == Block.REDSTONE_WIRE ? block.getDamage() : 0);
}
}
use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.
the class BlockRedstoneDiode method isFacingTowardsRepeater.
public boolean isFacingTowardsRepeater() {
BlockFace side = getFacing().getOpposite();
Block block = this.getSide(side);
return block instanceof BlockRedstoneDiode && ((BlockRedstoneDiode) block).getFacing() != side;
}
use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.
the class BlockRedstoneWire method onBreak.
@Override
public boolean onBreak(Item item) {
this.getLevel().setBlock(this, new BlockAir(), true, true);
Vector3 pos = getLocation();
this.updateSurroundingRedstone(false);
for (BlockFace blockFace : BlockFace.values()) {
this.level.updateAroundRedstone(pos.getSide(blockFace), null);
}
for (BlockFace blockFace : Plane.HORIZONTAL) {
Vector3 v = pos.getSide(blockFace);
if (this.level.getBlock(v).isNormalBlock()) {
this.updateAround(v.up(), BlockFace.DOWN);
} else {
this.updateAround(v.down(), BlockFace.UP);
}
}
return true;
}
use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.
the class BlockRedstoneWire method calculateCurrentChanges.
private void calculateCurrentChanges(boolean force) {
Vector3 pos = this.getLocation();
int meta = this.getDamage();
int maxStrength = meta;
this.canProvidePower = false;
int power = this.getIndirectPower();
this.canProvidePower = true;
if (power > 0 && power > maxStrength - 1) {
maxStrength = power;
}
int strength = 0;
for (BlockFace face : Plane.HORIZONTAL) {
Vector3 v = pos.getSide(face);
boolean flag = v.getX() != this.getX() || v.getZ() != this.getZ();
if (flag) {
strength = this.getMaxCurrentStrength(v, strength);
}
if (this.level.getBlock(v).isNormalBlock() && !this.level.getBlock(pos.up()).isNormalBlock()) {
if (flag) {
strength = this.getMaxCurrentStrength(v.up(), strength);
}
} else if (flag && !this.level.getBlock(v).isNormalBlock()) {
strength = this.getMaxCurrentStrength(v.down(), strength);
}
}
if (strength > maxStrength) {
maxStrength = strength - 1;
} else if (maxStrength > 0) {
--maxStrength;
} else {
maxStrength = 0;
}
if (power > maxStrength - 1) {
maxStrength = power;
}
if (meta != maxStrength) {
this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, meta, maxStrength));
this.setDamage(maxStrength);
this.level.setBlock(this, this, false, false);
this.level.updateAroundRedstone(this, null);
for (BlockFace face : BlockFace.values()) {
this.level.updateAroundRedstone(pos.getSide(face), face.getOpposite());
}
} else if (force) {
for (BlockFace face : BlockFace.values()) {
this.level.updateAroundRedstone(pos.getSide(face), face.getOpposite());
}
}
}
use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.
the class BlockTrapdoor method place.
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
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[] faces = { 2, 1, 3, 0 };
int faceBit = faces[facing.getHorizontalIndex()];
this.setDamage(this.getDamage() | faceBit);
if (top) {
this.setDamage(this.getDamage() | 0x04);
}
this.getLevel().setBlock(block, this, true, true);
return true;
}
Aggregations