Search in sources :

Example 6 with Explosion

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;
}
Also used : Explosion(icbm.classic.content.explosive.ex.Explosion) ExplosivePreDetonationEvent(resonant.api.explosion.ExplosionEvent.ExplosivePreDetonationEvent) Explosives(icbm.classic.content.explosive.Explosives) ItemStack(net.minecraft.item.ItemStack) ChatComponentText(net.minecraft.util.ChatComponentText) EntityMissile(icbm.classic.content.entity.EntityMissile)

Aggregations

Explosion (icbm.classic.content.explosive.ex.Explosion)6 Explosives (icbm.classic.content.explosive.Explosives)4 SideOnly (cpw.mods.fml.relauncher.SideOnly)2 EntityMissile (icbm.classic.content.entity.EntityMissile)2 Explosive (icbm.classic.content.explosive.Explosive)1 ItemStack (net.minecraft.item.ItemStack)1 ChatComponentText (net.minecraft.util.ChatComponentText)1 ExplosivePreDetonationEvent (resonant.api.explosion.ExplosionEvent.ExplosivePreDetonationEvent)1