Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted

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

Posted

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.

Posted

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.

Posted

I just did it as was written in tutorial... And what about glitches?

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

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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