Keybind défectueux



  • Bonjour, aujourd'hui j ai un petit problème concernant mais deux touches que je vient de créer en effet j ai créer deux évent différents tous deux avec l évent playerEvent mais voilà j appelé ma keybind avec ClientProxy.keybind.isPressed() le problème c est qu'elle fonctionne que dans une des deux alors que c est exactement la même chose et je ne comprend pas.


  • Moddeurs confirmés Modérateurs

    envoi t'es code


  • Modérateurs

    Tu peux donner tes codes car là, on peux pas t'aider.



  • Oui biensur :

    package portuar.otherWorld.client.alteration;
    
    import net.minecraft.client.Minecraft;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.nbt.NBTTagCompound;
    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.EntityEvent.EntityConstructing;
    import net.minecraftforge.event.entity.EntityJoinWorldEvent;
    import net.minecraftforge.event.entity.living.LivingAttackEvent;
    import net.minecraftforge.event.entity.living.LivingDeathEvent;
    import net.minecraftforge.event.entity.player.AttackEntityEvent;
    import net.minecraftforge.event.entity.player.PlayerEvent;
    import portuar.otherWorld.client.alteration.firePower.EntityFireProjectile;
    import portuar.otherWorld.proxy.ClientProxy;
    import portuar.otherWorld.proxy.CommonProxy;
    import cpw.mods.fml.client.FMLClientHandler;
    import cpw.mods.fml.common.eventhandler.SubscribeEvent;
    import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent;
    
    public class EventAlterationPower
    {
    
    @SubscribeEvent
    public void alterationPower_3(PlayerEvent event)
    {
    ExtendedEntityPropAlteration props = ExtendedEntityPropAlteration.get(event.entityPlayer);
    
    if(ClientProxy.spell_1.isPressed() == true)
    {
    if(props.getAlterationLvl() > 2 && props.getAlteration() == 0 && this.couldownFireBall > 40 && props.getCurrentEnergy() > this.energyPower_3)
    {
    
    }
    }
    
    }
    
    @SubscribeEvent
    public void alterationPower_6(PlayerEvent event)
    {
    
    ExtendedEntityPropAlteration props = ExtendedEntityPropAlteration.get(event.entityPlayer);
    
    if(ClientProxy.spell_1.isPressed())
    {
    if(props.getAlterationLvl() > 2 && props.getAlteration() == 1 && props.getCurrentEnergy() == props.getMaxEnergy())
    {
    
    }
    }
    }
    
    }
    
    

  • Moddeurs confirmés Rédacteurs Administrateurs

    Salut, TickEvent.Player ou InputEvent, avec cette event ça fonctionnera jamais.



  • Bah si vue que sa fonctionne lorsque je met qu'une des deux fonctions et puis elle est pratique puisqu avec inputEvent il y a cette histoire de packet !


    Je viens de pense à quelque chose que je ne peux malheureusement pas essayer tout de suite, peut on mettre deux event dans un même évent par exemple :
    Public voix monEvent(PlayerEvent enventp, InputEvent enventi)



  • Up !!!


  • Moddeurs confirmés Modérateurs

    Non tu ne peut pas mettre deux event en même temps



  • C'est asser problématique, avec PlayerEvent tout fonctionne bien en solo mais fais crasher le serveur donc il faudrait que j'utilise InputEvent mais bon comment appelé l'entity Player


  • Moddeurs confirmés Rédacteurs Administrateurs

    Dans tout les cas keybind n'existe que en client, sinon tu as TickEvent.PlayerTick



  • Mais je peux pas par exemple mettre une fonction avec inputEvent et quand j'appuie sur la touche il y a une variable qui se met sur true puis dans un eventPlayer si la variable est true alors je fais l'action désiré ?


    Bon enfete non vue que j'ai besoin de l'entity player pour mettre une valeur donc pas d'InputEvent! je vais tester avec TickEvent.PlayerTickEvent


  • Moddeurs confirmés Rédacteurs Administrateurs



  • 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,>

  • Moddeurs confirmés Rédacteurs Administrateurs

    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)



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


  • Moddeurs confirmés Rédacteurs Administrateurs

    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.



  • 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,>

  • Moddeurs confirmés Rédacteurs Administrateurs

    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.



  • 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.



  • up je n'y suis toujours pas arriver !


Log in to reply