use of cn.nukkit.event.block.BlockFromToEvent in project Nukkit by Nukkit.
the class BlockLiquid method checkForHarden.
private void checkForHarden() {
if (this instanceof BlockLava) {
boolean colliding = false;
for (BlockFace face : BlockFace.values()) {
if (colliding = this.getSide(face) instanceof BlockWater) {
break;
}
}
if (colliding) {
Block to;
if (this.getDamage() == 0) {
to = new BlockObsidian();
} else if (this.getDamage() <= 4) {
to = new BlockCobblestone();
} else {
return;
}
to.setComponents(this.getX(), this.getY(), this.getZ());
to.setLevel(this.getLevel());
BlockFromToEvent ev = new BlockFromToEvent(this, to);
this.getLevel().getServer().getPluginManager().callEvent(ev);
if (!ev.isCancelled()) {
this.getLevel().setBlock(this, ev.getTo(), true);
this.triggerLavaMixEffects(this);
}
}
}
}
use of cn.nukkit.event.block.BlockFromToEvent in project Nukkit by Nukkit.
the class BlockLiquid method onUpdate.
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
this.checkForHarden();
this.getLevel().scheduleUpdate(this, this.tickRate());
} else if (type == Level.BLOCK_UPDATE_SCHEDULED) {
if (this.temporalVector == null) {
this.temporalVector = new Vector3(0, 0, 0);
}
int decay = this.getFlowDecay(this);
int multiplier = this instanceof BlockLava ? 2 : 1;
boolean flag = true;
int smallestFlowDecay;
if (decay > 0) {
smallestFlowDecay = -100;
this.adjacentSources = 0;
smallestFlowDecay = this.getSmallestFlowDecay(this.level.getBlock(this.temporalVector.setComponents(this.x, this.y, this.z - 1)), smallestFlowDecay);
smallestFlowDecay = this.getSmallestFlowDecay(this.level.getBlock(this.temporalVector.setComponents(this.x, this.y, this.z + 1)), smallestFlowDecay);
smallestFlowDecay = this.getSmallestFlowDecay(this.level.getBlock(this.temporalVector.setComponents(this.x - 1, this.y, this.z)), smallestFlowDecay);
smallestFlowDecay = this.getSmallestFlowDecay(this.level.getBlock(this.temporalVector.setComponents(this.x + 1, this.y, this.z)), smallestFlowDecay);
int k = smallestFlowDecay + multiplier;
if (k >= 8 || smallestFlowDecay < 0) {
k = -1;
}
int topFlowDecay;
if ((topFlowDecay = this.getFlowDecay(this.level.getBlock(this.level.getBlock(this.temporalVector.setComponents(this.x, this.y + 1, this.z))))) >= 0) {
if (topFlowDecay >= 8) {
k = topFlowDecay;
} else {
k = topFlowDecay | 0x08;
}
}
if (this.adjacentSources >= 2 && this instanceof BlockWater) {
Block bottomBlock = this.level.getBlock(this.level.getBlock(this.temporalVector.setComponents(this.x, this.y - 1, this.z)));
if (bottomBlock.isSolid()) {
k = 0;
} else if (bottomBlock instanceof BlockWater && bottomBlock.getDamage() == 0) {
k = 0;
}
}
if (this instanceof BlockLava && decay < 8 && k < 8 && k > 1 && new Random().nextInt(4) != 0) {
k = decay;
flag = false;
}
if (k != decay) {
decay = k;
if (decay < 0) {
this.getLevel().setBlock(this, new BlockAir(), true);
} else {
this.getLevel().setBlock(this, this.getBlock(decay), true);
}
} else if (flag) {
// this.getLevel().scheduleUpdate(this, this.tickRate());
// this.updateFlow();
}
} else {
// this.updateFlow();
}
Block bottomBlock = this.level.getBlock(this.temporalVector.setComponents(this.x, this.y - 1, this.z));
if (bottomBlock.canBeFlowedInto() || bottomBlock instanceof BlockLiquid) {
if (this instanceof BlockLava && bottomBlock instanceof BlockWater) {
Block to = new BlockStone();
to.setComponents(bottomBlock.getX(), bottomBlock.getY(), bottomBlock.getZ());
to.setLevel(bottomBlock.getLevel());
BlockFromToEvent ev = new BlockFromToEvent(bottomBlock, to);
this.getLevel().getServer().getPluginManager().callEvent(ev);
if (!ev.isCancelled()) {
this.getLevel().setBlock(bottomBlock, ev.getTo(), true);
this.triggerLavaMixEffects(bottomBlock);
return 0;
}
}
if (decay >= 8) {
this.flowIntoBlock(bottomBlock, decay);
} else {
this.flowIntoBlock(bottomBlock, decay | 0x08);
}
}
if (decay >= 0 && ((decay == 0 && this.getDamage() == 0) || (!bottomBlock.canBeFlowedInto() && !(bottomBlock instanceof BlockLiquid)))) {
boolean[] flags = this.getOptimalFlowDirections();
int l = decay + multiplier;
if (decay >= 8) {
l = 1;
}
if (l >= 8) {
this.checkForHarden();
return 0;
}
if (flags[0]) {
this.flowIntoBlock(this.level.getBlock(this.temporalVector.setComponents(this.x - 1, this.y, this.z)), l);
}
if (flags[1]) {
this.flowIntoBlock(this.level.getBlock(this.temporalVector.setComponents(this.x + 1, this.y, this.z)), l);
}
if (flags[2]) {
this.flowIntoBlock(this.level.getBlock(this.temporalVector.setComponents(this.x, this.y, this.z - 1)), l);
}
if (flags[3]) {
this.flowIntoBlock(this.level.getBlock(this.temporalVector.setComponents(this.x, this.y, this.z + 1)), l);
}
}
this.checkForHarden();
}
return 0;
}
Aggregations