Магазины для оружия

Версия Minecraft
1.12.2
API
Forge
31
1
1
Всем привет! Снова я,да уже надоел однако мне нужна помощь:
Может ли кто-нибудь обьяснить как делать магазины для оружия ,у меня уже есть код "забора" патронов из инвентаря,но я даже не представляю как можно преобразовать предмет в "список предметов"

ak_47:
public class ak_47 extends ItemBase implements IHasModel {
    public ak_47(String name){
        super(name);
        this.setCreativeTab(rustmod.guns);
        this.setMaxDamage(460);
        this.setMaxStackSize(1);
    }
    private ItemStack findAmmo(EntityPlayer player){
        if(this.isBullet(player.getHeldItem(EnumHand.OFF_HAND))){
            return player.getHeldItem(EnumHand.OFF_HAND);
        }
        else if(this.isBullet(player.getHeldItem(EnumHand.MAIN_HAND))){
            return player.getHeldItem(EnumHand.MAIN_HAND);
        }
        else{
            for (int i = 0; i < player.inventory.getSizeInventory(); ++i){
                ItemStack itemstack = player.inventory.getStackInSlot(i);
                if(this.isBullet(itemstack)){
                    return itemstack;
                }
            }
            return ItemStack.EMPTY;
        }
    }
    protected boolean isBullet(ItemStack stack){return stack.getItem() instanceof Bulletak; }

    public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn){
        boolean flag = !this.findAmmo(playerIn).isEmpty();

        ItemStack itemstack = this.findAmmo(playerIn);
        ItemStack IteMstack = playerIn.getHeldItem(handIn);

        boolean flag1 = playerIn.capabilities.isCreativeMode || (itemstack.getItem() instanceof ItemArrow && ((Bulletak)  itemstack.getItem()).isInfinite(itemstack,itemstack ,playerIn));

        if(!playerIn.capabilities.isCreativeMode && !flag){
            return flag ? new ActionResult(EnumActionResult.PASS,IteMstack): new ActionResult(EnumActionResult.FAIL, IteMstack);
        }else{
            if(!worldIn.isRemote){
                EntityBulletak entitysnowball = new EntityBulletak(worldIn,playerIn);

                int a = 1;
                int k = 0;
                int max = 30;
                while (entitysnowball == new EntityBulletak(worldIn,playerIn)){
                    a++;
                    if(a >= max)
                        a = 1;
                    playerIn.getCooldownTracker().setCooldown(this,10);
                }



                entitysnowball.shoot(playerIn, playerIn.rotationPitch,playerIn.rotationYaw, 0.0F,2.5F,2.0F);
                worldIn.spawnEntity(entitysnowball);
                playerIn.rotationPitch = entitysnowball.rotationPitch - 10 + new Random().nextInt(3);
                itemstack.damageItem(1,playerIn);

               /* if(worldIn.spawnEntity(entitysnowball)){
                    for (int i = 1; i < 30 ; i++){
                        if(i == 30)
                        i++;
                        playerIn.getCooldownTracker().setCooldown(this,10);
                        continue;
                    }
                }*/

            }


            worldIn.playSound((EntityPlayer) null, playerIn.posX,playerIn.posY,playerIn.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 10.0F , 0.4F / (itemRand.nextFloat() * -0.4F + 0.8F));
            if(!flag1 && !playerIn.capabilities.isCreativeMode){
                itemstack.shrink(1);
                if (itemstack.isEmpty()){
                    playerIn.inventory.deleteStack(itemstack);
                }
            }

            return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, IteMstack);
        }
    }
}
EntityBulletak:
public class EntityBulletak extends EntityThrowable {
    public EntityBulletak(World worldIn)
    {
        super(worldIn);
    }

    public EntityBulletak(World worldIn, EntityLivingBase throwerIn)
    {
        super(worldIn, throwerIn);
    }

    public EntityBulletak(World worldIn, double x, double y, double z)
    {
        super(worldIn, x, y, z);
    }

    public static void registerFixesBulletak(DataFixer fixer)
    {
        EntityThrowable.registerFixesThrowable(fixer, "Bulletak");
    }

    /**
     * Handler for {@link World#setEntityState}
     */
    @SideOnly(Side.CLIENT)
    public void handleStatusUpdate(byte id)
    {
        if (id == 3)
        {
            for (int i = 0; i < 8; ++i)
            {

            }
        }
    }

    /**
     * Called when this EntityThrowable hits a block or entity.
     */
    protected void onImpact(RayTraceResult result)
    {
        if (result.entityHit != null)
        {
            int i = 10;



            result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i);
        }

        if (!this.world.isRemote)
        {
            this.world.setEntityState(this, (byte)3);
            this.setDead();
        }
    }

}

Bulletak:
public class Bulletak extends ItemBase implements IHasModel {
    public Bulletak(String name){
        super(name);
        this.setCreativeTab(rustmod.guns);
        this.setMaxStackSize(64);
        setUnlocalizedName("Bulletak");

        initItems.ITEMS.add(this);
    }
    public boolean isInfinite(ItemStack stack, ItemStack Semi_rifle, net.minecraft.entity.player.EntityPlayer player)
    {
        int enchant = net.minecraft.enchantment.EnchantmentHelper.getEnchantmentLevel(net.minecraft.init.Enchantments.INFINITY, Semi_rifle);
        return enchant <= 0 ? false : this.getClass() == Bulletak.class;
    }

    @Override
    public void registerModels() {

        rustmod.proxy.registerItemRenderer(this,0 , "inventory");
    }

}

Прокси:
CommonProxy:
@Mod.EventBusSubscriber(Side.CLIENT)
public class CommonProxy {
   public void registerItemRenderer(Item item, int meta, String id){}


   public void preInit(FMLPreInitializationEvent event) {
      EntityRegistry.registerModEntity(new ResourceLocation("rustmod", "Rocket"), EntityRocket.class, "rustmod:Rocket", 0, rustmod.instance, 64, 20, true);


      EntityRegistry.registerModEntity(new ResourceLocation("rustmod","Bulletak"), EntityBulletak.class, "rustmod.Bulletak",1, rustmod.instance, 64, 20,true );
      EntityRegistry.registerModEntity(new ResourceLocation("rustmod","BulletPistol"), EntityBulletPistol.class, "rustmod.Bulletak",2, rustmod.instance, 64, 20,true );
      EntityRegistry.registerModEntity(new ResourceLocation("rustmod","BulletShotgun"), EntityBulletShotgun.class, "rustmod.Bulletak",3, rustmod.instance, 64, 20,true );

      }



   public void init(FMLInitializationEvent event) {

   }

   public void postInit(FMLPostInitializationEvent event) {
   }

ClientProxy:
public class ClientProxy extends CommonProxy{







    public void registerItemRenderer(Item item , int meta, String id){

           ModelLoader.setCustomModelResourceLocation(item,meta, new ModelResourceLocation(item.getRegistryName(),id));



       }



    @Override

    public void preInit(FMLPreInitializationEvent event) {

        super.preInit(event);



        RenderingRegistry.registerEntityRenderingHandler(EntityRocket.class, new SnowballRenderFactory(initItems.Rocket));

        RenderingRegistry.registerEntityRenderingHandler(EntityBulletak.class,new SnowballRenderFactory(initItems.Bulletak));

        RenderingRegistry.registerEntityRenderingHandler(EntityBulletPistol.class,new SnowballRenderFactory(initItems.BulletPistol));

        RenderingRegistry.registerEntityRenderingHandler(EntityBulletShotgun.class,new SnowballRenderFactory(initItems.BulletShotgun));

    }

}
 
681
20
319
Не буду показывать кодом как это делать, но обьясню на пальцах
Данный способ хорош только в том случае, если у тебя не будет разных типов патронов
Создаем любой предмет и например делаем ему setmaxdamage 30
Тоесть максимальное количество использования предмета 30
Потом при зарядке магазине в пушку, мы сохраняем предмет в нбт пушки
Как только мы сделали выстрел, мы получаем с нбт пушки наш магазин, проверяем что в нем количество использований не 0, и отнимаем у него одно использование
 
Как вариант,можно сделать так:
Создаёшь отдельный слот в инвентаре(вкладку),создаёшь предмет "коробка патронов + name там твоих патронов\оружия"
После этого,ты добавляешь гуи + контейнер для данного итема.
Далее прописываешь возможность положить твой итем в слот.
После уже начинаешь работу с основной частью,а именно чтоб игрок мог открыть гуи,положить туда некое кол-во патронов(сохраняешь это всё в нбт)
Далее уже в самом оружие делаешь проверку,чтоб искал патроны не только в инвентаре,но и в слоте твоём,ну и чтоб искал int твоих патронов.

На словах легко конечно,но на деле будет чуть сложнее.
На 1.12.2 не был,поэтому утверждать как и что в плане кода там делать не могу.
 
Сверху