use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.
the class BlockRedstoneWire method getIndirectPower.
private int getIndirectPower() {
int power = 0;
Vector3 pos = getLocation();
for (BlockFace face : BlockFace.values()) {
int blockPower = this.getIndirectPower(pos.getSide(face), face);
if (blockPower >= 15) {
return 15;
}
if (blockPower > power) {
power = blockPower;
}
}
return power;
}
use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.
the class BlockTripWireHook method calculateState.
public void calculateState(boolean onBreak, boolean updateAround, int pos, Block block) {
BlockFace facing = getFacing();
Vector3 v = this.getLocation();
boolean attached = isAttached();
boolean powered = isPowered();
boolean canConnect = !onBreak;
boolean nextPowered = false;
int distance = 0;
Block[] blocks = new Block[42];
for (int i = 1; i < 42; ++i) {
Vector3 vector = v.getSide(facing, i);
Block b = this.level.getBlock(vector);
if (b instanceof BlockTripWireHook) {
if (((BlockTripWireHook) b).getFacing() == facing.getOpposite()) {
distance = i;
}
break;
}
if (b.getId() != Block.TRIPWIRE && i != pos) {
blocks[i] = null;
canConnect = false;
} else {
if (i == pos) {
b = block != null ? block : b;
}
if (b instanceof BlockTripWire) {
boolean disarmed = !((BlockTripWire) b).isDisarmed();
boolean wirePowered = ((BlockTripWire) b).isPowered();
nextPowered |= disarmed && wirePowered;
if (i == pos) {
this.level.scheduleUpdate(this, 10);
canConnect &= disarmed;
}
}
blocks[i] = b;
}
}
canConnect = canConnect & distance > 1;
nextPowered = nextPowered & canConnect;
BlockTripWireHook hook = new BlockTripWireHook();
hook.setAttached(canConnect);
hook.setPowered(nextPowered);
if (distance > 0) {
Vector3 vec = v.getSide(facing, distance);
BlockFace face = facing.getOpposite();
hook.setFace(face);
this.level.setBlock(vec, hook, true, false);
this.level.updateAroundRedstone(vec, null);
this.level.updateAroundRedstone(vec.getSide(face.getOpposite()), null);
this.addSound(vec, canConnect, nextPowered, attached, powered);
}
this.addSound(v, canConnect, nextPowered, attached, powered);
if (!onBreak) {
hook.setFace(facing);
this.level.setBlock(v, hook, true, false);
if (updateAround) {
this.level.updateAroundRedstone(v, null);
this.level.updateAroundRedstone(v.getSide(facing.getOpposite()), null);
}
}
if (attached != canConnect) {
for (int i = 1; i < distance; i++) {
Vector3 vc = v.getSide(facing, i);
block = blocks[i];
if (block != null && this.level.getBlockIdAt(vc.getFloorX(), vc.getFloorY(), vc.getFloorZ()) != Block.AIR) {
if (canConnect ^ ((block.getDamage() & 0x04) > 0)) {
block.setDamage(block.getDamage() ^ 0x04);
}
this.level.setBlock(vc, block, true, false);
}
}
}
}
use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.
the class ProjectileDispenseBehavior method dispense.
@Override
public void dispense(BlockDispenser source, Item item) {
Position dispensePos = Position.fromObject(source.getDispensePosition(), source.getLevel());
CompoundTag nbt = Entity.getDefaultNBT(dispensePos);
this.correctNBT(nbt);
BlockFace face = source.getFacing();
Entity projectile = Entity.createEntity(getEntityType(), dispensePos.getLevel().getChunk(dispensePos.getFloorX(), dispensePos.getFloorZ()), nbt);
if (projectile == null) {
return;
}
projectile.setMotion(new Vector3(face.getXOffset(), face.getYOffset() + 0.1f, face.getZOffset()).multiply(6));
projectile.spawnToAll();
}
use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.
the class BlockTrappedChest method place.
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
int[] faces = { 2, 5, 3, 4 };
BlockEntityChest chest = null;
this.setDamage(faces[player != null ? player.getDirection().getHorizontalIndex() : 0]);
for (BlockFace side : Plane.HORIZONTAL) {
if ((this.getDamage() == 4 || this.getDamage() == 5) && (side == BlockFace.WEST || side == BlockFace.EAST)) {
continue;
} else if ((this.getDamage() == 3 || this.getDamage() == 2) && (side == BlockFace.NORTH || side == BlockFace.SOUTH)) {
continue;
}
Block c = this.getSide(side);
if (c instanceof BlockTrappedChest && c.getDamage() == this.getDamage()) {
BlockEntity blockEntity = this.getLevel().getBlockEntity(c);
if (blockEntity instanceof BlockEntityChest && !((BlockEntityChest) blockEntity).isPaired()) {
chest = (BlockEntityChest) blockEntity;
break;
}
}
}
this.getLevel().setBlock(block, this, true, true);
CompoundTag nbt = new CompoundTag("").putList(new ListTag<>("Items")).putString("id", BlockEntity.CHEST).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
if (item.hasCustomName()) {
nbt.putString("CustomName", item.getCustomName());
}
if (item.hasCustomBlockData()) {
Map<String, Tag> customData = item.getCustomBlockData().getTags();
for (Map.Entry<String, Tag> tag : customData.entrySet()) {
nbt.put(tag.getKey(), tag.getValue());
}
}
BlockEntity blockEntity = new BlockEntityChest(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
if (chest != null) {
chest.pairWith(((BlockEntityChest) blockEntity));
((BlockEntityChest) blockEntity).pairWith(chest);
}
return true;
}
use of cn.nukkit.math.BlockFace in project Nukkit by Nukkit.
the class BlockRedstoneDiode method onBreak.
@Override
public boolean onBreak(Item item) {
Vector3 pos = getLocation();
this.level.setBlock(this, new BlockAir(), true, true);
for (BlockFace face : BlockFace.values()) {
this.level.updateAroundRedstone(pos.getSide(face), null);
}
return true;
}
Aggregations