• Register
    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Solved Ouvrir le guicrafting sur un tileEntity

    1.7.x
    1.7.2
    3
    6
    1285
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      PlagueZ last edited by

      Bonjour,

      je cherche a ouvrir le GuiCrafting vanilla de minecraft sur un tileEntity que j ai crée tout ce que j ai essayer jusque maintenant soit ca fonctionne pas soit le gui s affiche 1/2 seconde et disparait si vous avez une idée je suis preneur
      dans le block:

         @Override
         public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int metadata, float what, float these, float are) {
                 TileEntity tileEntity = world.getTileEntity(x, y, z);
                 if (tileEntity == null || player.isSneaking()) {
                         return false;
                 }
         //code to open gui explained later
         player.displayGUIWorkbench(x, y, z);
                 return true;
         }
      

      Handler:

      public class ViruZGuiHandler implements IGuiHandler{
      
      @Override
      public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
      TileEntity tile_entity = world.getTileEntity(x, y, z);
      if(tile_entity instanceof TileEntityWorkBench){
      return new ContainerWorkbench(player.inventory, world, x, y, z);
      }
      return null;
      }
      
      @Override
      public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
      TileEntity tile_entity = world.getTileEntity(x, y, z);
      if(tile_entity instanceof TileEntityWorkBench){
      return new GuiCrafting(player.inventory, world, x, y, z);
      }
      return null;
      }
      
      }
      register handler:
      

      @EventHandler
      public void load(FMLInitializationEvent event) {
      MinecraftForge.EVENT_BUS.register(new VirusZeventHandler());
      NetworkRegistry.INSTANCE.registerGuiHandler(this, new ViruZGuiHandler());
             if(event.getSide().isClient())
             {
      FMLCommonHandler.instance().bus().register(new KeyHandler());}
      }

      “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

      1 Reply Last reply Reply Quote 0
      • Phenix246
        Phenix246 Rédacteurs last edited by

        As tu enregistrer ton tileEntity ? as tu bien «rattaché» celui-ci à ton bloc ?

        donne nous également la classe de ton bloc et utilise les balises java, celui rend le code un peu plus lisible.

        Sinon as tu regarder comment c’est fait dans Minecraft en regardant le code du coffre ou du four

        1 Reply Last reply Reply Quote 0
        • robin4002
          robin4002 Moddeurs confirmés Rédacteurs Administrateurs last edited by

          Il faut faire ton propre gui. Le gui de base du workbench ne peut pas être utilisé autre part que sur le bloc de Minecraft

          1 Reply Last reply Reply Quote 0
          • P
            PlagueZ last edited by

            Voici la classe du block:

            package virusz.block;
            
            import net.minecraft.block.Block;
            import net.minecraft.block.material.Material;
            import net.minecraft.client.Minecraft;
            import net.minecraft.client.gui.inventory.GuiCrafting;
            import net.minecraft.entity.EntityLivingBase;
            import net.minecraft.entity.player.EntityPlayer;
            import net.minecraft.item.ItemStack;
            import net.minecraft.tileentity.TileEntity;
            import net.minecraft.util.MathHelper;
            import net.minecraft.world.World;
            import net.minecraftforge.common.util.ForgeDirection;
            import virusz.core.VirusZCore;
            import virusz.proxy.client.ClientProxy;
            import virusz.tileEntity.TileEntityWorkBench;
            
            public class BlockWorkbench extends Block {
            public BlockWorkbench(Material material) {
            super(material);
            this.setHardness(1.0F);
            }
            
            @Override
            public boolean hasTileEntity(int metadata) {
            return true;
            }
            
            @Override
            public TileEntity createTileEntity(World world, int metadata) {
            return new TileEntityWorkBench();
            }
            
               @Override
               public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int metadata, float what, float these, float are) {
                       TileEntity tileEntity = world.getTileEntity(x, y, z);
                       if (tileEntity == null || player.isSneaking()) {
                               return false;
                       }
                       player.displayGUIWorkbench(x, y, z);
                       return true;
               }
            
            public void onBlockPlacedBy(World world, int x, int y, int z,
            EntityLivingBase living, ItemStack stack) {
            if (stack.getItemDamage() == 0) {
            TileEntity tile = world.getTileEntity(x, y, z);
            if (tile instanceof TileEntityWorkBench) {
            int direction = MathHelper
            .floor_double((double) (living.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
            ((TileEntityWorkBench) tile).setDirection((byte) direction);
            }
            }
            }
            
            @Override
            public boolean rotateBlock(World world, int x, int y, int z,
            ForgeDirection axis) {
            if ((axis == ForgeDirection.UP || axis == ForgeDirection.DOWN)
            && !world.isRemote && world.getBlockMetadata(x, y, z) == 0) {
            TileEntity tile = world.getTileEntity(x, y, z);
            if (tile instanceof TileEntityWorkBench) {
            TileEntityWorkBench tileWorkbech = (TileEntityWorkBench) tile;
            byte direction = tileWorkbech.getDirection();
            direction++;
            if (direction > 3) {
            direction = 0;
            }
            tileWorkbech.setDirection(direction);
            return true;
            }
            }
            return false;
            }
            
            public ForgeDirection[] getValidRotations(World world, int x, int y, int z) {
            return world.getBlockMetadata(x, y, z) == 0 ? new ForgeDirection[] {
            ForgeDirection.UP, ForgeDirection.DOWN }
            : ForgeDirection.VALID_DIRECTIONS;
            }
            
            public boolean isOpaqueCube() {
            return false;
            }
            
            public boolean renderAsNormalBlock() {
            return false;
            }
            
            public int getRenderType() {
            return ClientProxy.renderInventoryTESRID;
            }
            }
            

            Créé les classe je veut bien mais même comme ca ca marche pas 😕 si tu as un tuto je suis preneur,
            ou le tile entity est bien enregistrer

            GameRegistry.registerTileEntity(TileEntityWorkBench.class, "workbench");
            

            et j ai regarder dans minecraft ils utilise la méthode que j utilise au dessus pour ouvrir le gui j’avoue ne pas trop comprendre comment marche l’ ouverture des gui en 1.7.2

            “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

            1 Reply Last reply Reply Quote 0
            • robin4002
              robin4002 Moddeurs confirmés Rédacteurs Administrateurs last edited by

              Youtube Video

              1 Reply Last reply Reply Quote 0
              • P
                PlagueZ last edited by

                Merci,

                ca fonctionne enfin je passe le sujet en resolut 😃

                “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Design by Woryk
                Contact / Mentions Légales

                MINECRAFT FORGE FRANCE © 2018

                Powered by NodeBB