Search in sources :

Example 1 with MessageSpeedloaderSync

use of blusunrize.immersiveengineering.common.util.network.MessageSpeedloaderSync in project ImmersiveEngineering by BluSunrize.

the class ItemRevolver method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack revolver, World world, EntityPlayer player, EnumHand hand) {
    if (!world.isRemote) {
        if (player.isSneaking() || revolver.getItemDamage() == 1) {
            CommonProxy.openGuiForItem(player, hand == EnumHand.MAIN_HAND ? EntityEquipmentSlot.MAINHAND : EntityEquipmentSlot.OFFHAND);
            return new ActionResult(EnumActionResult.SUCCESS, revolver);
        } else if (this.getUpgrades(revolver).getBoolean("nerf"))
            world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 1f, 0.6f);
        else {
            if (ItemNBTHelper.getInt(revolver, "cooldown") > 0)
                return new ActionResult(EnumActionResult.PASS, revolver);
            ItemStack[] bullets = getBullets(revolver);
            if (isEmpty(revolver)) {
                for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
                    ItemStack loader = player.inventory.getStackInSlot(i);
                    if (loader != null && loader.getItem() == this && loader.getItemDamage() == 1 && !isEmpty(loader)) {
                        int dc = 0;
                        for (ItemStack b : bullets) if (b != null) {
                            world.spawnEntityInWorld(new EntityItem(world, player.posX, player.posY, player.posZ, b));
                            dc++;
                        }
                        world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.PLAYERS, .5f, 3f);
                        ItemNBTHelper.setDelayedSoundsForStack(revolver, "casings", "random.successful_hit", .05f, 5, dc / 2, 8, 2);
                        setBullets(revolver, getBullets(loader));
                        setBullets(loader, new ItemStack[8]);
                        player.inventory.setInventorySlotContents(i, loader);
                        player.inventory.markDirty();
                        if (player instanceof EntityPlayerMP)
                            ImmersiveEngineering.packetHandler.sendTo(new MessageSpeedloaderSync(i), (EntityPlayerMP) player);
                        ItemNBTHelper.setBoolean(revolver, "blocked", true);
                        return new ActionResult(EnumActionResult.SUCCESS, revolver);
                    }
                }
            }
            if (!ItemNBTHelper.getBoolean(revolver, "blocked")) {
                if (bullets[0] != null && bullets[0].getItem() instanceof ItemBullet && ItemNBTHelper.hasKey(bullets[0], "bullet")) {
                    String key = ItemNBTHelper.getString(bullets[0], "bullet");
                    IBullet bullet = BulletHandler.getBullet(key);
                    if (bullet != null) {
                        Vec3d vec = player.getLookVec();
                        boolean electro = getUpgrades(revolver).getBoolean("electro");
                        int count = bullet.getProjectileCount(player);
                        if (count == 1) {
                            Entity entBullet = getBullet(player, vec, vec, key, bullets[0], electro);
                            player.worldObj.spawnEntityInWorld(bullet.getProjectile(player, bullets[0], entBullet, electro));
                        } else
                            for (int i = 0; i < count; i++) {
                                Vec3d vecDir = vec.addVector(player.getRNG().nextGaussian() * .1, player.getRNG().nextGaussian() * .1, player.getRNG().nextGaussian() * .1);
                                Entity entBullet = getBullet(player, vec, vecDir, key, bullets[0], electro);
                                player.worldObj.spawnEntityInWorld(bullet.getProjectile(player, bullets[0], entBullet, electro));
                            }
                        bullets[0] = bullet.getCasing(bullets[0]);
                        world.playSound(null, player.posX, player.posY, player.posZ, IESounds.revolverFire, SoundCategory.PLAYERS, 1f, 1f);
                    } else
                        world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.BLOCK_NOTE_HAT, SoundCategory.PLAYERS, 1f, 1f);
                } else
                    world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.BLOCK_NOTE_HAT, SoundCategory.PLAYERS, 1f, 1f);
                ItemStack[] cycled = new ItemStack[getBulletSlotAmount(revolver)];
                for (int i = 1; i < cycled.length; i++) cycled[i - 1] = bullets[i];
                cycled[cycled.length - 1] = bullets[0];
                setBullets(revolver, cycled);
                ItemNBTHelper.setInt(revolver, "cooldown", 10);
                return new ActionResult(EnumActionResult.SUCCESS, revolver);
            }
        }
    } else if (!player.isSneaking() && revolver.getItemDamage() == 0)
        return new ActionResult(ItemNBTHelper.getInt(revolver, "cooldown") > 0 ? EnumActionResult.PASS : EnumActionResult.SUCCESS, revolver);
    return new ActionResult(EnumActionResult.SUCCESS, revolver);
}
Also used : IBullet(blusunrize.immersiveengineering.api.tool.BulletHandler.IBullet) Entity(net.minecraft.entity.Entity) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) MessageSpeedloaderSync(blusunrize.immersiveengineering.common.util.network.MessageSpeedloaderSync) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

IBullet (blusunrize.immersiveengineering.api.tool.BulletHandler.IBullet)1 MessageSpeedloaderSync (blusunrize.immersiveengineering.common.util.network.MessageSpeedloaderSync)1 Entity (net.minecraft.entity.Entity)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ItemStack (net.minecraft.item.ItemStack)1 Vec3d (net.minecraft.util.math.Vec3d)1