MFF

    Minecraft Forge France
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes
    • Forge Events
      • Automatique
      • Foncé
      • Clair
    • S'inscrire
    • Se connecter

    Keybind défectueux

    Planifier Épinglé Verrouillé Déplacé Sans suite
    27 Messages 4 Publieurs 6.0k Vues 1 Watching
    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.
    • P Hors-ligne
      Portuar
      dernière édition par

      Bon j’ai un peu regarder, tester des truc mais aucune reponse voici mes codes :

      EventClass :

      package portuar.otherWorld.client.alteration;
      
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.potion.Potion;
      import net.minecraft.potion.PotionEffect;
      import net.minecraft.util.DamageSource;
      import net.minecraft.util.Vec3;
      import net.minecraftforge.event.entity.living.LivingAttackEvent;
      import net.minecraftforge.event.entity.player.AttackEntityEvent;
      import net.minecraftforge.event.entity.player.PlayerEvent;
      import portuar.otherWorld.client.MainClass;
      import portuar.otherWorld.client.alteration.firePower.EntityFireProjectile;
      import cpw.mods.fml.common.eventhandler.SubscribeEvent;
      import cpw.mods.fml.common.gameevent.TickEvent;
      import cpw.mods.fml.relauncher.Side;
      
      public class EventAlterationPower
      {
      
      public void alterationPowerkeybind(TickEvent.PlayerTickEvent event)
      {
      ExtendedEntityPropAlteration props = ExtendedEntityPropAlteration.get(event.player);
      
      if(MainClass.keyboard.isSpell1KeyDown(event.player))
      {
      System.out.println("????");
      }
      }
      
      }
      

      KeyboardClient :

      package portuar.otherWorld.proxy;
      
      import net.minecraft.client.settings.KeyBinding;
      
      import org.lwjgl.input.Keyboard;
      
      import portuar.otherWorld.client.MainClass;
      import portuar.otherWorld.client.alteration.KeyBindingAlteration;
      import portuar.otherWorld.client.alteration.PacketKeys;
      import portuar.otherWorld.client.alteration.firePower.EntityFireProjectile;
      import portuar.otherWorld.client.alteration.firePower.RenderFireProjectile;
      import cpw.mods.fml.client.FMLClientHandler;
      import cpw.mods.fml.client.registry.ClientRegistry;
      import cpw.mods.fml.client.registry.RenderingRegistry;
      import cpw.mods.fml.common.FMLCommonHandler;
      
      public class KeyboardClient extends KeyBindingAlteration
      {
      //RenderManager
      public static KeyBinding spell_1;
      public static KeyBinding spell_2;
      private int lastKeyState = 0;
      
      public KeyboardClient()
      {
      FMLCommonHandler.instance().bus().register(this);
      
      spell_1 = new KeyBinding("otherworld.spell_1", Keyboard.KEY_T, "key.categories.otherworld");
      spell_2 = new KeyBinding("otherworld.spell_2", Keyboard.KEY_C, "key.categories.otherworld");
      
      ClientRegistry.registerKeyBinding(spell_1);
      ClientRegistry.registerKeyBinding(spell_2);
      
      }
      
      public void sendKeyUpdate()
      {
      int currentKeyState = (this.spell_1.isPressed() ? 1 : 0) << 0 | (this.spell_2.isPressed() ? 1 : 0) << 1;
      if(currentKeyState != this.lastKeyState)
      {
      this.lastKeyState = currentKeyState;
      try
      {
      MainClass.packetHandler.sendToServer(new PacketKeys(currentKeyState));
      }
      catch(Exception exception)
      {
      MainClass.ugslogger.error("Failed to send a key packet");
      }
      super.processKeyUpdate(FMLClientHandler.instance().getClientPlayerEntity(), currentKeyState);
      }
      }
      
      }
      
      

      KeyBoard common :

      package portuar.otherWorld.client.alteration;
      
      import java.util.HashMap;
      import java.util.Map;
      
      import net.minecraft.entity.player.EntityPlayer;
      
      public class KeyBindingAlteration
      {
      private final Map <entityplayer, boolean="">spell_1 = new HashMap();
      private final Map <entityplayer, boolean="">spell_2 = new HashMap();
      
      public void registerKey()
      {
      
      }
      
      public boolean isSpell1KeyDown(EntityPlayer player)
      {
      if(this.spell_1.containsKey(player))
      {
      return this.spell_1.get(player);
      }
      return false;
      }
      
      public boolean isSpell2KeyDown(EntityPlayer player)
      {
      if(this.spell_2.containsKey(player))
      {
      return this.spell_2.get(player);
      }
      return false;
      }
      
      public void sendKeyUpdate()
      {}
      
      public void processKeyUpdate(EntityPlayer player, int keyState)
      {
      this.spell_1.put(player, Boolean.valueOf((keyState & 0x1) != 0));
      this.spell_2.put(player, Boolean.valueOf((keyState & 0x2) != 0));
      }
      
      public void removePlayerReferences(EntityPlayer player)
      {
      this.spell_1.remove(player);
      this.spell_2.remove(player);
      }
      }
      

      packet :

      
      package portuar.otherWorld.client.alteration;
      
      import io.netty.buffer.ByteBuf;
      import io.netty.channel.ChannelHandlerContext;
      
      import java.io.IOException;
      
      import cpw.mods.fml.common.network.ByteBufUtils;
      
      import portuar.otherWorld.client.MainClass;
      import portuar.otherWorld.proxy.ClientProxy;
      
      import net.minecraft.entity.player.EntityPlayer;
      
      public class PacketKeys extends AbstractPacket
      {
      private int keyState;
      
      public PacketKeys()
      {}
      
      public PacketKeys(int currentKeyState)
      {
      this.keyState = currentKeyState;
      }
      
      @Override
      public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer)
      {
      buffer.writeInt(this.keyState);
      }
      
      @Override
      public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer)
      {
      this.keyState = buffer.readInt();
      }
      
      @Override
      public void handleClientSide(EntityPlayer player)
      {
      
      }
      
      @Override
      public void handleServerSide(EntityPlayer player)
      {
      MainClass.keyboard.processKeyUpdate(player, this.keyState);
      }
      }
      ```</entityplayer,></entityplayer,>
      1 réponse Dernière réponse Répondre Citer 0
      • robin4002R Hors-ligne
        robin4002 Moddeurs confirmés Rédacteurs Administrateurs
        dernière édition par

        Tu as vérifie que le paquet s’envoie bien et qu’il est bien reçu ? (un petit System.out.println(“quelque chose”) quand le constructeur du paquet et dans la fonction handleServerSide)

        1 réponse Dernière réponse Répondre Citer 0
        • P Hors-ligne
          Portuar
          dernière édition par

          Non j ai mis un system.out.println dans handleserverside et rien dans la console

          1 réponse Dernière réponse Répondre Citer 0
          • robin4002R Hors-ligne
            robin4002 Moddeurs confirmés Rédacteurs Administrateurs
            dernière édition par

            Dans ce cas le problème vient du paquet, mon paquet est fait avec ffmtlib, je sais pas comment tu gère tes paquets, ça sera peut être différent du coup.

            1 réponse Dernière réponse Répondre Citer 0
            • P Hors-ligne
              Portuar
              dernière édition par

              Regarde si tu trouve une erreur voila :

              Dans ma class principale :

              package portuar.otherWorld.client;
              
              import net.minecraft.client.Minecraft;
              import net.minecraft.command.ICommandManager;
              import net.minecraft.command.ServerCommandManager;
              import net.minecraft.creativetab.CreativeTabs;
              import net.minecraft.item.Item;
              import net.minecraft.server.MinecraftServer;
              import net.minecraftforge.common.MinecraftForge;
              
              import org.apache.logging.log4j.Logger;
              
              import portuar.otherWorld.client.alteration.EventAlteration;
              import portuar.otherWorld.client.alteration.EventAlterationPower;
              import portuar.otherWorld.client.alteration.GuiEnergyBar;
              import portuar.otherWorld.client.alteration.KeyBindingAlteration;
              import portuar.otherWorld.client.alteration.PacketHandler;
              import portuar.otherWorld.client.items.ItemTest;
              import portuar.otherWorld.common.CommandOtherWorld;
              import portuar.otherWorld.proxy.CommonProxy;
              import cpw.mods.fml.common.FMLCommonHandler;
              import cpw.mods.fml.common.Mod;
              import cpw.mods.fml.common.Mod.EventHandler;
              import cpw.mods.fml.common.Mod.Instance;
              import cpw.mods.fml.common.SidedProxy;
              import cpw.mods.fml.common.event.FMLInitializationEvent;
              import cpw.mods.fml.common.event.FMLPostInitializationEvent;
              import cpw.mods.fml.common.event.FMLPreInitializationEvent;
              import cpw.mods.fml.common.event.FMLServerStartingEvent;
              import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
              import cpw.mods.fml.common.registry.GameRegistry;
              
              @Mod(modid = "otherworld", name = "OtherWorld", version = "0.0.1")
              
              public class MainClass
              {
              
              @Instance("otherworld")
              public static MainClass instance;
              
              @SidedProxy(clientSide = "portuar.otherWorld.proxy.ClientProxy", serverSide = "portuar.otherWorld.proxy.CommonProxy")
              public static CommonProxy proxy;
              
              @SidedProxy(clientSide = "portuar.otherWorld.proxy.KeyboardClient", serverSide = "portuar.otherWorld.alteration.client.KeyBindingAlteration")
              public static KeyBindingAlteration keyboard;
              public static Logger ugslogger;
              
              //public static Block Stasis;
              
              public static Item Catalyst;
              
              public static final PacketHandler packetHandler = new PacketHandler();
              
              @EventHandler
              public void preInit(FMLPreInitializationEvent event)
              {
              ugslogger = event.getModLog();
              }
              
              @EventHandler
              public void init(FMLInitializationEvent event)
              {
              packetHandler.initialise();
              
              registerEvent();
              
              proxy.registerRender();
              proxy.registerTileEntityRender();
              
              }
              
              @EventHandler
              public void postInit(FMLPostInitializationEvent event)
              {
              
              packetHandler.postInitialise();
              }
              
              }
              

              PacketKeys

              package portuar.otherWorld.client.alteration;
              
              import io.netty.buffer.ByteBuf;
              import io.netty.channel.ChannelHandlerContext;
              
              import java.io.IOException;
              
              import cpw.mods.fml.common.network.ByteBufUtils;
              
              import portuar.otherWorld.client.MainClass;
              import portuar.otherWorld.proxy.ClientProxy;
              
              import net.minecraft.entity.player.EntityPlayer;
              
              public class PacketKeys extends AbstractPacket
              {
              private int keyState;
              
              public PacketKeys()
              {}
              
              public PacketKeys(int currentKeyState)
              {
              this.keyState = currentKeyState;
              }
              
              @Override
              public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer)
              {
              buffer.writeInt(this.keyState);
              }
              
              @Override
              public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer)
              {
              this.keyState = buffer.readInt();
              }
              
              @Override
              public void handleClientSide(EntityPlayer player)
              {
              
              }
              
              @Override
              public void handleServerSide(EntityPlayer player)
              {
              System.out.println("SVAG");
              MainClass.keyboard.processKeyUpdate(player, this.keyState);
              }
              }
              

              Abstrack Packet

              package portuar.otherWorld.client.alteration;
              
              import io.netty.buffer.ByteBuf;
              import io.netty.channel.ChannelHandlerContext;
              import net.minecraft.entity.player.EntityPlayer;
              
              /**
              * AbstractPacket class. Should be the parent of all packets wishing to use the PacketPipeline.
              * @author sirgingalot
              */
              public abstract class AbstractPacket {
              
              /**
              * Encode the packet data into the ByteBuf stream. Complex data sets may need specific data handlers (See @link{cpw.mods.fml.common.network.ByteBuffUtils})
              *
              * @param ctx channel context
              * @param buffer the buffer to encode into
              */
              public abstract void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer);
              
              /**
              * Decode the packet data from the ByteBuf stream. Complex data sets may need specific data handlers (See @link{cpw.mods.fml.common.network.ByteBuffUtils})
              *
              * @param ctx channel context
              * @param buffer the buffer to decode from
              */
              public abstract void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer);
              
              /**
              * Handle a packet on the client side. Note this occurs after decoding has completed.
              *
              * @param player the player reference
              */
              public abstract void handleClientSide(EntityPlayer player);
              
              /**
              * Handle a packet on the server side. Note this occurs after decoding has completed.
              *
              * @param player the player reference
              */
              public abstract void handleServerSide(EntityPlayer player);
              }
              

              PacketHandler

              package portuar.otherWorld.client.alteration;
              
              import java.util.*;
              
              import io.netty.buffer.ByteBuf;
              import io.netty.buffer.Unpooled;
              import io.netty.channel.ChannelHandler;
              import io.netty.channel.ChannelHandlerContext;
              import io.netty.handler.codec.MessageToMessageCodec;
              
              import net.minecraft.client.Minecraft;
              import net.minecraft.entity.player.EntityPlayer;
              import net.minecraft.entity.player.EntityPlayerMP;
              import net.minecraft.network.INetHandler;
              import net.minecraft.network.NetHandlerPlayServer;
              
              import cpw.mods.fml.common.FMLCommonHandler;
              import cpw.mods.fml.common.network.FMLEmbeddedChannel;
              import cpw.mods.fml.common.network.FMLOutboundHandler;
              import cpw.mods.fml.common.network.NetworkRegistry;
              import cpw.mods.fml.common.network.internal.FMLProxyPacket;
              import cpw.mods.fml.relauncher.Side;
              import cpw.mods.fml.relauncher.SideOnly;
              
              /**
              * Packet pipeline class. Directs all registered packet data to be handled by the packets themselves.
              * @author sirgingalot
              * some code from: cpw
              */
              @ChannelHandler.Sharable
              public class PacketHandler extends MessageToMessageCodec <fmlproxypacket, abstractpacket="">{
              
              private EnumMap <side, fmlembeddedchannel="">channels;
              private LinkedList<class<? extends="" abstractpacket="">> packets = new LinkedList<class<? extends="" abstractpacket="">>();
              private boolean isPostInitialised = false;
              
              /**
              * Register your packet with the pipeline. Discriminators are automatically set.
              *
              * @param clazz the class to register
              *
              * @return whether registration was successful. Failure may occur if 256 packets have been registered or if the registry already contains this packet
              */
              public boolean registerPacket(Class clazz) {
              if (this.packets.size() > 256)
              {
              return false;
              }
              
              if (this.packets.contains(clazz))
              {
              return false;
              }
              
              if (this.isPostInitialised)
              {
              return false;
              }
              
              this.packets.add(clazz);
              return true;
              }
              
              @Override
              protected void encode(ChannelHandlerContext ctx, AbstractPacket msg, List <object>out) throws Exception {
              ByteBuf buffer = Unpooled.buffer();
              Class clazz = msg.getClass();
              if (!this.packets.contains(msg.getClass())) {
              throw new NullPointerException("No Packet Registered for: " + msg.getClass().getCanonicalName());
              }
              
              byte discriminator = (byte) this.packets.indexOf(clazz);
              buffer.writeByte(discriminator);
              msg.encodeInto(ctx, buffer);
              FMLProxyPacket proxyPacket = new FMLProxyPacket(buffer.copy(), ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
              out.add(proxyPacket);
              }
              
              @Override
              protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List <object>out) throws Exception {
              ByteBuf payload = msg.payload();
              byte discriminator = payload.readByte();
              Class clazz = this.packets.get(discriminator);
              if (clazz == null) {
              throw new NullPointerException("No packet registered for discriminator: " + discriminator);
              }
              
              AbstractPacket pkt = clazz.newInstance();
              pkt.decodeInto(ctx, payload.slice());
              
              EntityPlayer player;
              switch (FMLCommonHandler.instance().getEffectiveSide()) {
              case CLIENT:
              player = this.getClientPlayer();
              pkt.handleClientSide(player);
              break;
              
              case SERVER:
              INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
              player = ((NetHandlerPlayServer) netHandler).playerEntity;
              pkt.handleServerSide(player);
              break;
              
              default:
              }
              
              out.add(pkt);
              }
              
              public void initialise() {
              this.channels = NetworkRegistry.INSTANCE.newChannel("TUT", this);
              }
              
              public void postInitialise() {
              if (this.isPostInitialised) {
              return;
              }
              
              this.isPostInitialised = true;
              Collections.sort(this.packets, new Comparator<class<? extends="" abstractpacket="">>() {
              
              @Override
              public int compare(Class clazz1, Class clazz2) {
              int com = String.CASE_INSENSITIVE_ORDER.compare(clazz1.getCanonicalName(), clazz2.getCanonicalName());
              if (com == 0) {
              com = clazz1.getCanonicalName().compareTo(clazz2.getCanonicalName());
              }
              
              return com;
              }
              });
              }
              
              @SideOnly(Side.CLIENT)
              private EntityPlayer getClientPlayer() {
              return Minecraft.getMinecraft().thePlayer;
              }
              
              /**
              * Send this message to everyone.
              *
              
              * Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
              *
              * @param message The message to send
              */
              public void sendToAll(AbstractPacket message) {
              this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL);
              this.channels.get(Side.SERVER).writeAndFlush(message);
              }
              
              /**
              * Send this message to the specified player.
              *
              
              * Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
              *
              * @param message The message to send
              * @param player The player to send it to
              */
              public void sendTo(AbstractPacket message, EntityPlayerMP player) {
              this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER);
              this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player);
              this.channels.get(Side.SERVER).writeAndFlush(message);
              }
              
              /**
              * Send this message to everyone within a certain range of a point.
              *
              
              * Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
              *
              * @param message The message to send
              * @param point The {@link cpw.mods.fml.common.network.NetworkRegistry.TargetPoint} around which to send
              */
              public void sendToAllAround(AbstractPacket message, NetworkRegistry.TargetPoint point) {
              this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT);
              this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(point);
              this.channels.get(Side.SERVER).writeAndFlush(message);
              }
              
              /**
              * Send this message to everyone within the supplied dimension.
              *
              
              * Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
              *
              * @param message The message to send
              * @param dimensionId The dimension id to target
              */
              public void sendToDimension(AbstractPacket message, int dimensionId) {
              this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.DIMENSION);
              this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(dimensionId);
              this.channels.get(Side.SERVER).writeAndFlush(message);
              }
              
              /**
              * Send this message to the server.
              *
              
              * Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
              *
              * @param message The message to send
              */
              public void sendToServer(AbstractPacket message) {
              this.channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.TOSERVER);
              this.channels.get(Side.CLIENT).writeAndFlush(message);
              }
              }
              ```</class<?></object></object></class<?></class<?></side,></fmlproxypacket,>
              1 réponse Dernière réponse Répondre Citer 0
              • robin4002R Hors-ligne
                robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                dernière édition par

                Il faut que tu enregistre la classe du paquet.
                packetHandler.registerPacket(PacketKeys.class)
                Par contre je te déconseille ce système de paquet, il cause des fuites de mémoire.

                1 réponse Dernière réponse Répondre Citer 0
                • P Hors-ligne
                  Portuar
                  dernière édition par

                  Non toujours rien quand j’appuie sur la touche et pour le packet, c’est le seul moyen que j’ai trouvé via un tuto pour créer des packet sans API.

                  1 réponse Dernière réponse Répondre Citer 0
                  • P Hors-ligne
                    Portuar
                    dernière édition par

                    up je n’y suis toujours pas arriver !

                    1 réponse Dernière réponse Répondre Citer 0
                    • P Hors-ligne
                      Portuar
                      dernière édition par

                      Bon tout fonctionne coté client mais rien ne ce passe quand je suis sur un serveur !

                      1 réponse Dernière réponse Répondre Citer 0
                      • robin4002R Hors-ligne
                        robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                        dernière édition par

                        le System.out.println(“SVAG”);
                        s’affiche ?

                        1 réponse Dernière réponse Répondre Citer 0
                        • P Hors-ligne
                          Portuar
                          dernière édition par

                          ahah ouai mais en client pas en serveur :s

                          1 réponse Dernière réponse Répondre Citer 0
                          • robin4002R Hors-ligne
                            robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                            dernière édition par

                            What ?

                            @Override
                            public void handleServerSide(EntityPlayer player)
                            {
                            System.out.println("SVAG");
                            MainClass.keyboard.processKeyUpdate(player, this.keyState);
                            }
                            

                            Il faut ça en client mais pas un serveur ? ça devrait être l’inverse, faut que tu revoie ton système de paquet.

                            1 réponse Dernière réponse Répondre Citer 0
                            • P Hors-ligne
                              Portuar
                              dernière édition par

                              Non enfete je dit que des bêtise désoler, j’avais mis le même System.out.println dans l’eventHandler ! Non il n’y a pas SVAG ni du coté client ni du coté server

                              1 réponse Dernière réponse Répondre Citer 0
                              • robin4002R Hors-ligne
                                robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                                dernière édition par

                                Dans ce cas c’est que ton paquet n’est pas fonctionnel, je vais voir pour faire un tutoriel sur les paquets au plus vite.

                                1 réponse Dernière réponse Répondre Citer 0
                                • P Hors-ligne
                                  Portuar
                                  dernière édition par

                                  Pourtant j ai regarder le tutoriel que tout le monde sur minecraft forum conseille!

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

                                  MINECRAFT FORGE FRANCE © 2024

                                  Powered by NodeBB