Jump to content

[Solved]Packets...


Naiten

Recommended Posts

Hello. I've read the tutorial about packets and understand that they are used to transfer data between server and client side. There's said that packets are good for TE and GUI, but should i use them for usual entities or key bindings? If yes, tell me how, please.

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

Link to comment
Share on other sites

That tutorial only shows how to make a packet that does some some weird stuff with random numbers and i can hardly understand how to use that in my locomotive control system.

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

Link to comment
Share on other sites

uhm, what weird thing is it you don't understand?

If I recall correctly he is generating random numbers on the server side, then sending them to the client with a packet to display it on screen for the client?

 

In other words, it just shows how to transfer an int from server -> client.

It also states that you can send strings, floats etc. as well using the same procedure.

 

So what is it you are struggling with?

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

I've made a key handler that adds some motion to the locomotive the player is currently riding when key is pressed. It defines the key well and locomotive moves, but it gets teleported back after some seconds. I guess it's because of mistiming between server and client, so i have to use packets...

I send a packet in the key handler class... And where should i read it and apply changes to the entity?

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

Link to comment
Share on other sites

Yay, thanks, diesieben07. That actually helped. I'm only wodering now, am i doing it right?

 

package net.row;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.util.EnumSet;

import org.lwjgl.input.Keyboard;

import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.row.stock.LocoCherepanov;
import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler;
import cpw.mods.fml.common.TickType;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;

public class RoWKeyHandler extends KeyHandler {
    
    static KeyBinding ReverseUp = new KeyBinding("ReverseUp", Keyboard.KEY_R);

    public RoWKeyHandler() {
            super(new KeyBinding[]{ReverseUp}, new boolean[]{false});
    }
    @Override
    public String getLabel() {
            return "RoWKeyBindings";
    }
    @Override
    public void keyDown(EnumSet<TickType> types, KeyBinding kb,
                    boolean tickEnd, boolean isRepeat) {
    	if(kb.equals(ReverseUp)){
    		EntityPlayer player = Minecraft.getMinecraft().thePlayer;
    		if(player.ridingEntity instanceof LocoCherepanov){
    			LocoCherepanov loco = (LocoCherepanov) player.ridingEntity;
    			loco.reverse = -0.03F;
                
                ByteArrayOutputStream bos = new ByteArrayOutputStream(;
                DataOutputStream outputStream = new DataOutputStream(bos);
                try {
                	outputStream.writeFloat(loco.reverse);
                } catch (Exception ex) {
                        ex.printStackTrace();
                }
                
                Packet250CustomPayload packet = new Packet250CustomPayload();
                packet.channel = "RoWLocoControl";
                packet.data = bos.toByteArray();
                packet.length = bos.size();
                
                Side side = FMLCommonHandler.instance().getEffectiveSide();
                if (side == Side.CLIENT) {
                	EntityClientPlayerMP playerMP = (EntityClientPlayerMP) player;
                	playerMP.sendQueue.addToSendQueue(packet);
                }
             }
    	}
    }
    @Override
    public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd) {
    }
    @Override
    public EnumSet<TickType> ticks() {
            return EnumSet.of(TickType.CLIENT);
    }
}

 

package net.row;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.row.stock.LocoCherepanov;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;

public class RoWPacketHandler implements IPacketHandler {
        @Override
        public void onPacketData(INetworkManager manager,
                        Packet250CustomPayload packet, Player player) {
                
                if (packet.channel.equals("RoWLocoControl")) {
                        handleControl(packet, player);
                }
        }
        private void handleControl(Packet250CustomPayload packet, Player player) {
                DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
                float reverse;
                try {
                	reverse = inputStream.readFloat();
                	EntityPlayer entityPlayer = (EntityPlayer)player;
                	if(entityPlayer.ridingEntity instanceof LocoCherepanov){
                		LocoCherepanov loco = (LocoCherepanov) entityPlayer.ridingEntity;
                		loco.reverse = reverse;
                	}
                } catch (IOException e) {
                	e.printStackTrace();
                	return;
                }
        }

}

 

And one more question. If i perform some changes to entity motion and position variables, that are later used in default moveEntity(), in onUpdate() and locomotive movement is a bit glitchy (it does not get teleported back, but twitches), is that also a packet problem or not?

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • no this one https://pastebin.com/5uMxHeWf
    • I am in such a mess. I have lost over 4.7m due to a scammer... It started as bank wires and then bitcoin. it is hard to imagine but it is true and can send any proof, then I tried to use a couple of recovery companies and was as well. Graphic design has been more than just a hobby for me since high school—it has become a thriving career. Starting in my parents' garage, I eventually expanded to my office, running a successful graphic design business. However, like many, I faced the need to diversify my investments due to inflation. This led me to invest 60.16 in Bitcoin, a decision that paid off handsomely as my investment grew to 4.7m over time. This financial windfall allowed me to upgrade my equipment and take on more ambitious projects, furthering the growth of my business. Unfortunately, my excitement was abruptly cut short when I fell victim to a hacking incident. Malware infected my computer, giving hackers access to my Bitcoin wallet. The devastation of potentially losing all my hard-earned savings and plans weighed heavily on me. At this dire moment, a fellow designer suggested Linux Cyber Security Company as a potential solution. Desperate for a lifeline, I reached out to them, hoping for a miracle. The response from Linux Cyber Security Company was prompt, incredibly professional, and effective. Their team quickly traced the hacker’s activities and recovered most of my funds, alleviating a significant amount of stress and uncertainty. Beyond the recovery, they took the time to educate me on essential practices to secure my Bitcoin holdings better. They emphasized using antivirus software to prevent malware infections, avoiding suspicious downloads, and the added security provided by hardware wallets. This experience served as a critical wake-up call for me. It highlighted the vulnerabilities inherent in digital assets and underscored the importance of robust security measures. Thanks to the guidance and expertise of Linux Cyber Security Company, I now feel more equipped to protect my digital assets proactively. Their insights have empowered me to implement stronger security protocols in my business operations and personal finances alike. With my Bitcoin funds securely recovered and a newfound understanding of digital security best practices, I am more confident in navigating future challenges. This journey has reinforced my commitment to safeguarding my hard-earned assets and leveraging technology responsibly. I am optimistic about the growth opportunities ahead, creatively in graphic design and prudently in investment strategies. In conclusion, while the hacking incident was a setback, it ultimately became a catalyst for enhancing my digital security awareness and resilience. I am grateful to Linux Cyber Security Company for their expertise and support during a challenging time, enabling me to continue pursuing my passion for graphic design with renewed confidence and financial stability. Contact a professional company I am sure they can help you with your case too, Website [www.linuxcybersecurity.com Email the team; info@)(linuxcybersecurity.com
    • https://pastebin.com/B2HnBZTa
    • it was easy villager mate, thanks ill see how to do it without that mod! thanks
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.