Jump to content

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


TheMCJavaFre4k

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

 

PacketPlaySoundOnClient:

Spoiler

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() {}
	
	@Override
	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);
	}

	@Override
	public void toBytes(ByteBuf buf) {
		System.out.println("To Bytes Pos = " + pos + ", Slot = " + slot);
		buf.writeLong(pos.toLong());
		buf.writeInt(slot);
		buf.writeInt(instruction);
	}

	



}

 

 

ClientSoundHandler:

Spoiler

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

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

			System.out.print("Plays");

			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));			
					Minecraft.getMinecraft().getSoundHandler().playSound(slot1.get(0));
					break;

				}



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

Spoiler

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

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

    • Keep this post up just in case but I'm using the curseforge launcher and it's working  IM SOO HAPPY
    • Post logs as per https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/ They may have information that will answer these questions.
    • I was left reeling when a glitch on a cryptocurrency exchange caused me to lose $166,000 worth of my hard-earned savings. It felt like my entire world had crumbled in the blink of an eye, leaving me with a sense of hopelessness. Determined not to give up, I delved into research on recovery options, unsure of what to expect. That's when I stumbled upon I was left reeling when a glitch on a cryptocurrency exchange caused me to lose $166,000 worth of my hard-earned savings. It felt like my entire world had crumbled in the blink of an eye, leaving me with a sense of hopelessness. Determined not to give up, I delved into research on recovery options, unsure of what to expect. That's when I stumbled upon DIGITAL HACK RECOVERY, a beacon of hope in my darkest hour. Despite my initial doubts, I decided to take a leap of faith and give them a shot as a final lifeline. The experts at DIGITAL HACK RECOVERY proved to be masters of their craft, guiding me through their exclusive process with precision and expertise. Utilizing cutting-edge blockchain analysis methods, they were able to track down the elusive trail of my missing funds and identify the exact point of failure. Their forensic talents were unparalleled as they tirelessly combed through the intricate web of blockchain data to locate my cryptocurrency. With each step they took, they kept me informed of their progress, never wavering in their belief that my funds could be rescued. After several painstaking weeks, DIGITAL HACK RECOVERY finally located and restored my $166,000 worth of cryptocurrency. I was awestruck that they were able to salvage what I had thought was lost forever. The whole experience restored my faith in the crypto space and proved that even in the worst situations, recovery is possible with the right experts on your side. I will be forever grateful to DIGITAL HACK RECOVERY for giving me back my life savings when I needed it most. Their tireless efforts and technical mastery turned what could have been a devastating loss into an uplifting success story. Book a time with DIGITAL HACK RECOVERY through: digital hack recovery @ techie . com &  +12018871705
    • public class ParticleReboundRecipe implements Recipe<CraftingContainer> { private List<ParticleReboundIngredient> inputs; private ParticleReboundFuel fuel; private ItemStack output; public ParticleReboundRecipe(List<ParticleReboundIngredient> inputs, ParticleReboundFuel fuel, ItemStack output) { this.inputs = inputs; this.fuel = fuel; this.output = output; } // TODO: Implement interface ... // TODO: Move to separate file if desired public record ParticleReboundIngredient(Ingredient ingredient, int count) { public static final Codec<ParticleReboundIngredient> CODEC = RecordCodecBuilder.create( builder -> builder.group( Ingredient.CODEC.fieldOf("ingredient").forGetter((i) -> i.ingredient), Codec.INT.fieldOf("count").forGetter(i -> i.count) ).apply(builder, ParticleReboundIngredient::new) ); } // TODO: Move to separate file if desired public record ParticleReboundFuel(String tag) { public static final Codec<ParticleReboundFuel> CODEC = RecordCodecBuilder.create( builder -> builder.group(Codec.STRING.fieldOf("tag").forGetter(f -> f.tag)).apply(builder, ParticleReboundFuel::new) ); public boolean isFuel(ItemStack stack) { // TODO: Check if fuel item matches the tag } } public class Serializer implements RecipeSerializer<ParticleReboundRecipe> { public static final Codec<ParticleReboundRecipe> CODEC = RecordCodecBuilder.create( builder -> builder.group( ParticleReboundIngredient.CODEC.listOf().fieldOf("inputs").forGetter(r -> r.inputs), ParticleReboundFuel.CODEC.fieldOf("fuel").forGetter(r -> r.fuel), ItemStack.CODEC.fieldOf("output").forGetter(r -> r.output) ).apply(builder, ParticleReboundRecipe::new) ); @Override public @NotNull Codec<ParticleReboundRecipe> codec() { return CODEC; } // TODO: The rest ... } }   ?
  • Topics

×
×
  • Create New...

Important Information

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