use of cn.nukkit.block.BlockAir in project Nukkit by Nukkit.
the class PlayerInventory method setArmorContents.
public void setArmorContents(Item[] items) {
if (items.length < 4) {
Item[] newItems = new Item[4];
System.arraycopy(items, 0, newItems, 0, items.length);
items = newItems;
}
for (int i = 0; i < 4; ++i) {
if (items[i] == null) {
items[i] = new ItemBlock(new BlockAir(), null, 0);
}
if (items[i].getId() == Item.AIR) {
this.clear(this.getSize() + i);
} else {
this.setItem(this.getSize() + i, items[i]);
}
}
}
use of cn.nukkit.block.BlockAir in project Nukkit by Nukkit.
the class ItemBow method onReleaseUsing.
public boolean onReleaseUsing(Player player) {
Item itemArrow = Item.get(Item.ARROW, 0, 1);
if (player.isSurvival() && !player.getInventory().contains(itemArrow)) {
player.getInventory().sendContents(player);
return false;
}
double damage = 2;
boolean flame = false;
if (this.hasEnchantments()) {
Enchantment bowDamage = this.getEnchantment(Enchantment.ID_BOW_POWER);
if (bowDamage != null && bowDamage.getLevel() > 0) {
damage += 0.25 * (bowDamage.getLevel() + 1);
}
Enchantment flameEnchant = this.getEnchantment(Enchantment.ID_BOW_FLAME);
flame = flameEnchant != null && flameEnchant.getLevel() > 0;
}
CompoundTag nbt = new CompoundTag().putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("", player.x)).add(new DoubleTag("", player.y + player.getEyeHeight())).add(new DoubleTag("", player.z))).putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("", -Math.sin(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI))).add(new DoubleTag("", -Math.sin(player.pitch / 180 * Math.PI))).add(new DoubleTag("", Math.cos(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI)))).putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("", (player.yaw > 180 ? 360 : 0) - (float) player.yaw)).add(new FloatTag("", (float) -player.pitch))).putShort("Fire", player.isOnFire() || flame ? 45 * 60 : 0).putDouble("damage", damage);
int diff = (Server.getInstance().getTick() - player.getStartActionTick());
double p = (double) diff / 20;
double f = Math.min((p * p + p * 2) / 3, 1) * 2;
EntityShootBowEvent entityShootBowEvent = new EntityShootBowEvent(player, this, new EntityArrow(player.chunk, nbt, player, f == 2), f);
if (f < 0.1 || diff < 5) {
entityShootBowEvent.setCancelled();
}
Server.getInstance().getPluginManager().callEvent(entityShootBowEvent);
if (entityShootBowEvent.isCancelled()) {
entityShootBowEvent.getProjectile().kill();
player.getInventory().sendContents(player);
} else {
entityShootBowEvent.getProjectile().setMotion(entityShootBowEvent.getProjectile().getMotion().multiply(entityShootBowEvent.getForce()));
if (player.isSurvival()) {
Enchantment infinity;
if (!this.hasEnchantments() || (infinity = this.getEnchantment(Enchantment.ID_BOW_INFINITY)) == null || infinity.getLevel() <= 0)
player.getInventory().removeItem(itemArrow);
if (!this.isUnbreakable()) {
Enchantment durability = this.getEnchantment(Enchantment.ID_DURABILITY);
if (!(durability != null && durability.getLevel() > 0 && (100 / (durability.getLevel() + 1)) <= new Random().nextInt(100))) {
this.setDamage(this.getDamage() + 1);
if (this.getDamage() >= 385) {
player.getInventory().setItemInHand(new ItemBlock(new BlockAir(), 0, 0));
} else {
player.getInventory().setItemInHand(this);
}
}
}
}
if (entityShootBowEvent.getProjectile() instanceof EntityProjectile) {
ProjectileLaunchEvent projectev = new ProjectileLaunchEvent(entityShootBowEvent.getProjectile());
Server.getInstance().getPluginManager().callEvent(projectev);
if (projectev.isCancelled()) {
entityShootBowEvent.getProjectile().kill();
} else {
entityShootBowEvent.getProjectile().spawnToAll();
player.level.addSound(player, Sound.RANDOM_BOW, 1, 1, player.getViewers().values());
}
} else {
entityShootBowEvent.getProjectile().spawnToAll();
}
}
return true;
}
use of cn.nukkit.block.BlockAir in project Nukkit by Nukkit.
the class BlockEntityFurnace method checkFuel.
protected void checkFuel(Item fuel) {
FurnaceBurnEvent ev = new FurnaceBurnEvent(this, fuel, fuel.getFuelTime() == null ? 0 : fuel.getFuelTime());
if (ev.isCancelled()) {
return;
}
maxTime = ev.getBurnTime();
burnTime = ev.getBurnTime();
burnDuration = 0;
if (this.getBlock().getId() == Item.FURNACE) {
this.getLevel().setBlock(this, new BlockFurnaceBurning(this.getBlock().getDamage()), true);
}
if (burnTime > 0 && ev.isBurning()) {
fuel.setCount(fuel.getCount() - 1);
if (fuel.getCount() == 0) {
if (fuel.getId() == Item.BUCKET && fuel.getDamage() == 10) {
fuel.setDamage(0);
fuel.setCount(1);
} else {
fuel = new ItemBlock(new BlockAir(), 0, 0);
}
}
this.inventory.setFuel(fuel);
}
}
use of cn.nukkit.block.BlockAir in project Nukkit by Nukkit.
the class ItemBucket method onActivate.
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
Block targetBlock = Block.get(this.meta);
if (targetBlock instanceof BlockAir) {
if (target instanceof BlockLiquid && target.getDamage() == 0) {
Item result = Item.get(BUCKET, this.getDamageByTarget(target.getId()), 1);
PlayerBucketFillEvent ev;
player.getServer().getPluginManager().callEvent(ev = new PlayerBucketFillEvent(player, block, face, this, result));
if (!ev.isCancelled()) {
player.getLevel().setBlock(target, new BlockAir(), true, true);
// replaced with water that can flow.
for (BlockFace side : Plane.HORIZONTAL) {
Block b = target.getSide(side);
if (b.getId() == STILL_WATER) {
level.setBlock(b, new BlockWater());
}
}
if (player.isSurvival()) {
Item clone = this.clone();
clone.setCount(this.getCount() - 1);
player.getInventory().setItemInHand(clone);
player.getInventory().addItem(ev.getItem());
}
return true;
} else {
player.getInventory().sendContents(player);
}
}
} else if (targetBlock instanceof BlockLiquid) {
Item result = Item.get(BUCKET, 0, 1);
PlayerBucketEmptyEvent ev;
player.getServer().getPluginManager().callEvent(ev = new PlayerBucketEmptyEvent(player, block, face, this, result));
if (!ev.isCancelled()) {
player.getLevel().setBlock(block, targetBlock, true, true);
if (player.isSurvival()) {
Item clone = this.clone();
clone.setCount(this.getCount() - 1);
player.getInventory().setItemInHand(clone);
player.getInventory().addItem(ev.getItem());
}
return true;
} else {
player.getInventory().sendContents(player);
}
}
return false;
}
use of cn.nukkit.block.BlockAir in project Nukkit by Nukkit.
the class EntityHumanType method attack.
@Override
public boolean attack(EntityDamageEvent source) {
if (!this.isAlive()) {
return false;
}
if (source.getCause() != DamageCause.VOID && source.getCause() != DamageCause.CUSTOM && source.getCause() != DamageCause.MAGIC) {
int points = 0;
int epf = 0;
int toughness = 0;
for (Item armor : inventory.getArmorContents()) {
points += armor.getArmorPoints();
epf += calculateEnchantmentReduction(armor, source);
toughness += armor.getToughness();
}
float originalDamage = source.getDamage();
float finalDamage = (float) (originalDamage * (1 - Math.max(points / 5, points - originalDamage / (2 + toughness / 4)) / 25) * (1 - /*0.75 */
epf * 0.04));
source.setDamage(finalDamage - originalDamage, DamageModifier.ARMOR);
// source.setDamage(source.getDamage(DamageModifier.ARMOR_ENCHANTMENTS) - (originalDamage - originalDamage * (1 - epf / 25)), DamageModifier.ARMOR_ENCHANTMENTS);
}
if (super.attack(source)) {
Entity damager = null;
if (source instanceof EntityDamageByEntityEvent) {
damager = ((EntityDamageByEntityEvent) source).getDamager();
}
for (int slot = 0; slot < 4; slot++) {
Item armor = this.inventory.getArmorItem(slot);
if (armor.hasEnchantments()) {
if (damager != null) {
for (Enchantment enchantment : armor.getEnchantments()) {
enchantment.doPostAttack(damager, this);
}
}
Enchantment durability = armor.getEnchantment(Enchantment.ID_DURABILITY);
if (durability != null && durability.getLevel() > 0 && (100 / (durability.getLevel() + 1)) <= new Random().nextInt(100))
continue;
}
armor.setDamage(armor.getDamage() + 1);
if (armor.getDamage() >= armor.getMaxDurability()) {
inventory.setArmorItem(slot, new ItemBlock(new BlockAir()));
} else {
inventory.setArmorItem(slot, armor, true);
}
}
return true;
} else {
return false;
}
}
Aggregations