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

Hi! I'm trying to send some custom network packets from server to client. The packets are sent but I have some problems handling them on client. To avoid arbitrary chuck generation I'm trying to use level#hasChunckAt(pos). It's deprected. Is this the correct thing to use or should I use something else? And it doesn't execute the code in client because I can get the ServerLevel but I need ClientLevel? How can I get it working? Thanks.

import java.util.function.Supplier;

import com.rinventor.transportmod.core.base.PTMDbg;

import net.minecraft.core.BlockPos;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.network.NetworkEvent;

public class InformationScreenSyncMessage {

	public final BlockPos pos;
	public final String data;

    public InformationScreenSyncMessage(BlockPos pos, String data) {
    	this.pos = pos;
    	this.data = data;
    }

    public InformationScreenSyncMessage(FriendlyByteBuf buffer) {
    	this(buffer.readBlockPos(), buffer.readUtf());
    }

    public void encode(FriendlyByteBuf buffer) {
    	buffer.writeBlockPos(this.pos);
    	buffer.writeUtf(this.data);
    }

    public static void handle(InformationScreenSyncMessage msg, Supplier<NetworkEvent.Context> ctx) {
        ctx.get().enqueueWork(() ->
            // Make sure it's only executed on the physical client
            DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> InformationScreenClient.handlePacket(msg, ctx))
        );
        ctx.get().setPacketHandled(true);
    }
    
    public class InformationScreenClient
    {
    	@SuppressWarnings("deprecation")
	public static void handlePacket(InformationScreenSyncMessage msg, Supplier<NetworkEvent.Context> ctx) {
    	    Level level = ctx.get().getSender().getLevel();
    	    BlockPos pos = msg.pos;
    	    if (level.hasChunkAt(pos)) {
    	    	if (level.getBlockEntity(pos) instanceof InformationScreenBlockEntity be) {
    			be.data = msg.data;
    		}
    	    }
    	}
    	
    }

}

 

Edited by RInventor7

level = Minecraft.getInstance().level

level.isLoaded(BlockPos)

Mojang have moved to "sections" instead of chunks.

It won't generate chunks on the client, it will crash if you access unloaded chunks.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

  • RInventor7 changed the title to Custom clientbound packet handling [1.19] [SOLVED]

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.