use of icbm.classic.content.explosive.ex.Explosion in project ICBM-Classic by BuiltBrokenModding.
the class ItemRocketLauncher method onItemRightClick.
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
if (!world.isRemote) {
long clickMs = System.currentTimeMillis();
if (clickTimePlayer.containsKey(player.getCommandSenderName())) {
if (clickMs - clickTimePlayer.get(player.getCommandSenderName()) < firingDelay) {
//TODO play weapon empty click audio to note the gun is reloading
return itemStack;
}
}
if (this.getEnergy(itemStack) >= ENERGY || player.capabilities.isCreativeMode) {
// Check the player's inventory and look for missiles.
for (int slot = 0; slot < player.inventory.getSizeInventory(); slot++) {
ItemStack inventoryStack = player.inventory.getStackInSlot(slot);
if (inventoryStack != null) {
if (inventoryStack.getItem() instanceof ItemMissile) {
int meta = inventoryStack.getItemDamage();
Explosives ex = Explosives.get(meta);
ExplosivePreDetonationEvent evt = new ExplosivePreDetonationEvent(world, player.posX, player.posY, player.posZ, ExplosiveType.AIR, Explosives.get(meta).handler);
MinecraftForge.EVENT_BUS.post(evt);
if (((Explosion) ex.handler) != null && !evt.isCanceled()) {
// Limit the missile to tier two.
if ((((Explosion) ex.handler).getTier() <= Settings.MAX_ROCKET_LAUCNHER_TIER || Engine.runningAsDev) && ((Explosion) ex.handler).isCruise()) {
EntityMissile entityMissile = new EntityMissile(player);
entityMissile.missileType = EntityMissile.MissileType.LAUNCHER;
entityMissile.explosiveID = ex;
entityMissile.acceleration = 1;
entityMissile.launch(null);
world.spawnEntityInWorld(entityMissile);
if (player.isSneaking()) {
player.mountEntity(entityMissile);
player.setSneaking(false);
}
if (!player.capabilities.isCreativeMode) {
player.inventory.setInventorySlotContents(slot, null);
player.inventoryContainer.detectAndSendChanges();
this.discharge(itemStack, ENERGY, true);
}
//Store last time player launched a rocket
clickTimePlayer.put(player.getCommandSenderName(), clickMs);
return itemStack;
}
} else {
player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("message.launcher.protected")));
}
}
}
}
}
}
return itemStack;
}
Aggregations