Back pack



  • bien salut j'ai suivi le truc de scarex sur les back pack mais je ne sait pas comment adapter sa :

    
    [size=smallpackage] fr.scarex.tutorialmod;
    
    import net.minecraft.entity.player.EntityPlayer;
    
    import net.minecraft.world.World;
    
    import cpw.mods.fml.common.network.IGuiHandler;
    
    import fr.scarex.tutorialmod.client.gui.inventory.GuiBackPack;
    
    import fr.scarex.tutorialmod.inventory.InventoryBackPack;
    
    import fr.scarex.tutorialmod.inventory.container.ContainerBackPack;
    
    /**
    
     * @author SCAREX
    
     * 
    
     */
    
    public class CommonProxy implements IGuiHandler
    
    {
    
    @Override
    
    public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    
    switch (ID) {
    
    case 0:
    
    return new ContainerBackPack(player.inventory, new InventoryBackPack(player.getHeldItem(), 54));
    
    }
    
    return null;
    
    }
    
    @Override
    
    public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    
    switch (ID) {
    
    case 0:
    
    return new GuiBackPack(player.inventory, new InventoryBackPack(player.getHeldItem(), 54));
    
    }
    
    return null;
    
    }
    
    }
    
    

    a sa :

    package com.adamitemod.mod;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.world.World;
    import cpw.mods.fml.common.network.IGuiHandler;
    
    public class GuiHandler implements IGuiHandler
    {
        @Override
        public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
        {
            TileEntity tile = world.getTileEntity(x, y, z);
            if(tile instanceof TileEntityMachine)
    
            {
                return new ContainerMachine((TileEntityMachine)tile, player.inventory);
            }
            else if(tile instanceof TileEntityMachinePulveriser)
            {
                return new ContainerMachinePulveriser((TileEntityMachinePulveriser)tile, player.inventory);
            }
    
            return null;
        }
    
        @Override
        public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
        {
            TileEntity tile = world.getTileEntity(x, y, z);
            if(tile instanceof TileEntityMachine)
            {
                return new GuiMachine((TileEntityMachine)tile, player.inventory);
            }
    
            else if(tile instanceof TileEntityMachinePulveriser)
            {
                return new GuiMachinePulveriser((TileEntityMachinePulveriser)tile, player.inventory);
            }
    
            return null;
        }
    }
    

  • Administrateurs

    Salut,
    Il suffit de rajouter un else if :

    else if(ID == 0)
    {
    return new ContainerBackPack(player.inventory, new InventoryBackPack(player.getHeldItem(), 54));
    }
    

    En dessous des autres conditions.



  • ses bon mais sa crash voici mon crash report :

    –-- Minecraft Crash Report ----
    // I blame Dinnerbone.

    Time: 30/05/16 22:59
    Description: Unexpected error

    java.lang.ClassCastException: com.adamitemod.mod.ContainerBackPack cannot be cast to net.minecraft.client.gui.GuiScreen
    at cpw.mods.fml.client.FMLClientHandler.showGuiScreen(FMLClientHandler.java:471)
    at cpw.mods.fml.common.FMLCommonHandler.showGuiScreen(FMLCommonHandler.java:303)
    at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:94)
    at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501)
    at com.adamitemod.mod.items.ItemBackPack.onItemRightClick(ItemBackPack.java:31)
    at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:164)
    at net.minecraft.client.multiplayer.PlayerControllerMP.sendUseItem(PlayerControllerMP.java:430)
    at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1557)
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:2044)
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039)
    at net.minecraft.client.Minecraft.run(Minecraft.java:962)
    at net.minecraft.client.main.Main.main(Main.java:164)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
    at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
    at GradleStart.main(Unknown Source)

    A detailed walkthrough of the error, its code path and all known details is as follows:

    -- Head --
    Stacktrace:
    at cpw.mods.fml.client.FMLClientHandler.showGuiScreen(FMLClientHandler.java:471)
    at cpw.mods.fml.common.FMLCommonHandler.showGuiScreen(FMLCommonHandler.java:303)
    at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:94)
    at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501)
    at com.adamitemod.mod.items.ItemBackPack.onItemRightClick(ItemBackPack.java:31)
    at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:164)
    at net.minecraft.client.multiplayer.PlayerControllerMP.sendUseItem(PlayerControllerMP.java:430)
    at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1557)

    -- Affected level --
    Details:
    Level name: MpServer
    All players: 1 total; [EntityClientPlayerMP['Player265'/212, l='MpServer', x=-2,50, y=82,62, z=259,50]]
    Chunk stats: MultiplayerChunkCache: 25, 25
    Level seed: 0
    Level generator: ID 00 - default, ver 1. Features enabled: false
    Level generator options: 
    Level spawn location: World: (-12,64,256), Chunk: (at 4,4,0 in -1,16; contains blocks -16,0,256 to -1,255,271), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)
    Level time: 296 game time, 296 day time
    Level dimension: 0
    Level storage version: 0x00000 - Unknown?
    Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
    Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
    Forced entities: 27 total; [EntitySkeleton['Skeleton'/774, l='MpServer', x=-0,50, y=19,00, z=300,50], EntityClientPlayerMP['Player265'/212, l='MpServer', x=-2,50, y=82,62, z=259,50], EntityZombie['Zombie'/1206, l='MpServer', x=-2,00, y=20,00, z=292,44], EntityChicken['Chicken'/75, l='MpServer', x=-33,53, y=84,00, z=252,62], EntityChicken['Chicken'/76, l='MpServer', x=-34,38, y=87,00, z=259,56], EntityChicken['Chicken'/77, l='MpServer', x=-22,53, y=84,00, z=255,53], EntityChicken['Chicken'/78, l='MpServer', x=-29,39, y=90,80, z=260,72], EntityCreeper['Creeper'/718, l='MpServer', x=21,50, y=20,00, z=291,50], EntityChicken['Chicken'/79, l='MpServer', x=-11,50, y=79,00, z=294,50], EntityCreeper['Creeper'/719, l='MpServer', x=24,50, y=20,00, z=291,50], EntityChicken['Chicken'/80, l='MpServer', x=-13,50, y=78,00, z=293,50], EntityChicken['Chicken'/81, l='MpServer', x=-15,50, y=78,00, z=294,50], EntityCreeper['Creeper'/721, l='MpServer', x=35,99, y=18,84, z=286,81], EntityChicken['Chicken'/82, l='MpServer', x=-15,50, y=78,00, z=293,50], EntityBat['Bat'/466, l='MpServer', x=0,49, y=37,34, z=305,52], EntityChicken['Chicken'/83, l='MpServer', x=-7,44, y=82,00, z=238,11], EntityBat['Bat'/467, l='MpServer', x=-4,72, y=32,10, z=296,75], EntityChicken['Chicken'/84, l='MpServer', x=0,81, y=76,00, z=243,41], EntityChicken['Chicken'/85, l='MpServer', x=8,56, y=80,00, z=252,44], EntityChicken['Chicken'/86, l='MpServer', x=-0,84, y=77,00, z=240,72], EntityZombie['Zombie'/859, l='MpServer', x=3,50, y=36,00, z=297,50], EntityBat['Bat'/605, l='MpServer', x=-0,75, y=19,10, z=288,75], EntitySheep['Sheep'/103, l='MpServer', x=24,50, y=95,00, z=285,50], EntitySheep['Sheep'/104, l='MpServer', x=24,50, y=93,00, z=287,50], EntitySheep['Sheep'/105, l='MpServer', x=29,47, y=82,00, z=291,47], EntitySheep['Sheep'/106, l='MpServer', x=27,66, y=87,00, z=288,47], EntityCreeper['Creeper'/497, l='MpServer', x=10,50, y=34,00, z=286,50]]
    Retry entities: 0 total; []
    Server brand: fml,forge
    Server type: Integrated singleplayer server
    Stacktrace:
    at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415)
    at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2566)
    at net.minecraft.client.Minecraft.run(Minecraft.java:991)
    at net.minecraft.client.main.Main.main(Main.java:164)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
    at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
    at GradleStart.main(Unknown Source)

    – System Details --
    Details:
    Minecraft Version: 1.7.10
    Operating System: Windows 10 (x86) version 10.0
    Java Version: 1.8.0_66, Oracle Corporation
    Java VM Version: Java HotSpot(TM) Client VM (mixed mode), Oracle Corporation
    Memory: 726545040 bytes (692 MB) / 1046937600 bytes (998 MB) up to 1046937600 bytes (998 MB)
    JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
    AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
    IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95
    FML: MCP v9.05 FML v7.10.99.99 Minecraft Forge 10.13.4.1558 4 mods loaded, 4 mods active
    States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
    UCHIJAAAA mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) 
    UCHIJAAAA FML{7.10.99.99} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.4.1558-1.7.10.jar) 
    UCHIJAAAA Forge{10.13.4.1558} [Minecraft Forge] (forgeSrc-1.7.10-10.13.4.1558-1.7.10.jar) 
    UCHIJAAAA adamitemod{1.0.0} [Adamite Mod] (bin) 
    GL info: ' Vendor: 'Intel' Version: '4.0.0 - Build 10.18.10.4276' Renderer: 'Intel(R) HD Graphics'
    Launched Version: 1.7.10
    LWJGL: 2.9.1
    OpenGL: Intel(R) HD Graphics GL version 4.0.0 - Build 10.18.10.4276, Intel
    GL Caps: Using GL 1.3 multitexturing.
    Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
    Anisotropic filtering is supported and maximum anisotropy is 16.
    Shaders are available because OpenGL 2.1 is supported.

    Is Modded: Definitely; Client brand changed to 'fml,forge'
    Type: Client (map_client.txt)
    Resource Packs: []
    Current Language: English (US)
    Profiler Position: N/A (disabled)
    Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
    Anisotropic Filtering: Off (1)



  • ma class aussi -_- :

    package com.adamitemod.mod;
    
    import com.adamitemod.mod.items.ItemBackPack;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.InventoryPlayer;
    import net.minecraft.inventory.Container;
    import net.minecraft.inventory.Slot;
    import net.minecraft.item.ItemStack;
    import net.minecraft.nbt.NBTTagCompound;
    
    public class ContainerBackPack extends Container
    {
    public InventoryBackPack invBackpack;
    public int rows;
    
    public ContainerBackPack(InventoryPlayer playerInv, InventoryBackPack inv) {
    this.invBackpack = inv;
    this.rows = inv.getSizeInventory() / 9;
    int i = (this.rows - 4) * 18;
    int j;
    int k;
    
    for (j = 0; j < this.rows; ++j) {
    for (k = 0; k < 9; ++k) {
    this.addSlotToContainer(new SlotBackPack(inv, k + j * 9, 8 + k * 18, 18 + j * 18));
    }
    }
    
    for (j = 0; j < 3; ++j) {
    for (k = 0; k < 9; ++k) {
    this.addSlotToContainer(new Slot(playerInv, k + j * 9 + 9, 8 + k * 18, 103 + j * 18 + i));
    }
    }
    
    for (j = 0; j < 9; ++j) {
    this.addSlotToContainer(new Slot(playerInv, j, 8 + j * 18, 161 + i));
    }
    }
    
    @Override
    public boolean canInteractWith(EntityPlayer player) {
    return true;
    }
    
    public void writeToNBT(ItemStack stack) {
    if (!stack.hasTagCompound()) stack.setTagCompound(new NBTTagCompound());
    invBackpack.writeToNBT(stack.getTagCompound());
    }
    
    @Override
    public ItemStack transferStackInSlot(EntityPlayer player, int index) {
    ItemStack itemstack = null;
    Slot slot = (Slot) this.inventorySlots.get(index);
    
    if (slot != null && slot.getHasStack()) {
    ItemStack itemstack1 = slot.getStack();
    itemstack = itemstack1.copy();
    
    if (itemstack.getItem() instanceof ItemBackPack) return null;
    
    if (index < this.invBackpack.getSizeInventory()) {
    if (!this.mergeItemStack(itemstack1, this.invBackpack.getSizeInventory(), this.inventorySlots.size(), true)) return null;
    } else if (!this.mergeItemStack(itemstack1, 0, this.invBackpack.getSizeInventory(), false)) { return null; }
    
    if (itemstack1.stackSize == 0)
    slot.putStack((ItemStack) null);
    else
    slot.onSlotChanged();
    }
    
    return itemstack;
    }
    
    @Override
    public ItemStack slotClick(int slotIndex, int buttonPressed, int flag, EntityPlayer player) {
    
    if (flag == 2 && buttonPressed == player.inventory.currentItem) return null;
    if (slotIndex - this.invBackpack.getSizeInventory() - 27 == player.inventory.currentItem) return null;
    return super.slotClick(slotIndex, buttonPressed, flag, player);
    }
    
    @Override
    public void onContainerClosed(EntityPlayer player) {
    this.writeToNBT(player.getHeldItem());
    super.onContainerClosed(player);
    }
    }
    
    

  • Administrateurs

    Si tu retourne le container dans getClientGuiElement au lieu du gui c'est normal que ça crash.



  • j'ai pas compris 😢



  • Ses de sa que tu parle?

    package com.adamitemod.mod;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.world.World;
    import cpw.mods.fml.common.network.IGuiHandler;
    
    public class GuiHandler implements IGuiHandler
    {
        @Override
        public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
        {
            TileEntity tile = world.getTileEntity(x, y, z);
            if(tile instanceof TileEntityMachine)
    
            {
                return new ContainerMachine((TileEntityMachine)tile, player.inventory);
            }
            else if(tile instanceof TileEntityMachinePulveriser)
            {
                return new ContainerMachinePulveriser((TileEntityMachinePulveriser)tile, player.inventory);
            }
            else if(ID == 0)
            {
                return new ContainerBackPack(player.inventory, new InventoryBackPack(player.getHeldItem(), 54));
            }
            return null;
        }
    
        @Override
        public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
        {
            TileEntity tile = world.getTileEntity(x, y, z);
            if(tile instanceof TileEntityMachine)
            {
                return new GuiMachine((TileEntityMachine)tile, player.inventory);
            }
    
            else if(tile instanceof TileEntityMachinePulveriser)
            {
                return new GuiMachinePulveriser((TileEntityMachinePulveriser)tile, player.inventory);
            }
            else if(ID == 0)
            {
                return new ContainerBackPack(player.inventory, new InventoryBackPack(player.getHeldItem(), 54));
            }
    
            return null;
        }
    }
    

  • Administrateurs

    Dans getClientGuiElement tu dois mettre
    return new GuiBackPack(player.inventory, new InventoryBackPack(player.getHeldItem(), 54));
    au lieu de :
    return new ContainerBackPack(player.inventory, new InventoryBackPack(player.getHeldItem(), 54));