Jump to content

Packets with Capabilities [Solved]


netherstorm123
 Share

Recommended Posts

Hello, I am having a little problem with telling the server who the EntityPlayerMP is. I am using capabilities to save details about the player and then transfer it from server to client. I resorted to packets as the health was not in sync with the server when above 20. Such issue did not exist in single player as the health always returned to what it was supposed to be. 

My packet code is as follows:

public class PacketCurrentHealth implements IMessage {
	
	EntityPlayerMP player;
	
	private float currentHealth;

    @Override
    public void fromBytes(ByteBuf buf) {
        currentHealth = buf.readFloat();
    }

    @Override
    public void toBytes(ByteBuf buf) {
        buf.writeFloat(currentHealth);
    }

    public PacketCurrentHealth() {
    	
    	ICurrentHealth cH = player.getCapability(CurrentHealthProvider.CURRENTHEALTH_CAP, null);
    	currentHealth = cH.getCurrentHealth();
    }

    public static class Handler implements IMessageHandler<PacketCurrentHealth, IMessage> {
        @Override
        public IMessage onMessage(PacketCurrentHealth message, MessageContext ctx) {

            FMLCommonHandler.instance().getWorldThread(ctx.netHandler).addScheduledTask(() -> handle(message, ctx));
            return null;
        }

        public void handle(PacketCurrentHealth message, MessageContext ctx) {
  
            EntityPlayerMP playerEntity = ctx.getServerHandler().player;
           
            ICurrentHealth cH = playerEntity.getCapability(CurrentHealthProvider.CURRENTHEALTH_CAP, null);
            playerEntity.setHealth(message.currentHealth);
                
                
            
        }
    }
}

I call it when the player joins the world on the common(client and server) side:

@SubscribeEvent
	public void onJoinWorld(EntityJoinWorldEvent event) {
		if (event.getEntity() instanceof EntityPlayerMP) {
			EntityPlayerMP player = (EntityPlayerMP) event.getEntity();
			
			PacketHandler.INSTANCE.sendToServer(new PacketCurrentHealth());
		}
	}

I register the packets using this method where the registerMessages() is called on the common.

public static void registerMessages() {
        INSTANCE.registerMessage(PacketCurrentHealth.Handler.class, PacketCurrentHealth.class, nextID(), Side.SERVER);
    }

I have tested the capability and must say that it does work on both sides. Due to the issue being a multiplayer problem, I update the capability on the server only using:


	@SubscribeEvent
	public void playerTick(LivingEvent.LivingUpdateEvent event)
	{
		if(event.getEntityLiving() instanceof EntityPlayerMP)
		{
			EntityPlayerMP player = (EntityPlayerMP) event.getEntityLiving();
			
			if (player.world.isRemote) return;
			
			ICurrentHealth currentHealth = player.getCapability(CurrentHealthProvider.CURRENTHEALTH_CAP, null);
			currentHealth.set(player.getHealth());
		}
	}

Thank you, I am looking forward to seeing possible solutions.

Edited by netherstorm123
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

    • Can you submit the debug.log? (In Curseforge it's in Minecraft settings somewhere) ¿Puede enviar el archivo debug.log? (En Curseforge, está en la configuración de Minecraft)
    • ---- Minecraft Crash Report ---- 2 3WARNING: coremods are present: 4llibrary (llibrary-core-1.0.11-1.12.2.jar) 5IELoadingPlugin (ImmersiveEngineering-core-0.12-98.jar) 6clothesline-hooks (clothesline-hooks-1.12.2-0.0.1.2.jar) 7SteveKunGLibPlugin (SteveKunG's-Lib-1.12.2-1.2.0.jar) 8ApotheosisCore (Apotheosis-1.12.2-1.12.5.jar) 9iceandfire (iceandfire-1.9.1-1.12.2.jar) 10GSHooksLoader (GalaxySpace-1.12.2-2.0.19.jar) 11MixinBooter (!mixinbooter-7.0.jar) 12MicdoodlePlugin (Galacticraft-1.12.2-4.0.4.jar) 13Contact their authors BEFORE contacting forge 14 15// I bet Cylons wouldn't have this problem. 16 17Time: 1/29/23 7:44 PM 18Description: Exception in server tick loop 19 20java.lang.NoSuchMethodError: slimeknights.tconstruct.library.tools.ToolCore.func_190903_i()Lnet/minecraft/item/ItemStack; 21at liketechnik.tinkertweaks.config.ConfigFile.lambda$null$5(ConfigFile.java:138) 22at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:174) 23at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) 24at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) 25at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) 26at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) 27at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) 28at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) 29at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) 30at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:485) 31at liketechnik.tinkertweaks.config.ConfigFile.lambda$insertDefaults$6(ConfigFile.java:149) 32at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) 33at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) 34at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) 35at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) 36at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) 37at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) 38at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) 39at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) 40at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:485) 41at liketechnik.tinkertweaks.config.ConfigFile.insertDefaults(ConfigFile.java:129) 42at slimeknights.mantle.config.AbstractConfig.load(AbstractConfig.java:32) 43at liketechnik.tinkertweaks.config.Config.load(Config.java:25) 44at liketechnik.tinkertweaks.LiketechniksTinkerTweaks.registerTools(LiketechniksTinkerTweaks.java:58) 45at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_350_LiketechniksTinkerTweaks_registerTools_Register.invoke(.dynamic) 46at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) 47at net.minecraftforge.fml.common.eventhandler.EventBus$1.invoke(EventBus.java:144) 48at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182) 49at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:850) 50at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:630) 51at net.minecraftforge.fml.server.FMLServerHandler.beginServerLoading(FMLServerHandler.java:99) 52at net.minecraftforge.fml.common.FMLCommonHandler.onServerStart(FMLCommonHandler.java:333) 53at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(DedicatedServer.java:125) 54at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:486) 55at java.lang.Thread.run(Thread.java:750) 56 57No Mixin Metadata is found in the Stacktrace. 58 59 60A detailed walkthrough of the error, its code path and all known details is as follows: 61--------------------------------------------------------------------------------------- 62 63-- System Details -- 64Details: 65Minecraft Version: 1.12.2 66Operating System: Linux (amd64) version 5.4.0-121-generic 67Java Version: 1.8.0_362, Temurin 68Java VM Version: OpenJDK 64-Bit Server VM (mixed mode), Temurin 69Memory: 942390688 bytes (898 MB) / 1400373248 bytes (1335 MB) up to 1771044864 bytes (1689 MB) 70JVM Flags: 3 total; -XX:MaxMetaspaceSize=300M -Xmx1900M -Xms950M 71IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 72FML: MCP 9.42 Powered by Forge 14.23.5.2859 41 mods loaded, 41 mods active 73States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored 74 75| State | ID | Version | Source | Signature | 76|:----- |:------------------------ |:------------------------ |:------------------------------------------------------- |:---------------------------------------- | 77| LCH | minecraft | 1.12.2 | minecraft.jar | None | 78| LCH | mcp | 9.42 | minecraft.jar | None | 79| LCH | FML | 8.0.99.99 | forge.jar | e3c3d50c7c986df74c645c0ac54639741c90a557 | 80| LCH | forge | 14.23.5.2859 | forge.jar | e3c3d50c7c986df74c645c0ac54639741c90a557 | 81| LCH | micdoodlecore | 4.0.4 | minecraft.jar | None | 82| LCH | mixinbooter | 7.0 | minecraft.jar | None | 83| LCH | clothesline-hooks | 1.12.2-0.0.1.2 | minecraft.jar | None | 84| LCH | deconstruction | 3.0.4 | [MC1.12.2]DeconTable-3.0.4.jar | None | 85| LCH | placebo | 1.6.0 | Placebo-1.12.2-1.6.0.jar | None | 86| LCH | apotheosis | 1.12.4 | Apotheosis-1.12.2-1.12.5.jar | None | 87| LCH | galacticraftcore | 4.0.4 | Galacticraft-1.12.2-4.0.4.jar | None | 88| LCH | galacticraftplanets | 4.0.4 | Galacticraft-1.12.2-4.0.4.jar | None | 89| LCH | asmodeuscore | 0.0.30 | AsmodeusCore-1.12.2-0.0.31.jar | None | 90| LCH | attributefix | 1.0.10 | AttributeFix-1.12.2-1.0.10.jar | d476d1b22b218a10d845928d1665d45fce301b27 | 91| LCH | codechickenlib | 3.2.3.358 | CodeChickenLib-1.12.2-3.2.3.358-universal.jar | f1850c39b2516232a2108a7bd84d1cb5df93b261 | 92| LCH | redstoneflux | 2.1.1 | RedstoneFlux-1.12-2.1.1.1-universal.jar | None | 93| LCH | cofhcore | 4.6.6 | CoFHCore-1.12.2-4.6.6.1-universal.jar | None | 94| LCH | cofhworld | 1.4.0 | CoFHWorld-1.12.2-1.4.0.1-universal.jar | None | 95| LCH | mantle | 1.12-1.3.3.55 | Mantle-1.12-1.3.3.55.jar | None | 96| LCH | jei | 4.16.1.302 | jei_1.12.2-4.16.1.302.jar | None | 97| LCH | tconstruct | 1.12.2-2.13.0.183 | TConstruct-1.12.2-2.13.0.183.jar | None | 98| LCH | conarm | 1.2.5.10 | conarm-1.12.2-1.2.5.10.jar | b33d2c8df492beff56d1bbbc92da49b8ab7345a1 | 99| LCH | golems | 7.1.9 | ExtraGolems-1.12-7.1.9.jar | None | 100| LCH | galaxyspace | 2.0.19 | GalaxySpace-1.12.2-2.0.19.jar | None | 101| LCH | waila | 1.8.26 | Hwyla-1.8.26-B41_1.12.2.jar | None | 102| LCH | llibrary | 1.7.20 | llibrary-1.7.20-1.12.2.jar | b9f30a813bee3b9dd5652c460310cfcd54f6b7ec | 103| LCH | iceandfire | 1.9.1 | iceandfire-1.9.1-1.12.2.jar | None | 104| LCH | exoplanets | 0.1.4 | Interstellar-Exoplanets-0.1.4.jar | 3a39a2b4e84bec377849d48f372382b39f883e16 | 105| LCH | mjrlegendslib | 1.12.2-1.2.1 | MJRLegendsLib-1.12.2-1.2.1.jar | b02331787272ec3515ebe63ecdeea0d746653468 | 106| LCH | stevekung's_lib | 1.2.0 | SteveKunG's-Lib-1.12.2-1.2.0.jar | None | 107| LCH | moreplanets | 2.3.0 | More-Planets-1.12.2-2.3.0-GC4.0.4.jar | None | 108| LCH | moreplanetsextras | 1.12.2-1.0 | MorePlanetsExtras-1.12.2-1.0.jar | None | 109| LCH | mutantbeasts | 1.12.2-1.0.2 | MutantBeasts-1.12.2-1.0.2.jar | None | 110| LCH | simpleplanes | 3.0.1.7 | simpleplanes-1.12.2-3.0.1.7.jar | None | 111| LCH | liketechnikstinkertweaks | 1.12.2-1.0.0.DEV.01dd320 | TinkersToolLevelingWithRandomModifiers-1.12.2-1.0.3.jar | None | 112| LCH | vampirism | 1.6.2 | Vampirism-1.12.2-1.6.2.jar | None | 113| LCH | teamlapen-lib | 1.6.2 | Vampirism-1.12.2-1.6.2.jar | None | 114| LCH | ladylib | 2.6.2 | Ladylib-2.6.2.jar | None | 115| LCH | modwinder | 1.1 | Ladylib-2.6.2.jar | None | 116| LCH | dissolution | 0.3.13 | Dissolution-1.12.2-0.3.13r2.jar | None | 117| LCH | immersiveengineering | 0.12-98 | ImmersiveEngineering-0.12-98.jar | None | 118 119Loaded coremods (and transformers): 120llibrary (llibrary-core-1.0.11-1.12.2.jar) 121net.ilexiconn.llibrary.server.core.plugin.LLibraryTransformer 122net.ilexiconn.llibrary.server.core.patcher.LLibraryRuntimePatcher 123IELoadingPlugin (ImmersiveEngineering-core-0.12-98.jar) 124blusunrize.immersiveengineering.common.asm.IEClassTransformer 125clothesline-hooks (clothesline-hooks-1.12.2-0.0.1.2.jar) 126com.jamieswhiteshirt.clothesline.hooks.plugin.ClassTransformer 127SteveKunGLibPlugin (SteveKunG's-Lib-1.12.2-1.2.0.jar) 128 129ApotheosisCore (Apotheosis-1.12.2-1.12.5.jar) 130shadows.ApotheosisTransformer 131iceandfire (iceandfire-1.9.1-1.12.2.jar) 132com.github.alexthe666.iceandfire.patcher.IceAndFireRuntimePatcher 133GSHooksLoader (GalaxySpace-1.12.2-2.0.19.jar) 134galaxyspace.core.hooklib.minecraft.PrimaryClassTransformer 135MixinBooter (!mixinbooter-7.0.jar) 136 137MicdoodlePlugin (Galacticraft-1.12.2-4.0.4.jar) 138micdoodle8.mods.miccore.MicdoodleTransformer 139Pulsar/tconstruct loaded Pulses: 140- TinkerCommons (Enabled/Forced) 141- TinkerWorld (Enabled/Not Forced) 142- TinkerTools (Enabled/Not Forced) 143- TinkerHarvestTools (Enabled/Forced) 144- TinkerMeleeWeapons (Enabled/Forced) 145- TinkerRangedWeapons (Enabled/Forced) 146- TinkerModifiers (Enabled/Forced) 147- TinkerSmeltery (Enabled/Not Forced) 148- TinkerGadgets (Enabled/Not Forced) 149- TinkerOredict (Enabled/Forced) 150- TinkerIntegration (Enabled/Forced) 151- TinkerFluids (Enabled/Forced) 152- TinkerMaterials (Enabled/Forced) 153- TinkerModelRegister (Enabled/Forced) 154- wailaIntegration (Enabled/Not Forced) 155 156Profiler Position: N/A (disabled) 157Is Modded: Definitely; Server brand changed to 'fml,forge' 158Type: Dedicated Server (map_server.txt)
    • Es que nunca me llega ha aparecer la carpeta de crash reports, el informe de error que yo pasé lo tengo que coger directamente de logs, y siempre que se me crashea me pone error 1.
    • Yes, you can. People have made datapacks for cutting wood planks into stairs, etc. Just make your Json recipe files formatting exactly the same way the files are done for the Stone Cutter recipes.
    • YEESSSSSSSSSSSSS OH MY GOD devs please pay attention to PostChain#parseUniformNode method it seems to be broken (or i am just dumb) and finally i can change this to [SOLVED]
  • Topics

×
×
  • Create New...

Important Information

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