Jump to content

Recommended Posts

Posted

Is this a joke? Are you trolling?

 

Seriously, you give us nothing to work with. It's like phoning the doctor and screaming "Ouch it hurts!" without any further explanation.

because I don' t know what to show?

CommonProxy/ The Packet / PacketPipeLine / The ExtendedPlayer / MainClass

VampZ modder

Posted

Well, maybe you should first clarify what your "trouble" is...

I've trouble with sending a packet from server side to client side

It's my first time with packet sending

VampZ modder

Posted

Well, maybe you should first clarify what your "trouble" is...

I've trouble with sending a packet from server side to client side

It's my first time with packet sending

 

Have you searched for a tutorial? I believe diesieben07 has one on this forum.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Well, maybe you should first clarify what your "trouble" is...

I've trouble with sending a packet from server side to client side

It's my first time with packet sending

 

Have you searched for a tutorial? I believe diesieben07 has one on this forum.

 

Yeah I've searched some tutorials: CoolAlias's one but I find it still complex because it's my first time with the packethandler and sending packets

VampZ modder

Posted

PacketPipeLine

 

 

@ChannelHandler.Sharable

public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, AbstractPacket> {

 

private EnumMap<Side, FMLEmbeddedChannel>          channels;

    private LinkedList<Class<? extends AbstractPacket>> packets          = new LinkedList<Class<? extends AbstractPacket>>();

    private boolean                                    isPostInitialised = false;

 

    public boolean registerPacket(Class<? extends AbstractPacket> clazz) {

        if (this.packets.size() > 256) {

            // You should log here!!

            return false;

        }

 

        if (this.packets.contains(clazz)) {

            // You should log here!!

            return false;

        }

 

        if (this.isPostInitialised) {

            // You should log here!!

            return false;

        }

 

        this.packets.add(clazz);

        return true;

    }

   

    public void initialise() {

   

    this.channels = NetworkRegistry.INSTANCE.newChannel("VampZ", this); 

    registerPackets();

    }

   

    public void registerPackets() {

    registerPacket(SyncPlayerPropsPacket.class);

    }

    @Override

    protected void encode(ChannelHandlerContext ctx, AbstractPacket msg, List<Object> out) throws Exception {

        ByteBuf buffer = Unpooled.buffer();

        Class<? extends AbstractPacket> 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<? extends AbstractPacket> 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);

    }

   

    @SideOnly(Side.CLIENT)

    private EntityPlayer getClientPlayer() {

        return Minecraft.getMinecraft().thePlayer;

    }

   

    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);

    }

 

    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);

    }

 

    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);

    }

 

    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);

    }

 

    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);

    }

 

 

}

 

 

 

 

SyncPlayerPropsPacket

 

 

public class SyncPlayerPropsPacket extends AbstractPacket

{

 

private NBTTagCompound data;

 

public SyncPlayerPropsPacket() {}

 

public SyncPlayerPropsPacket(EntityPlayer player) {

data = new NBTTagCompound();

ExtendedPlayer.get(player).saveNBTData(data);

}

 

@Override

public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {

ByteBufUtils.writeTag(buffer, data);

}

 

@Override

public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {

data = ByteBufUtils.readTag(buffer);

}

 

@Override

public void handleClientSide(EntityPlayer player) {

ExtendedPlayer.get(player).loadNBTData(data);

}

 

@Override

public void handleServerSide(EntityPlayer player) {

}

}

 

 

 

ExtendedPlayer

 

 

package com.neosup.VampZ;

 

import ibxm.Player;

 

import java.io.ByteArrayOutputStream;

import java.io.DataOutputStream;

 

import net.minecraft.entity.Entity;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.EntityPlayerMP;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.world.World;

import net.minecraftforge.common.IExtendedEntityProperties;

 

import com.neosup.VampZ.network.SyncPlayerPropsPacket;

import com.neosup.VampZ.proxy.CommonProxy;

 

public class ExtendedPlayer implements IExtendedEntityProperties {

 

public final static String EXT_PROP_VZPLAYER = "ExtendedPlayer";

private final EntityPlayer player;

 

private int MaxLevel, CurrentVampLevel, CurrentWereLevel, CurrentPlayerLevel;

 

public ExtendedPlayer(EntityPlayer player){

this.player = player;

this.MaxLevel = 15;

}

 

public static final void register(EntityPlayer player){

player.registerExtendedProperties(ExtendedPlayer.EXT_PROP_VZPLAYER, new ExtendedPlayer(player));

}

 

public static final ExtendedPlayer get(EntityPlayer player){

return (ExtendedPlayer) player.getExtendedProperties(EXT_PROP_VZPLAYER);

}

 

public static void saveProxyData(EntityPlayer player) {

ExtendedPlayer playerData = ExtendedPlayer.get(player);

NBTTagCompound savedData = new NBTTagCompound();

}

 

private static final String getSaveKey(EntityPlayer player) {

return player.getCommandSenderName() + ":" + EXT_PROP_VZPLAYER;

}

 

 

@Override

public void saveNBTData(NBTTagCompound compound) {

NBTTagCompound properties = new NBTTagCompound();

properties.setInteger("CurrentPlayerLevel", this.CurrentPlayerLevel);

properties.setInteger("CurrentVampLevel", this.CurrentVampLevel);

properties.setInteger("CurrentWereLevel", this.CurrentWereLevel);

properties.setInteger("MaxLevel", this.MaxLevel);

compound.setTag(EXT_PROP_VZPLAYER, properties);

 

}

 

@Override

public void loadNBTData(NBTTagCompound compound) {

NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_VZPLAYER);

this.CurrentPlayerLevel = properties.getInteger("CurrentPlayerLevel");

this.CurrentVampLevel = properties.getInteger("CurrentVampLevel");

this.CurrentWereLevel = properties.getInteger("CurrentWereLevel");

this.MaxLevel = properties.getInteger("MaxLevel");

 

}

 

@Override

public void init(Entity entity, World world) {

}

 

public int getLevelVampire(){

return this.CurrentVampLevel;

}

 

public int getLevelWerewolf(){

return this.CurrentWereLevel;

}

 

public int getLevelHuman(){

return this.CurrentPlayerLevel;

}

 

public boolean CanPlayerLevel(){

if(this.getLevelHuman() < this.MaxLevel || this.getLevelVampire() < this.MaxLevel || this.getLevelWerewolf() < this.MaxLevel){

return true;

}else{

return false;

}

}

public int AddLevelVampire(int levelup){

return this.CurrentVampLevel += levelup;

}

 

public int AddLevelWerewolf(int levelup){

return this.CurrentWereLevel += levelup;

}

public int AddLevelPlayer(int levelup){

return this.CurrentPlayerLevel += levelup;

}

 

public static final void loadProxyData(EntityPlayer player) {

ExtendedPlayer playerData = ExtendedPlayer.get(player);

NBTTagCompound savedData = CommonProxy.getEntityData(getSaveKey(player));

if (savedData != null) { playerData.loadNBTData(savedData); }

MainClass.packetPipeline.sendTo(new SyncPlayerPropsPacket(player), (EntityPlayerMP) player);

}

 

/**

* Sends a packet to the client containing information stored on the server

* for ExtendedPlayer

*/

public final void sync()

{

ByteArrayOutputStream bos = new ByteArrayOutputStream(8);

DataOutputStream outputStream = new DataOutputStream(bos);

 

// We'll write max mana first so when we set current mana client

// side, it doesn't get set to 0 (see methods below)

try {

outputStream.writeInt(this.CurrentPlayerLevel);

outputStream.writeInt(this.CurrentVampLevel);

outputStream.writeInt(this.CurrentWereLevel);

} catch (Exception ex) {

ex.printStackTrace();

}

}

}

 

 

 

 

CommonProxy

 

 

public class CommonProxy implements IGuiHandler {

 

private static final Map<String, NBTTagCompound> extendedEntityData = new HashMap<String, NBTTagCompound>();

 

public void registerRenderThings() {

}

 

public static void storeEntityData(String name, NBTTagCompound compound)

{

extendedEntityData.put(name, compound);

}

 

public static NBTTagCompound getEntityData(String name)

{

return extendedEntityData.remove(name);

}

 

public void registerTileEntitySpecialRenderer() {

 

}

public void registerItemRenderers() {

 

}

public void initialize() {

MainClass.channel = NetworkRegistry.INSTANCE.newEventDrivenChannel(MainClass.networkChannelName);

 

}

 

@Override

public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {

return null;

}

 

@Override

public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {

return null;

}

 

 

VampZ modder

Posted

I've trouble with sending a packet from server side to client side.

When I use a method in my ExtendedPlayer to see which level the player is Client side shows 0 and server side shows 2 (Changed level)

 

VampZ modder

Posted

You have no idea what you are doing, right? You are just copy-pasting code from a tutorial, and you don't even care to remove the old comments which have nothing to do with your code. Then, I suggest using the SimpleNetworkWrapper for packet handling, diesieben07 has a tutorial here.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • So, I have a minecraft world hosted with essential on forge 1.20.1, there's 149 mods, and the forge version is 47.3.0, and it's been like that for a good 2-3 weeks, and all of a sudden, it stopped loading, and I have 0 clue as to why, and this world means A LOT to me, so if anyone out there is able to help, I would GLADLY appreciate it. here's the link if ya wanna help:   [04Dec2024 22:42:24.552] [Worker-ResourceReload-3/ERROR][net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener/]: Couldn't parse data file slabsexpanded:snow_blockblocktoslab from slabsexpanded:recipes/snow_blockblocktoslab.json com.google.gson.JsonParseException: com.google.gson.stream.MalformedJsonException: Expected name at line 16 column 4 path $.result.item at net.minecraft.util.GsonHelper.m_13780_(GsonHelper.java:526) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?] at net.minecraft.util.GsonHelper.m_263475_(GsonHelper.java:531) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?] at net.minecraft.util.GsonHelper.m_13776_(GsonHelper.java:581) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?] at net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener.m_278771_(SimpleJsonResourceReloadListener.java:41) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?] at net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener.m_5944_(SimpleJsonResourceReloadListener.java:29) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?] at net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener.m_5944_(SimpleJsonResourceReloadListener.java:17) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?] at net.minecraft.server.packs.resources.SimplePreparableReloadListener.m_10786_(SimplePreparableReloadListener.java:11) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?] at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768) ~[?:?] at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1760) ~[?:?] at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] Caused by: com.google.gson.stream.MalformedJsonException: Expected name at line 16 column 4 path $.result.item at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1657) ~[gson-2.10.jar%23107!/:?] at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:514) ~[gson-2.10.jar%23107!/:?] at com.google.gson.stream.JsonReader.hasNext(JsonReader.java:422) ~[gson-2.10.jar%23107!/:?] at com.google.gson.internal.bind.TypeAdapters$28.read(TypeAdapters.java:779) ~[gson-2.10.jar%23107!/:?] at com.google.gson.internal.bind.TypeAdapters$28.read(TypeAdapters.java:725) ~[gson-2.10.jar%23107!/:?] at com.google.gson.internal.bind.TypeAdapters$34$1.read(TypeAdapters.java:1007) ~[gson-2.10.jar%23107!/:?] at net.minecraft.util.GsonHelper.m_13780_(GsonHelper.java:524) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?]
    • Hello! I have been having a problem with Forgematica, Embeddium, Oculus, and create. I wanted to download litematica so I could see which blocks are in my creative mode build, so that I could collect them all in survival. However, litematica is a fabric mod. I found a port called forgematica, which I added (along with it's dependency) to my mods folder. I loaded into a new world, and built a structure. Then, I added a part from the create mod, and the game crashed instantly, with exit code -1. Thanks for any help! Crash Report and mods list: https://pastebin.com/rtzh6LAi
    • Have you found a modder for this vehicle project? Because it will be really hard and I want to know that hero who can create all this
  • Topics

×
×
  • Create New...

Important Information

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