Дюп

svk

1,185
3
Код:
    public void reload(EntityPlayer player, World world, ItemStack item)
    {
        if(BaseClassMod.Server)
            if(!world.isRemote)
                if(player.getCurrentEquippedItem() != null)
                    if(player.getCurrentEquippedItem().getItem() == item.getItem())
                        if(!item.getTagCompound().getBoolean("loadedAmmo"))
                        {
                            player.getEntityData().getCompoundTag("industrialGuns").setLong("lastShot", (long) (System.currentTimeMillis() + reloadDuration));

                            if(player.inventory.hasItem(ammo))
                            {
                                int slotAmmo = 0;
                                ItemStack itemAmmo = null;

                                for (int j = 0; j < player.inventory.getSizeInventory(); j++)
                                {
                                    ItemStack item2 = player.inventory.getStackInSlot(j);

                                    if (item2 != null && item2.getItem() == ammo)
                                    {
                                        if(itemAmmo == null)
                                        {
                                            itemAmmo = item2;
                                        }
                                            
                                        if(item2.getTagCompound().getInteger("isAmount") >= itemAmmo.getTagCompound().getInteger("isAmount"))
                                        {
                                            itemAmmo = item2;
                                            slotAmmo = j;
                                        }

                                        if(item2.getTagCompound().getInteger("isAmount") == ((Ammo) ammo).amount)
                                        {
                                            break;
                                        }
                                    }
                                }

                                item.getTagCompound().setInteger("count", itemAmmo.getTagCompound().getInteger("isAmount"));
                                item.getTagCompound().setBoolean("loadedAmmo", true);
                                
                                world.playSound(player.posX, player.posY, player.posZ, ModInfo.MODID + ":" + sound + "Reload", 0.6F, 1, true);

                                if(itemAmmo.stackSize > 1)
                                {
                                    --itemAmmo.stackSize;
                                }
                                else
                                {
                                    player.inventory.setInventorySlotContents(slotAmmo, null);
                                }
                            }
                        }
                        else
                        {                
                            ItemStack item2 = new ItemStack(ammo);

                            NBTTagCompound nbt = item2.stackTagCompound = new NBTTagCompound();
                            nbt.setInteger("isAmount", item.getTagCompound().getInteger("count"));
                            player.inventory.addItemStackToInventory(item2);
                            item.getTagCompound().setInteger("count", 0);
                            item.getTagCompound().setBoolean("loadedAmmo", false);
                            world.playSound(player.posX, player.posY, player.posZ, ModInfo.MODID + ":" + sound + "Unload", 0.6F, 1, true);
                        }
    }

В чём дюп: 
Нажимаешь R оружие заряжает патроны.
Нажимаешь R оружие разряжает патроны.

Но если быстренько переместить разряженную обойму в другой слот и нажать R, то патроны опять разрядются. А если этого не делать - всё норм
[merge_posts_bbcode]Добавлено: 03.08.2015 19:48:38[/merge_posts_bbcode]

Дюп на сервере* Да и вообще, обновление НБТ происходит очень редко и индикатор патронов на клиенте тормозит. Может это как-то связанно?
 
Оказывается если игрок в креативе, то при открытии инвентаря сервер синхронизирует его с клиентом 0_o
Если перейти в другой режим всё ок.
Зачем это так?

Ну понятно, игрок ведь из гуи вещи берёт)
 
Назад
Сверху