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

[1.7.2][SOLVED]Send Packet to Server


korti11
 Share

Recommended Posts

Good evening everybody,

 

I send the packet to the server but nothing changes.

 

Key event

 

 

	Item[] items = new Item[]{RedTools.redSword, RedTools.redSwordCharged, RedTools.redPickaxe, RedTools.redPickaxeCharged, RedTools.redAxe, RedTools.redAxeCharged};
	RedstoneTools.packetLine.registerPacket(PacketSwitch.class);

	if(invert.isPressed()){
		InventoryPlayer inventory = Minecraft.getMinecraft().thePlayer.inventory;
		for(int i = 0; i < items.length && inventory.getCurrentItem() != null; i += 2){
			if(inventory.getCurrentItem().getUnlocalizedName().equals(new ItemStack(items[i]).getUnlocalizedName())){
				RedstoneTools.packetLine.sendToServer(new PacketSwitch());
			}
			else if(inventory.getCurrentItem().getUnlocalizedName().equals(new ItemStack(items[i + 1]).getUnlocalizedName())){
				RedstoneTools.packetLine.sendToServer(new PacketSwitch());
			}
		}
	}

 

 

 

Packet

 

 

import at.minecraft.korti.invertredstonetools.tools.RedTools;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;

public class PacketSwitch extends AbstractPacket{

@Override
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
	// TODO Auto-generated method stub

}

@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
	// TODO Auto-generated method stub

}

@Override
public void handleClientSide(EntityPlayer player) {
	// TODO Auto-generated method stub

}

@Override
public void handleServerSide(EntityPlayer player) {
	Item[] items = new Item[]{RedTools.redSword, RedTools.redSwordCharged, RedTools.redPickaxe, RedTools.redPickaxeCharged, RedTools.redAxe, RedTools.redAxeCharged};

	InventoryPlayer inventory = player.inventory;

	for(int i = 0; i < items.length && inventory.getCurrentItem() != null; i += 2){
		if(inventory.getCurrentItem().getUnlocalizedName().equals(new ItemStack(items[i]).getUnlocalizedName())){
			inventory.setInventorySlotContents(inventory.currentItem, new ItemStack(items[i + 1], 1, inventory.getCurrentItem().getItemDamage()));
		}
		else if(inventory.getCurrentItem().getUnlocalizedName().equals(new ItemStack(items[i + 1]).getUnlocalizedName())){
			inventory.setInventorySlotContents(inventory.currentItem, new ItemStack(items[i], 1, inventory.getCurrentItem().getItemDamage()));
		}
	}

}

}

 

 

 

A good new week everybody.

Link to comment
Share on other sites

So I changed it, but nothing changes.

 

Packet

 

 

public class PacketSwitch extends AbstractPacket{

ItemStack itemStack;

public PacketSwitch(ItemStack itemStack){
	this.itemStack = itemStack;
}

@Override
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
	ByteBufUtils.writeItemStack(buffer, itemStack);
}

@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
	itemStack = ByteBufUtils.readItemStack(buffer);
}

@Override
public void handleClientSide(EntityPlayer player) {

	itemStack.setItemDamage(player.inventory.getCurrentItem().getItemDamage());

	player.inventory.setInventorySlotContents(player.inventory.currentItem, itemStack);

}

@Override
public void handleServerSide(EntityPlayer player) {

	itemStack.setItemDamage(player.inventory.getCurrentItem().getItemDamage());

	player.inventory.setInventorySlotContents(player.inventory.currentItem, itemStack);

}

}

[spoiler

Link to comment
Share on other sites

Only the construtor work.

 

 

 

public class PacketSwitch extends AbstractPacket{

ItemStack itemStack;

public PacketSwitch(ItemStack itemStack){
	this.itemStack = itemStack;
	System.out.println(RedModInfo.ModName + ": new Packet");
}

@Override
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
	ByteBufUtils.writeItemStack(buffer, itemStack);
	System.out.println(RedModInfo.ModName + ": Packet was encoded");
}

@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
	itemStack = ByteBufUtils.readItemStack(buffer);
	System.out.println(RedModInfo.ModName + ": Packet was decoded");
}

@Override
public void handleClientSide(EntityPlayer player) {

}

@Override
public void handleServerSide(EntityPlayer player) {

	itemStack.setItemDamage(player.inventory.getCurrentItem().getItemDamage());

	player.inventory.setInventorySlotContents(player.inventory.currentItem, itemStack);

	System.out.println(RedModInfo.ModName + ": Item was switched");
}

}

 

 

Link to comment
Share on other sites

Did you register your packet in the PacketPipeline class? If you don't register your packets, it can't process them.

 

I do it in tandem with the initialization process:

public void initialise() {
this.channels = NetworkRegistry.INSTANCE.newChannel(ModInfo.CHANNEL, this);
registerPackets();
}

public void registerPackets() {
registerPacket(SomePacket.class);
registerPacket(SomeOtherPacket.class);
}

Also don't forget to call postInitialise() during post initialization.

 

@Chibill - I have never had any problems with my packets getting sent in the normal client mode, nor in the regular Minecraft launcher; you must be doing something incorrectly.

Link to comment
Share on other sites

So now crash it when i press my key.

 

[17:02:47] [server thread/INFO]: Starting integrated minecraft server version 1.7.2
[17:02:47] [server thread/INFO]: Generating keypair
[17:02:47] [server thread/INFO]: Injecting new block and item data into this server instance
[17:02:47] [server thread/INFO]: Loading dimension 0 (test) (net.minecraft.server.integrated.IntegratedServer@4e284a28)
[17:02:47] [server thread/INFO]: Loading dimension 1 (test) (net.minecraft.server.integrated.IntegratedServer@4e284a28)
[17:02:47] [server thread/INFO]: Loading dimension -1 (test) (net.minecraft.server.integrated.IntegratedServer@4e284a28)
[17:02:47] [server thread/INFO]: Preparing start region for level 0
POKEE false
[17:02:48] [Netty Client IO #0/INFO]: Server protocol version 1
[17:02:48] [Netty IO #1/INFO]: Client protocol version 1
[17:02:48] [Netty IO #1/INFO]: Client attempting to join with 4 mods : mcp@8.09,FML@7.2.125.1039,Forge@10.12.0.1039,invertredstonetools@Alpha 0.1.1
[17:02:48] [Netty IO #1/INFO]: Attempting connection with missing mods [] at CLIENT
[17:02:48] [Netty Client IO #0/INFO]: Attempting connection with missing mods [] at SERVER
[17:02:48] [server thread/INFO]: [server thread] Server side modded connection established
[17:02:48] [server thread/INFO]: Player882[local:E:b64eea86] logged in with entity id 117 at (-441.29226556369974, 4.0, -908.4239892768311)
[17:02:48] [Client thread/INFO]: [Client thread] Client side modded connection established
[17:02:48] [server thread/INFO]: Player882 joined the game
Invert Redstone Tools: new Packet
[17:03:05] [server thread/ERROR]: There was a critical exception handling a packet on channel invertredstonetools
io.netty.handler.codec.DecoderException: java.lang.InstantiationException: at.minecraft.korti.invertredstonetools.utils.network.PacketSwitch
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[MessageToMessageDecoder.class:?]
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) ~[DefaultChannelPipeline.class:?]
at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:?]
at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:74) [FMLProxyPacket.class:?]
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:211) [NetworkManager.class:?]
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:173) [NetworkSystem.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:681) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:569) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:114) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:454) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:706) [MinecraftServer$2.class:?]
Caused by: java.lang.InstantiationException: at.minecraft.korti.invertredstonetools.utils.network.PacketSwitch
at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_51]
at at.minecraft.korti.invertredstonetools.utils.network.PacketPipeline.decode(PacketPipeline.java:89) ~[PacketPipeline.class:?]
at at.minecraft.korti.invertredstonetools.utils.network.PacketPipeline.decode(PacketPipeline.java:1) ~[PacketPipeline.class:?]
at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:?]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:?]
... 13 more
[17:03:05] [server thread/INFO]: Player882 lost connection: TextComponent{text='A fatal error has occured, this connection is terminated', siblings=[], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null}}
[17:03:05] [server thread/INFO]: Player882 left the game
[17:03:05] [server thread/INFO]: Stopping singleplayer server as player logged out
[17:03:05] [server thread/INFO]: Stopping server
[17:03:05] [server thread/INFO]: Saving players
[17:03:05] [server thread/INFO]: Saving worlds
[17:03:05] [server thread/INFO]: Saving chunks for level 'test'/Overworld
[17:03:05] [server thread/INFO]: Saving chunks for level 'test'/Nether
[17:03:05] [server thread/INFO]: Saving chunks for level 'test'/The End
[17:03:05] [server thread/INFO]: Unloading dimension 0
[17:03:05] [server thread/INFO]: Unloading dimension -1
[17:03:05] [server thread/INFO]: Unloading dimension 1

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

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • This is the capability inject and provider for one of my capabilities. All of them are coded the exact same way. public class CapabilityDamageTypes { @CapabilityInject(IDamageTypes.class) public static Capability<IDamageTypes> DAMAGE_TYPES_CAPABILITY = null; public static void register() { CapabilityManager.INSTANCE.register(IDamageTypes.class, new Storage(), new Factory()); } private static class Storage implements Capability.IStorage<IDamageTypes> { @Nullable @Override public INBT writeNBT(Capability<IDamageTypes> capability, IDamageTypes instance, Direction side) { CompoundNBT tag = new CompoundNBT(); tag.putFloat("slash", instance.getSlashDamage()); tag.putFloat("impact", instance.getImpactDamage()); tag.putFloat("puncture", instance.getPunctureDamage()); tag.putFloat("fire", instance.getFireDamage()); tag.putFloat("lightning", instance.getLightningDamage()); tag.putFloat("ice", instance.getIceDamage()); tag.putFloat("dark", instance.getDarkDamage()); tag.putFloat("holy", instance.getHolyDamage()); tag.putFloat("magic", instance.getMagicDamage()); tag.putString("mobDamageType", instance.getMobDamageType()); return tag; } @Override public void readNBT(Capability<IDamageTypes> capability, IDamageTypes instance, Direction side, INBT nbt) { float slash = ((CompoundNBT) nbt).getFloat("slash"); float impact = ((CompoundNBT) nbt).getFloat("impact"); float puncture = ((CompoundNBT) nbt).getFloat("puncture"); float fire = ((CompoundNBT) nbt).getFloat("fire"); float lightning = ((CompoundNBT) nbt).getFloat("lightning"); float ice = ((CompoundNBT) nbt).getFloat("ice"); float dark = ((CompoundNBT) nbt).getFloat("dark"); float holy = ((CompoundNBT) nbt).getFloat("holy"); float magic = ((CompoundNBT) nbt).getFloat("magic"); String mobDamageType = ((CompoundNBT) nbt).getString("mobDamageType"); instance.setSlashDamage(slash); instance.setImpactDamage(impact); instance.setPunctureDamage(puncture); instance.setFireDamage(fire); instance.setLightningDamage(lightning); instance.setIceDamage(ice); instance.setDarkDamage(dark); instance.setHolyDamage(holy); instance.setMagicDamage(magic); instance.setMobDamageType(mobDamageType); } } private static class Factory implements Callable<IDamageTypes> { @Override public IDamageTypes call() throws Exception { return new DamageTypes(0, 0, 0, 0, 0, 0, 0, 0, 0, "IMPACT"); } } } package com.cwjn.hardstuckintegration.Capabilities.DamageTypes; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.Direction; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilitySerializable; import net.minecraftforge.common.util.LazyOptional; import javax.annotation.Nonnull; import javax.annotation.Nullable; public class DamageTypesProvider implements ICapabilitySerializable<CompoundNBT> { //private final DamageTypes damage = new DamageTypes(); //private final LazyOptional<IDamageTypes> damageOptional = LazyOptional.of(() -> damage); private DamageTypes damage; private LazyOptional<IDamageTypes> damageOptional; public void invalidate() { damageOptional.invalidate(); } public DamageTypesProvider(float I, float P, float S, float F, float L, float IC, float D, float H, float M, String mobDamageType) { damage = new DamageTypes(I, P, S, F, L, IC, D, H, M, mobDamageType); damageOptional = LazyOptional.of(() -> damage); } @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { return cap == CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY ? damageOptional.cast() : LazyOptional.empty(); } @Override public CompoundNBT serializeNBT() { if (CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY == null) { return new CompoundNBT(); } else { return (CompoundNBT) CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY.writeNBT(damage, null); } } @Override public void deserializeNBT(CompoundNBT nbt) { if (CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY != null) { CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY.readNBT(damage, null, nbt); } } }  
    • I got it now I installed the java 16 jdk instead of 8. Now it works thanks!  
    • net.minecraft.ResourceLocationException: Non [a-z0-9/._-] character in path of location: minecraft:textures/models/armor/gold_layer_١.png     at net.minecraft.resources.ResourceLocation.<init>(ResourceLocation.java:37) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading}     at net.minecraft.resources.ResourceLocation.<init>(ResourceLocation.java:42) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading}     at net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer.getArmorResource(HumanoidArmorLayer.java:146) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer.m_117118_(HumanoidArmorLayer.java:60) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer.m_6494_(HumanoidArmorLayer.java:36) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer.m_6494_(HumanoidArmorLayer.java:23) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.entity.LivingEntityRenderer.m_7392_(LivingEntityRenderer.java:126) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.entity.MobRenderer.m_7392_(SourceFile:45) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading}     at net.minecraft.client.renderer.entity.MobRenderer.m_7392_(SourceFile:18) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading}     at net.minecraft.client.renderer.entity.EntityRenderDispatcher.m_114384_(EntityRenderDispatcher.java:129) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.LevelRenderer.m_109517_(LevelRenderer.java:1280) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.LevelRenderer.m_109599_(LevelRenderer.java:1076) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.GameRenderer.m_109089_(GameRenderer.java:1050) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.GameRenderer.m_109093_(GameRenderer.java:830) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91383_(Minecraft.java:1039) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91374_(Minecraft.java:659) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:186) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:runtimedistcleaner:A}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) ~[?:?] {}     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}     at java.lang.reflect.Method.invoke(Method.java:567) ~[?:?] {}     at net.minecraftforge.fml.loading.targets.CommonClientLaunchHandler.lambda$launchService$0(CommonClientLaunchHandler.java:45) ~[fmlloader-1.17.1-37.0.126.jar%2322!:?] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-9.0.7.jar%235!:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-9.0.7.jar%235!:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-9.0.7.jar%235!:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-9.0.7.jar%235!:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-9.0.7.jar%235!:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-9.0.7.jar%235!:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-9.0.7.jar%235!:?] {}     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:90) [bootstraplauncher-0.1.17.jar:?] {}   (This the crash report(
    • Also you should consider reading the README.txt file (there it explains how to set up the workspace and what to do on specific errors)
    • First you need to run "gradlew genEclipseRuns" / "gradlew genIntellijRuns" and then "gradlew eclipse" / "gradlew intellij". There isn't a setupdecompworkspace any more
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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