cn.nukkit.item.ItemFireCharge Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powernukkit Show documentation
Show all versions of powernukkit Show documentation
A Minecraft Bedrock Edition server software implementation made in Java from scratch which supports all new features.
package cn.nukkit.item;
import cn.nukkit.Player;
import cn.nukkit.block.Block;
import cn.nukkit.block.BlockFire;
import cn.nukkit.block.BlockID;
import cn.nukkit.event.block.BlockIgniteEvent;
import cn.nukkit.level.Level;
import cn.nukkit.level.Sound;
import cn.nukkit.Player;
import cn.nukkit.math.BlockFace;
import java.util.concurrent.ThreadLocalRandom;
import cn.nukkit.event.block.BlockIgniteEvent;
import cn.nukkit.network.protocol.LevelEventPacket;
/**
* @author PetteriM1
*/
public class ItemFireCharge extends Item {
public ItemFireCharge() {
this(0, 1);
}
public ItemFireCharge(Integer meta) {
this(meta, 1);
}
public ItemFireCharge(Integer meta, int count) {
super(FIRE_CHARGE, 0, count, "Fire Charge");
}
@Override
public boolean canBeActivated() {
return true;
}
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
if (player.isAdventure()) {
return false;
}
if (block.getId() == AIR && (target.isSolid() || target.getBurnChance() > 0)) {
if (target.getId() == OBSIDIAN) {
if (level.createPortal(target)) {
return true;
}
}
BlockFire fire = (BlockFire) Block.get(BlockID.FIRE);
fire.x = block.x;
fire.y = block.y;
fire.z = block.z;
fire.level = level;
if (fire.isBlockTopFacingSurfaceSolid(fire.down()) || fire.canNeighborBurn()) {
BlockIgniteEvent e = new BlockIgniteEvent(block, null, player, BlockIgniteEvent.BlockIgniteCause.FLINT_AND_STEEL);
block.getLevel().getServer().getPluginManager().callEvent(e);
if (!e.isCancelled()) {
level.setBlock(fire, fire, true);
level.addLevelEvent(block, LevelEventPacket.EVENT_SOUND_BLAZE_SHOOT, 78642);
level.scheduleUpdate(fire, fire.tickRate() + ThreadLocalRandom.current().nextInt(10));
}
if (player.isSurvival()) {
Item item = player.getInventory().getItemInHand();
item.setCount(item.getCount() - 1);
player.getInventory().setItemInHand(item);
}
return true;
}
}
return false;
}
}