use of cn.nukkit.Player in project Nukkit by Nukkit.
the class BlockRail method place.
// Information from http://minecraft.gamepedia.com/Rail
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
Block down = this.down();
if (down == null || down.isTransparent()) {
return false;
}
Map<BlockRail, BlockFace> railsAround = this.checkRailsAroundAffected();
List<BlockRail> rails = new ArrayList<>(railsAround.keySet());
List<BlockFace> faces = new ArrayList<>(railsAround.values());
if (railsAround.size() == 1) {
BlockRail other = rails.get(0);
this.setDamage(this.connect(other, railsAround.get(other)).metadata());
} else if (railsAround.size() == 4) {
if (this.isAbstract()) {
this.setDamage(this.connect(rails.get(faces.indexOf(SOUTH)), SOUTH, rails.get(faces.indexOf(EAST)), EAST).metadata());
} else {
this.setDamage(this.connect(rails.get(faces.indexOf(EAST)), EAST, rails.get(faces.indexOf(WEST)), WEST).metadata());
}
} else if (!railsAround.isEmpty()) {
if (this.isAbstract()) {
if (railsAround.size() == 2) {
BlockRail rail1 = rails.get(0);
BlockRail rail2 = rails.get(1);
this.setDamage(this.connect(rail1, railsAround.get(rail1), rail2, railsAround.get(rail2)).metadata());
} else {
List<BlockFace> cd = Stream.of(CURVED_SOUTH_EAST, CURVED_NORTH_EAST, CURVED_SOUTH_WEST).filter(o -> o.connectingDirections().stream().allMatch(faces::contains)).findFirst().get().connectingDirections();
BlockFace f1 = cd.get(0);
BlockFace f2 = cd.get(1);
this.setDamage(this.connect(rails.get(faces.indexOf(f1)), f1, rails.get(faces.indexOf(f2)), f2).metadata());
}
} else {
BlockFace f = faces.stream().sorted((f1, f2) -> (f1.getIndex() < f2.getIndex()) ? 1 : ((x == y) ? 0 : -1)).findFirst().get();
BlockFace fo = f.getOpposite();
if (faces.contains(fo)) {
// Opposite connectable
this.setDamage(this.connect(rails.get(faces.indexOf(f)), f, rails.get(faces.indexOf(fo)), fo).metadata());
} else {
this.setDamage(this.connect(rails.get(faces.indexOf(f)), f).metadata());
}
}
}
this.level.setBlock(this, this, true, true);
if (!isAbstract()) {
level.scheduleUpdate(this, this, 0);
}
return true;
}
use of cn.nukkit.Player in project Nukkit by Nukkit.
the class BlockEntityBrewingStand method sendBrewTime.
protected void sendBrewTime() {
ContainerSetDataPacket pk = new ContainerSetDataPacket();
pk.property = ContainerSetDataPacket.PROPERTY_BREWING_STAND_BREW_TIME;
pk.value = this.brewTime;
for (Player p : this.inventory.getViewers()) {
int windowId = p.getWindowId(this.inventory);
if (windowId > 0) {
pk.windowId = windowId;
p.dataPacket(pk);
}
}
}
use of cn.nukkit.Player in project Nukkit by Nukkit.
the class BlockEntityFurnace method onUpdate.
@Override
public boolean onUpdate() {
if (this.closed) {
return false;
}
this.timing.startTiming();
boolean ret = false;
Item fuel = this.inventory.getFuel();
Item raw = this.inventory.getSmelting();
Item product = this.inventory.getResult();
FurnaceRecipe smelt = this.server.getCraftingManager().matchFurnaceRecipe(raw);
boolean canSmelt = (smelt != null && raw.getCount() > 0 && ((smelt.getResult().equals(product, true) && product.getCount() < product.getMaxStackSize()) || product.getId() == Item.AIR));
if (burnTime <= 0 && canSmelt && fuel.getFuelTime() != null && fuel.getCount() > 0) {
this.checkFuel(fuel);
}
if (burnTime > 0) {
burnTime--;
burnDuration = (int) Math.ceil(burnTime / maxTime * 200);
if (smelt != null && canSmelt) {
cookTime++;
if (cookTime >= 200) {
product = Item.get(smelt.getResult().getId(), smelt.getResult().getDamage(), product.getCount() + 1);
FurnaceSmeltEvent ev = new FurnaceSmeltEvent(this, raw, product);
this.server.getPluginManager().callEvent(ev);
if (!ev.isCancelled()) {
this.inventory.setResult(ev.getResult());
raw.setCount(raw.getCount() - 1);
if (raw.getCount() == 0) {
raw = new ItemBlock(new BlockAir(), 0, 0);
}
this.inventory.setSmelting(raw);
}
cookTime -= 200;
}
} else if (burnTime <= 0) {
burnTime = 0;
cookTime = 0;
burnDuration = 0;
} else {
cookTime = 0;
}
ret = true;
} else {
if (this.getBlock().getId() == Item.BURNING_FURNACE) {
this.getLevel().setBlock(this, new BlockFurnace(this.getBlock().getDamage()), true);
}
burnTime = 0;
cookTime = 0;
burnDuration = 0;
}
for (Player player : this.getInventory().getViewers()) {
int windowId = player.getWindowId(this.getInventory());
if (windowId > 0) {
ContainerSetDataPacket pk = new ContainerSetDataPacket();
pk.windowId = windowId;
pk.property = ContainerSetDataPacket.PROPERTY_FURNACE_TICK_COUNT;
;
pk.value = cookTime;
player.dataPacket(pk);
pk = new ContainerSetDataPacket();
pk.windowId = windowId;
pk.property = ContainerSetDataPacket.PROPERTY_FURNACE_LIT_TIME;
pk.value = burnDuration;
player.dataPacket(pk);
}
}
this.lastUpdate = System.currentTimeMillis();
this.timing.stopTiming();
return ret;
}
use of cn.nukkit.Player in project Nukkit by Nukkit.
the class EntityItem method onUpdate.
@Override
public boolean onUpdate(int currentTick) {
if (this.closed) {
return false;
}
int tickDiff = currentTick - this.lastUpdate;
if (tickDiff <= 0 && !this.justCreated) {
return true;
}
this.lastUpdate = currentTick;
this.timing.startTiming();
boolean hasUpdate = this.entityBaseTick(tickDiff);
if (this.isAlive()) {
if (this.pickupDelay > 0 && this.pickupDelay < 32767) {
this.pickupDelay -= tickDiff;
if (this.pickupDelay < 0) {
this.pickupDelay = 0;
}
} else {
for (Entity entity : this.level.getNearbyEntities(this.boundingBox.grow(1, 0.5, 1), this)) {
if (entity instanceof Player) {
if (((Player) entity).pickupEntity(this, true)) {
return true;
}
}
}
}
this.motionY -= this.getGravity();
if (this.checkObstruction(this.x, this.y, this.z)) {
hasUpdate = true;
}
this.move(this.motionX, this.motionY, this.motionZ);
double friction = 1 - this.getDrag();
if (this.onGround && (Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionZ) > 0.00001)) {
friction *= this.getLevel().getBlock(this.temporalVector.setComponents((int) Math.floor(this.x), (int) Math.floor(this.y - 1), (int) Math.floor(this.z) - 1)).getFrictionFactor();
}
this.motionX *= friction;
this.motionY *= 1 - this.getDrag();
this.motionZ *= friction;
if (this.onGround) {
this.motionY *= -0.5;
}
this.updateMovement();
if (this.age > 6000) {
ItemDespawnEvent ev = new ItemDespawnEvent(this);
this.server.getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
this.age = 0;
} else {
this.kill();
hasUpdate = true;
}
}
}
this.timing.stopTiming();
return hasUpdate || !this.onGround || Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionY) > 0.00001 || Math.abs(this.motionZ) > 0.00001;
}
use of cn.nukkit.Player in project Nukkit by Nukkit.
the class EntityMinecartAbstract method close.
@Override
public void close() {
super.close();
if (linkedEntity instanceof Player) {
linkedEntity.riding = null;
linkedEntity = null;
}
SmokeParticle particle = new SmokeParticle(this);
level.addParticle(particle);
}
Aggregations