本文整理汇总了Java中cn.nukkit.event.entity.EntityBlockChangeEvent类的典型用法代码示例。如果您正苦于以下问题:Java EntityBlockChangeEvent类的具体用法?Java EntityBlockChangeEvent怎么用?Java EntityBlockChangeEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EntityBlockChangeEvent类属于cn.nukkit.event.entity包,在下文中一共展示了EntityBlockChangeEvent类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onEntityFall
import cn.nukkit.event.entity.EntityBlockChangeEvent; //导入依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onEntityFall(EntityBlockChangeEvent event) {
Entity entity = event.getEntity();
Location location = NukkitUtil.getLocation(entity);
if (!PS.get().hasPlotArea(location.getWorld())) {
return;
}
PlotArea area = location.getPlotArea();
if (area == null) {
return;
}
Block from = event.getFrom();
Block to = event.getTo();
final Plot finalPlot = area.getOwnedPlotAbs(location);
boolean toBlock = from == null || from.getId() == 0;
if (toBlock) {
List<MetadataValue> meta = entity.getMetadata("plot");
if (meta.isEmpty()) {
return;
}
Plot origin = (Plot) meta.get(0).value();
if (origin != null && !origin.equals(finalPlot)) {
kill(entity, event);
}
} else {
entity.setMetadata("plot", new MetadataValue((Plugin) PS.get().IMP) {
private Plot plot = finalPlot;
@Override
public Object value() {
return plot;
}
@Override
public void invalidate() {
plot = null;
}
});
}
}
示例2: onUpdate
import cn.nukkit.event.entity.EntityBlockChangeEvent; //导入依赖的package包/类
@Override
public boolean onUpdate(int currentTick) {
if (closed) {
return false;
}
this.timing.startTiming();
int tickDiff = currentTick - lastUpdate;
if (tickDiff <= 0 && !justCreated) {
return true;
}
lastUpdate = currentTick;
boolean hasUpdate = entityBaseTick(tickDiff);
if (isAlive()) {
motionY -= getGravity();
move(motionX, motionY, motionZ);
float friction = 1 - getDrag();
motionX *= friction;
motionY *= 1 - getDrag();
motionZ *= friction;
Vector3 pos = (new Vector3(x - 0.5, y, z - 0.5)).round();
if (onGround) {
kill();
Block block = level.getBlock(pos);
if (block.getId() > 0 && block.isTransparent() && !block.canBeReplaced()) {
if (this.level.getGameRules().getBoolean("doEntityDrops")) {
getLevel().dropItem(this, Item.get(this.getBlock(), this.getDamage(), 1));
}
} else {
EntityBlockChangeEvent event = new EntityBlockChangeEvent(this, block, Block.get(getBlock(), getDamage()));
server.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
getLevel().setBlock(pos, event.getTo(), true);
if (event.getTo().getId() == Item.ANVIL) {
getLevel().addSound(new AnvilFallSound(pos));
}
}
}
hasUpdate = true;
}
updateMovement();
}
this.timing.stopTiming();
return hasUpdate || !onGround || Math.abs(motionX) > 0.00001 || Math.abs(motionY) > 0.00001 || Math.abs(motionZ) > 0.00001;
}