Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[SOLVED]Client-Side packet handler not receiving packet with dedicated server.


Recommended Posts

Hi There

Im currently sending packets from a tile entity to all nearby clients to play sounds(This is necessary over traditional playSound methods due to high control over the sound). On a single player world, everything works as expected and the debug printouts within the code come from the expected sides. When running on a dedicated server, the packet constructor and toBytes() are both called with correct data but nothing happens following that. No code within the Packet Handler is executed and neither is fromBytes().




import io.netty.buffer.ByteBuf;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;

public class PacketPlaySoundOnClient implements IMessage{

	public BlockPos pos;
	public int slot;	
	public int instruction;

	public PacketPlaySoundOnClient(BlockPos pos, int slot, int instruction) {
		this.pos = pos;
		this.slot = slot;
		this.instruction = instruction;
		System.out.println("Constructing Packet");

	public PacketPlaySoundOnClient() {}
	public void fromBytes(ByteBuf buf) {
		pos = BlockPos.fromLong(buf.readLong());
		slot = buf.readInt();
		instruction = buf.readInt();	
		System.out.println("From Bytes Pos = " + pos + ", Slot = " + slot);

	public void toBytes(ByteBuf buf) {
		System.out.println("To Bytes Pos = " + pos + ", Slot = " + slot);







package net.themcjavafre4k.mcdj.networking;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.themcjavafre4k.mcdj.SoundHandler;
import net.themcjavafre4k.mcdj.item.ItemCustomRecord;
import net.themcjavafre4k.mcdj.item.MCDJItems;
import net.themcjavafre4k.mcdj.sound.SoundDJDeck;
import net.themcjavafre4k.mcdj.tileentity.TileEntityDJDeck;

public class ClientSoundHandler implements IMessageHandler<PacketPlaySoundOnClient, IMessage> {

	private List<SoundDJDeck> slot1 = new ArrayList<SoundDJDeck>();

	public IMessage onMessage(PacketPlaySoundOnClient msg, MessageContext ctx) {

		if(ctx.side != Side.CLIENT) {

			System.err.println("Recieved on Server Side");
			return null;

		System.out.println("Packet recieved");

		Minecraft.getMinecraft().addScheduledTask(() -> {

			TileEntityDJDeck tile = (TileEntityDJDeck) Minecraft.getMinecraft().world.getTileEntity(msg.pos);


			ItemStack records = tile.inventory.getStackInSlot(0);
			ItemCustomRecord slot1Record = (ItemCustomRecord)records.getItem();

				switch(msg.slot) {
				case 0:
					System.out.println("Playing Sound In Slot 1");

					slot1.add(new SoundDJDeck(msg.pos, SoundHandler.getRecordSound(MCDJItems.customRecord.indexOf(tile.inventory.getStackInSlot(0).getItem())), 0));			


		return null;




Registering packet in my ClientProxy(Only packet with id 11):

MCDJMod.network.registerMessage(ClientSoundHandler.class, PacketPlaySoundOnClient.class, 11, Side.CLIENT);



Calling send method:


System.out.print("Play Method Called \n");

		if(!world.isRemote) {

			MCDJMod.network.sendToAllAround(new PacketPlaySoundOnClient(pos, slot, 0), new NetworkRegistry.TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 20)); 




On a side not, If i leave out the instruction integer from my packet, I get the following IndexOutOfBoundException from the client followed by disconnection from the server:

readerIndex(11) + length(2) exceeds writerIndex(12): UnpooledSlicedByteBuf(ridx: 11, widx: 12, cap: 12/12, unwrapped: PooledUnsafeDirectByteBuf(ridx: 0, widx: 13, cap: 13))


Not sure if this may have something to do with the issue.

Edited by TheMCJavaFre4k
Link to comment
Share on other sites

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.

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.


  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Hi, I'm one of the user who's using Custom NPCs 1.7.10. But I have one problem. I see some items are equipped to NPC rotated, not in the right position. How can I rotate the arm of NPC?
    • Hello. I decided to try to make a mod, but for some reason I stumbled at the very beginning. How do I register a block for it to appear in the inventory? It seems that I'm trying to do it according to the manual, but only the procedure for registering new blocks is described there. So I made a mod class. I registered the registration, but when I install it into the game, I do not see my block in the intent. And I will also be grateful if you give a link to some kind of detailed manual. So that step by step it was described how what can be created. Thanks.   @Mod("examplemod") public class ExampleMod { // Directly reference a log4j logger. private static final Logger LOGGER = LogManager.getLogger(); private static final String MODID = "0.1"; private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID); public static final RegistryObject<Block> MyBlock = BLOCKS.register("mysuperblockreg", () -> new SuperBlock(BlockBehaviour.Properties.of(Material.WOOD).lightLevel((s) -> { return 1; }).sound(SoundType.WOOD))); public ExampleMod() { // Register the setup method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); // Register the enqueueIMC method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC); // Register the processIMC method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC); BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus()); // Register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); } private void setup(final FMLCommonSetupEvent event) { // some preinit code LOGGER.info("HELLO FROM PREINIT"); LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName()); } private void enqueueIMC(final InterModEnqueueEvent event) { // some example code to dispatch IMC to another mod InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world"; }); } private void processIMC(final InterModProcessEvent event) { // some example code to receive and process InterModComms from other mods LOGGER.info("Got IMC {}", event.getIMCStream().map(m -> m.messageSupplier().get()).collect(Collectors.toList())); } // You can use SubscribeEvent and let the Event Bus discover methods to call @SubscribeEvent public void onServerStarting(FMLServerStartingEvent event) { // do something when the server starts LOGGER.info("HELLO from server starting"); } // You can use EventBusSubscriber to automatically subscribe events on the // contained class (this is subscribing to the MOD // Event bus for receiving Registry Events) @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public static class RegistryEvents { @SubscribeEvent public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) { // register a new block here LOGGER.info("HELLO from Register Block"); } } }  
    • I'm probably really stupid but how do I fix this error. It happens whenever I try to startup Minecraft forge 1.8.9 recommended [19:13:10 ERROR]: Gave up trying to download https://maven.minecraftforge.net/jline/jline/2.13/jline-2.13.jar for job 'Version & Libraries' [19:13:10 ERROR]: Job 'Version & Libraries' finished with 1 failure(s)! (took 0:00:13.982)   How do I fix this?
    • Override attackEntityFrom and do checks there, for example DamageSource#isProjectile. Or check how Enderman does it.
    • Hey, I just started modding, and especially texturing, so I'm still new to all of this. I thought a fun thing to do would be to turn the world to glass (turn blocks such as grass and stone and ores etc..) to have the grass texture, so the world would be glass. Seemed kinda fun. So I just copy-pasted the glass texture into my pack, renamed it to stone, and ran into a problem. It is rendering the glass texture, but is not transparent. Its just grey on the inside, with the glass textures on the side. I am completely lost as of what to do. Does anyone have a solution ? thank you
  • Topics

  • Who's Online (See full list)

  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.