• S'inscrire
    • Se connecter
    • Recherche
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes

    Comment utiliser les capabilities sur mon inventaire custom ?

    Sans suite
    1.11.x
    3
    7
    1277
    Charger plus de messages
    • Du plus ancien au plus récent
    • Du plus récent au plus ancien
    • Les plus votés
    Répondre
    • Répondre à l'aide d'un nouveau sujet
    Se connecter pour répondre
    Ce sujet a été supprimé. Seuls les utilisateurs avec les droits d'administration peuvent le voir.
    • Snyker
      Snyker dernière édition par

      Bonjour,

      Donc après avoir fait mon inventaire custom, je bloque à problème, stockées les slots que j’ai ajoutée. J’ai essayer de comprendre la doc, j’ai compris la moitié des trucs (Je sais qu’il me faut une interface, une class storage et une factory) j’ai regarder un post dans le support, (Sa ma pas aider plus que ça).

      Je tiens à préciser que mon inventaire marche, seul soucis il ne stock que les items liées à l’inventaire de minecraft (Et pas les miens).

      Voici toutes mes classes actuels (Sans les capabilities):

      #ArkofusContainerPlayer(ArkofusContainerPlayer)
      :::

      public class ArkofusContainerPlayer extends Container{
      
         private final EntityPlayer thePlayer;
      
         public ArkofusContainerPlayer(EntityPlayer player, InventoryPlayer inventoryPlayer, ArkofusInventoryPlayer arkofusInventoryPlayer) {
             this.thePlayer = player;
             this.bindArkofusInventory(arkofusInventoryPlayer);
             this.bindPlayerInventory(inventoryPlayer);
             this.bindArmorInventory(inventoryPlayer, arkofusInventoryPlayer);
         }
      
         private void bindPlayerInventory(InventoryPlayer inventoryPlayer) {
             //Inventaire
             for(int y = 0; y < 3; y++){
                 for(int x = 0; x < 9; x++){
                     this.addSlotToContainer(new Slot(inventoryPlayer, x + (y * 9) + 9, (96 + (x * 36)) / 2, (310 + (y * 36)) / 2));
                 }
             }
      
             //Item Armor Corps à Corps, Slot hot bar, index 0
             this.addSlotToContainer(new SlotArme(inventoryPlayer, 0, 64 / 2, 188 / 2));
      
             //HotBar Slot
             for(int x = 1; x < 9; x++){
                 this.addSlotToContainer(new Slot(inventoryPlayer, x, (114 + ((x-1) * 36)) / 2, 440 / 2));
             }
         }
      
         private void bindArkofusInventory(ArkofusInventoryPlayer arkofusInventoryPlayer) {
             for(int y = 0; y < 6; ++y) {
                 for(int x = 0; x < 5; ++x) {
                     this.addSlotToContainer(new SlotCustom(arkofusInventoryPlayer, x + (y * 10) + 10, (298 + (36 * x)) / 2, (62 + (36 * y)) / 2));
                 }
             }
         }
      
         private void bindArmorInventory(InventoryPlayer inventoryPlayer, ArkofusInventoryPlayer arkofusInventoryPlayer) {
             //Bouclier
             this.addSlotToContainer(new SlotArmor(this.thePlayer, inventoryPlayer, inventoryPlayer.getSizeInventory() - 1, 22 / 2, 188 / 2, 0));
      
             //Casque
             this.addSlotToContainer(new SlotArmor(this.thePlayer, inventoryPlayer, inventoryPlayer.getSizeInventory() - 2, 232 / 2, 62 / 2, 5));
             //Plastron
             this.addSlotToContainer(new SlotArmor(this.thePlayer, inventoryPlayer, inventoryPlayer.getSizeInventory() - 3, 232 / 2, 104 / 2, 4));
             //Pantalon
             this.addSlotToContainer(new SlotArmor(this.thePlayer, inventoryPlayer, inventoryPlayer.getSizeInventory() - 4, 232 / 2, 146 / 2, 3));
             //Boots
             this.addSlotToContainer(new SlotArmor(this.thePlayer, inventoryPlayer, inventoryPlayer.getSizeInventory() - 5, 232 / 2, 188 / 2, 2));
      
             //Amu
             this.addSlotToContainer(new SlotAmulette(arkofusInventoryPlayer, 0, 22/2, 62/2));
      
             //Anneau
             this.addSlotToContainer(new SlotAnneau(arkofusInventoryPlayer, 1, 22/2, 104/2));
             this.addSlotToContainer(new SlotAnneau(arkofusInventoryPlayer, 2, 22/2, 146/2));
      
             //Dofus
             for(int x = 0; x < 6; ++x){
                 this.addSlotToContainer(new SlotArkofus(arkofusInventoryPlayer, 3 + x, (22 +(x * 42)) /2, 230/2));
             }
         }
      
         @Override
         public boolean canInteractWith(EntityPlayer playerIn) {
             return true;
         }
      
      }
      

      :::

      #GuiInventoryPlayer(GuiInventoryPlayer)
      :::

      public class GuiInventoryPlayer extends GuiContainer {
      
         EntityPlayer player;
         int oldMouseY;
         int oldMouseX;
      
         public GuiInventoryPlayer(EntityPlayer player, InventoryPlayer inventoryPlayer, ArkofusInventoryPlayer inventoryCustom) {
             super(new ArkofusContainerPlayer(player, inventoryPlayer, inventoryCustom));
             this.player = player;
             this.xSize = 512 / 2;
             this.ySize = 512 / 2;
         }
      
         @Override
         public boolean doesGuiPauseGame() {
             return false;
         }
      
         @Override
         public void drawScreen(int mouseX, int mouseY, float partialTicks) {
             super.drawScreen(mouseX, mouseY, partialTicks);
             this.oldMouseX = mouseX;
             this.oldMouseY = mouseY;
         }
      
         @Override
         protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
             this.fontRenderer.drawString(I18n.format("container.arkofus_inventory"), 216/2, 13/2, 0xfde43a); //On dessine le "titre" du gui, le I18n.format va traduire le texte donné, n'oubliez pas de l'ajouter dans votre fichier de langues !
         }
      
         @Override
         protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
             GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
             this.mc.getTextureManager().bindTexture(new ResourceLocation(ArkofusUtils.MODID, "textures/gui/container/inventory_player.png"));
             this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0,0, this.xSize, this.ySize);
      
             this.drawEntityOnScreen(this.guiLeft + 75, this.guiTop + 98, 30, (float)(this.guiLeft + 51) - oldMouseX , (float)(this.guiTop+ 75 - 50) - this.oldMouseY, this.mc.player);
         }
      
         private void drawEntityOnScreen(int posX, int posY, int scale, float mouseX, float mouseY, EntityLivingBase ent) {
             GlStateManager.enableColorMaterial();
             GlStateManager.pushMatrix();
             GlStateManager.translate((float)posX, (float)posY, 50.0F);
             GlStateManager.scale((float)(-scale), (float)scale, (float)scale);
             GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F);
             float f = ent.renderYawOffset;
             float f1 = ent.rotationYaw;
             float f2 = ent.rotationPitch;
             float f3 = ent.prevRotationYawHead;
             float f4 = ent.rotationYawHead;
             GlStateManager.rotate(135.0F, 0.0F, 1.0F, 0.0F);
             RenderHelper.enableStandardItemLighting();
             GlStateManager.rotate(-135.0F, 0.0F, 1.0F, 0.0F);
             GlStateManager.rotate(-((float)Math.atan((double)(mouseY / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F);
             ent.renderYawOffset = (float)Math.atan((double)(mouseX / 40.0F)) * 20.0F;
             ent.rotationYaw = (float)Math.atan((double)(mouseX / 40.0F)) * 40.0F;
             ent.rotationPitch = -((float)Math.atan((double)(mouseY / 40.0F))) * 20.0F;
             ent.rotationYawHead = ent.rotationYaw;
             ent.prevRotationYawHead = ent.rotationYaw;
             GlStateManager.translate(0.0F, 0.0F, 0.0F);
             RenderManager rendermanager = Minecraft.getMinecraft().getRenderManager();
             rendermanager.setPlayerViewY(180.0F);
             rendermanager.setRenderShadow(false);
             rendermanager.doRenderEntity(ent, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, false);
             rendermanager.setRenderShadow(true);
             ent.renderYawOffset = f;
             ent.rotationYaw = f1;
             ent.rotationPitch = f2;
             ent.prevRotationYawHead = f3;
             ent.rotationYawHead = f4;
             GlStateManager.popMatrix();
             RenderHelper.disableStandardItemLighting();
             GlStateManager.disableRescaleNormal();
             GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit);
             GlStateManager.disableTexture2D();
             GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
         }
      
      }
      

      :::

      #ArkofusInventoryPlayer(ArkofusInventoryPlayer)
      :::

      public class ArkofusInventoryPlayer implements IInventory {
      
         private final String name = "Arkofus Inventory";
         private final String tagName = "ArkofusInvTag";
         public static final int INV_SIZE = 72;
         private NonNullList <itemstack>inventory = NonNullList.<itemstack>withSize(INV_SIZE, ItemStack.EMPTY);
      
         private EntityPlayer player;
      
         private ItemStackHandler stackHandler = new ItemStackHandler(INV_SIZE);
      
         private List <iinventorychangedlistener>changeListeners;
      
         public ArkofusInventoryPlayer(){}
      
         public ArkofusInventoryPlayer(EntityPlayer player) {
             this.player = player;
         }
      
         @Override
         public int getSizeInventory() {
             return INV_SIZE;
         }
      
         @Override
         public boolean isEmpty() {
             return inventory.isEmpty();
         }
      
         @Override
         public ItemStack getStackInSlot(int index) {
             return index >= 0 && index <= inventory.size() ? this.inventory.get(index) : ItemStack.EMPTY;
         }
      
         @Override
         public ItemStack decrStackSize(int index, int count) {
      
             ItemStack itemStack = getStackInSlot(index);
      
             if(!itemStack.isEmpty()){
                 if(itemStack.getCount() <= count) {
                     setInventorySlotContents(index, ItemStack.EMPTY);
                     this.markDirty();
                     return itemStack;
                 } else {
                     itemStack = getStackInSlot(index).splitStack(count);
                     if(getStackInSlot(index).getCount() <= 0) setInventorySlotContents(index, ItemStack.EMPTY);
                     else setInventorySlotContents(index, getStackInSlot(index));
                     markDirty();
                     return itemStack;
                 }
             }
      
             return ItemStack.EMPTY;
         }
      
         @Override
         public ItemStack removeStackFromSlot(int index) {
             ItemStack itemstack = getStackInSlot(index);
             setInventorySlotContents(index, ItemStack.EMPTY);
             return itemstack;
         }
      
         @Override
         public void setInventorySlotContents(int index, ItemStack stack) {
             if(index < 0 ||index >= inventory.size()) return;
             if(stack != ItemStack.EMPTY && stack.getCount() > this.getInventoryStackLimit()) stack.setCount(getInventoryStackLimit());
             if(stack != ItemStack.EMPTY && stack.getCount() == 0) stack = ItemStack.EMPTY;
             inventory.set(index, stack);
             this.markDirty();
         }
      
         @Override
         public int getInventoryStackLimit() {
             return 999;
         }
      
         @Override
         public void markDirty() {
             if (this.changeListeners != null) {
                 for (int i = 0; i < this.changeListeners.size(); ++i) {
                     ((IInventoryChangedListener)this.changeListeners.get(i)).onInventoryChanged(this);
                 }
             }
         }
      
         @Override
         public boolean isUsableByPlayer(EntityPlayer player) {
             return true;
         }
      
         @Override
         public void openInventory(EntityPlayer player) {
      
         }
      
         @Override
         public void closeInventory(EntityPlayer player) {}
      
         @Override
         public boolean isItemValidForSlot(int index, ItemStack stack) {
             //if(index == SLOT_Custom && item.getItem() instanceof ItemCustom) return true;
             return true;
         }
      
         @Override
         public int getField(int id) {
             return 0;
         }
      
         @Override
         public void setField(int id, int value) {}
      
         @Override
         public int getFieldCount() {
             return 0;
         }
      
         @Override
         public void clear() {
             for(int s = 0; s < inventory.size(); s++){
                 setInventorySlotContents(s, ItemStack.EMPTY);
             }
         }
      
         @Override
         public String getName() {
             return name;
         }
      
         @Override
         public boolean hasCustomName() {
             return name.length() > 0;
         }
      
         @Override
         public ITextComponent getDisplayName() {
             return new TextComponentString(name);
         }
      
      }
      

      :::

      #SlotCustom(SlotCustom)
      :::

      public class SlotCustom extends Slot {
      
         public SlotCustom(IInventory inventoryIn, int index, int xPosition, int yPosition) {
             super(inventoryIn, index, xPosition, yPosition);
         }
      
         @Override
         public int getItemStackLimit(ItemStack stack) {
             return 999;
         }
      
         @Override
         public boolean isItemValid(ItemStack itemstack) {
             return true;
         }
      }
      

      :::</iinventorychangedlistener></itemstack></itemstack>

      Aucune signature n'est disponible pour une barre chocolatée.

      1 réponse Dernière réponse Répondre Citer 0
      • SpyMan
        SpyMan dernière édition par

        Yo je crois que cela devrait d’aider https://www.minecraftforgefrance.fr/showthread.php?tid=905

        1 réponse Dernière réponse Répondre Citer 0
        • Snyker
          Snyker dernière édition par

          Déjà vue sauf que j’ai pas réussi à le convertir vers le Capability 😞

          Aucune signature n'est disponible pour une barre chocolatée.

          1 réponse Dernière réponse Répondre Citer 0
          • LeBossMax2
            LeBossMax2 dernière édition par

            Il existe une class qui permet de wrapper un IInventory en IItemHandler.

            1 réponse Dernière réponse Répondre Citer 0
            • Snyker
              Snyker dernière édition par

              @‘LeBossMax2’:

              Il existe une class qui permet de wrapper un IInventory en IItemHandler.

              Tu pourrais m’en dire plus s’il te plait ? Car j’ai trouver plusieurs class, comme le InvWrapper, SidedInvWrapper etc…

              Aucune signature n'est disponible pour une barre chocolatée.

              1 réponse Dernière réponse Répondre Citer 0
              • SpyMan
                SpyMan dernière édition par

                Je pense que ça pourrait d’aider https://github.com/coolAlias/Forge_Tutorials/blob/master/CustomPlayerInventory.java

                1 réponse Dernière réponse Répondre Citer 0
                • Snyker
                  Snyker dernière édition par

                  @‘SpyMan’:

                  Je pense que ça pourrait d’aider https://github.com/coolAlias/Forge_Tutorials/blob/master/CustomPlayerInventory.java

                  C’est grâce à lui que j’ai pu avoir mon inventaire, sauf que je n’arrive pas à le convertir vers les capabilities.

                  Edit : Je n’y arrive toujours pas xD

                  Aucune signature n'est disponible pour une barre chocolatée.

                  1 réponse Dernière réponse Répondre Citer 0
                  • 1 / 1
                  • Premier message
                    Dernier message
                  Design by Woryk
                  Contact / Mentions Légales

                  MINECRAFT FORGE FRANCE © 2018

                  Powered by NodeBB