Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Ive tried to get my old Message System to work. When i send a Message from client to server it will work, when i send a Message vom server to Client I get anError:

Can somebody help me.

image.png.e0223902780d7a5fade2a76626cedbe2.png

 

My Packet Handler:

package com.wilpito.wilpitomod.handler;


import com.wilpito.wilpitomod.network.MessageTileBase;

import net.minecraft.client.Minecraft;
import net.minecraft.network.NetworkManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.network.NetworkDirection;
import net.minecraftforge.fml.network.NetworkRegistry;
import net.minecraftforge.fml.network.simple.SimpleChannel;


public class PacketHandler {
	private static final String PROTICOL_VERSION = "1";
    public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel(
    		new ResourceLocation("wilpitomod","main") 
    		,() -> PROTICOL_VERSION
    		, PROTICOL_VERSION::equals
    		, PROTICOL_VERSION::equals);

	public static final int TILEMSG=11;

	
	public PacketHandler()
	{
		CHANNEL.registerMessage(TILEMSG, MessageTileBase.class, MessageTileBase::encode, MessageTileBase::new,MessageTileBase::handle);		
	}
	
	public static void TileMsgSend(MessageTileBase msg,World World){
		if (!World.isRemote) return;
		CHANNEL.sendToServer(msg);
	}
	public static void TileMsgSendtoClient(MessageTileBase msg, World worldIn){
		
		NetworkManager manager = Minecraft.getInstance().getConnection().getNetworkManager();
		
			CHANNEL.sendTo(msg, manager, NetworkDirection.PLAY_TO_CLIENT);
		}
	}
}

My Message:

package com.wilpito.wilpitomod.network;

import net.minecraft.network.PacketBuffer;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.network.NetworkEvent;

import java.util.function.Supplier;

public class MessageTileBase { 
	// A default constructor is always required
	public MessageTileBase(){}
	// Coordinates of Tile
	protected BlockPos pos;
	protected String text;
	
	
	public MessageTileBase(BlockPos pos, String text){
		this.pos = pos;
		this.text = text;		
	}
	
    public MessageTileBase(PacketBuffer buf) {
		pos = buf.readBlockPos();
	    text = buf.readString();
    }
    
    public  void encode(PacketBuffer buf) {
    	buf.writeBlockPos(pos);
 	    buf.writeString(text);
 	    //.. Code on Client Side will folw hier..
    }
    public void handle(Supplier<NetworkEvent.Context> context) {
    	if (context == null) {
    		
    	}
    }
}

I Create the Messaeg for testing in My Tile Entity Tick() with 

PacketHandler.TileMsgSendtoClient(new MessageTileBase(this.pos ,"TEST"),this.world);

 

This will work when activating Message from Client to server:


PacketHandler.TileMsgSend(new MessageTileBase(new BlockPos(0,0,0),"TEST"),Minecraft.getInstance().world);

 

I think something is wrong with the network manager.

        NetworkManager manager = Minecraft.getInstance().getConnection().getNetworkManager();       
        CHANNEL.sendTo(msg, manager, NetworkDirection.PLAY_TO_CLIENT);
 

  • Author

Oky it might be a little bit strange. But i dont find an easy way to do this elsewhere.

Normaly i have 6 Packet handler on the same CHANNEL.In my old Mod on 1.8 it works.

Do you have an example with will work? In this forrum i only found the message class and the command line for CHANNEL.registerMessage.

 

I kow the direction, but in this time i need to send update Information from Server to Client. In an other case i will send Setup Informations from Client to server. So i Need both directions.

Current problem:

i Have a tileEntity on server with wil be updatte automatiocally with new Energy by transfering Energy from nighbors. When i Open the  Client Screen the current value should be shown on Scrren and can be changed by server before the Screen close. The client can't change the energy level.

 

  • Author
Quote

In this case the syncing should be done on the Container level, not the tile entity. It only needs to sync while the GUI is open.

Okay you are right. But the only way i know is to send an explicit message to sync between Client and Server. In old versions i've send an update when Tile value have be changed. This may have slow down perfomence.

 

At this time i down't know how to do a sync for some values to Client Container it in 1.15.2. I'm serching for anExample for do this in 1.15.2 about 3 days... but find nothing with will work.

It might verry helpfull to have some complete examples or an complete small mod to look at the code.

 

 

 

 

 

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.