use of cn.nukkit.math.Vector3 in project Nukkit by Nukkit.
the class BlockUpdateScheduler method perform.
private void perform(long tick) {
try {
lastTick = tick;
Set<BlockUpdateEntry> updates = pendingUpdates = queuedUpdates.remove(tick);
if (updates != null) {
for (BlockUpdateEntry entry : updates) {
Vector3 pos = entry.pos;
if (level.isChunkLoaded(NukkitMath.floorDouble(pos.x) >> 4, NukkitMath.floorDouble(pos.z) >> 4)) {
Block block = level.getBlock(entry.pos);
if (Block.equals(block, entry.block, false)) {
block.onUpdate(level.BLOCK_UPDATE_SCHEDULED);
}
} else {
level.scheduleUpdate(entry.block, entry.pos, 0);
}
}
}
} finally {
pendingUpdates = null;
}
}
use of cn.nukkit.math.Vector3 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;
}
use of cn.nukkit.math.Vector3 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.Vector3 in project Nukkit by Nukkit.
the class BlockRedstoneDiode method onUpdate.
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_SCHEDULED) {
if (!this.isLocked()) {
Vector3 pos = getLocation();
boolean shouldBePowered = this.shouldBePowered();
if (this.isPowered && !shouldBePowered) {
this.level.setBlock(pos, this.getUnpowered(), true, true);
this.level.updateAroundRedstone(this.getLocation().getSide(getFacing().getOpposite()), null);
} else if (!this.isPowered) {
this.level.setBlock(pos, this.getPowered(), true, true);
this.level.updateAroundRedstone(this.getLocation().getSide(getFacing().getOpposite()), null);
if (!shouldBePowered) {
// System.out.println("schedule update 2");
level.scheduleUpdate(getPowered(), this, this.getDelay());
}
}
}
} else if (type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_REDSTONE) {
if (type == Level.BLOCK_UPDATE_NORMAL && this.getSide(BlockFace.DOWN).isTransparent()) {
this.level.useBreakOn(this);
return Level.BLOCK_UPDATE_NORMAL;
} else {
this.updateState();
return Level.BLOCK_UPDATE_NORMAL;
}
}
return 0;
}
use of cn.nukkit.math.Vector3 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;
}
Aggregations