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

[1.15.2][Solved] Getting entity on Client Side


Papa_Prime
 Share

Recommended Posts

Hello, I am currently trying to sync the client with the server. I am currently unable to find a way in which I can encode entity identifiers from the server to the client. This is my current code:

public class ActionControlCSPacket {

    static Map map;

    public ActionControlCSPacket(Map controlMap)
    {
        map = controlMap;
    }

    public static void encode(ActionControlCSPacket msg, PacketBuffer buf)
    {
        PlayerEntity[] players = (PlayerEntity[]) map.keySet().toArray(new PlayerEntity[0]);
        CompoundNBT tag = new CompoundNBT();
        for(int t = 0; t < players.length; t++) {
            tag.put(String.valueOf(t), players[t].serializeNBT());
        }
        Integer[] values1 = (Integer[]) map.values().toArray(new Integer[0]);
        int[] values = new int[0];
        for(int i = 0; i < values1.length; i++)
        {
            values[i] = values1[i].intValue();
        }
        buf.writeCompoundTag(tag);
        buf.writeVarIntArray(values);
    }

    public static ActionControlCSPacket decode(PacketBuffer buf)
    {
        CompoundNBT tag = buf.readCompoundTag();
        int[] values = buf.readVarIntArray();
        Map hmap = new HashMap<PlayerEntity, Integer>();

        for(int i = 0; i < values.length; i++)
        {

            hmap.put(?????, values[i]);
        }

        return new ActionControlCSPacket(hmap);
    }

    public static void handle(ActionControlCSPacket message, Supplier<NetworkEvent.Context> ctx) {

        ActionControl.setControl(map);
        System.out.print("called");
        ctx.get().setPacketHandled(true);
    }
}

I have tried using the decoded tag in a number of ways but was unable to use the INBT to identify an entity. An idea would be to encode player IDs and then find them on the client but I am not aware of a method which allows me to do this although I am certain that it exists. Any help would be appreciated.

Edit: I have located such a method in the world class. Was obvious, still working on a solution.

Edited by Papa_Prime
Link to comment
Share on other sites

Here is the update code, not fully functional yet but getting there:

public class ActionControlCSPacket {

    static Map map;

    public ActionControlCSPacket(Map controlMap)
    {
        map = controlMap;
    }

    public static void encode(ActionControlCSPacket msg, PacketBuffer buf)
    {
        Integer[] players = (Integer[]) map.keySet().toArray(new Integer[0]);
        int[] id = new int[players.length];
        for(int i = 0; i < players.length; i++)
        {
            id[i] = players[i].intValue();
        }
        Integer[] preValues = (Integer[]) map.values().toArray(new Integer[0]);
        int[] values = new int[players.length];
        for(int i = 0; i < players.length; i++)
        {
            values[i] = preValues[i].intValue();
        }
        buf.writeVarIntArray(id);
        buf.writeVarIntArray(values);
    }

    public static ActionControlCSPacket decode(PacketBuffer buf)
    {
        Minecraft mc = Minecraft.getInstance();
        World world = mc.player.world;

        int[] id = buf.readVarIntArray();
        int[] values = buf.readVarIntArray();

        Map hmap = new HashMap<Integer, Integer>();

        for(int i = 0; i < id.length; i++)
        {
            hmap.put(id[i], values[i]);
        }

        return new ActionControlCSPacket(hmap);
    }

    public static void handle(ActionControlCSPacket message, Supplier<NetworkEvent.Context> ctx) {

        ActionControl.setControl(map);
        ctx.get().setPacketHandled(true);
    }
}

Just need to fix the array out of bounds exception which is easy. Leaving this here in case anyone finds more mistakes in my code. Going offline for now.

Edit: Updated to a version which seems to work

Edited by Papa_Prime
clean code
Link to comment
Share on other sites

On 6/13/2020 at 10:07 AM, diesieben07 said:

What on earth.

Please learn basic Java (generics, how collections work, etc.). Your code is a mess.

I caught on to that when I went to test it. Going to update it here now, this is what I got to work.

Edited by Papa_Prime
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.

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

    • ---- Minecraft Crash Report ---- WARNING: coremods are present:   TransformLoader (DynamicSurroundings-1.12.2-3.6.1.0.jar)   ForgelinPlugin (Forgelin-1.8.4.jar)   MovingWorldCore (movingworld-1.12-6.353-full.jar)   Quark Plugin (Quark-r1.6-179.jar)   CorePlugin (ForgeEndertech-1.12.2-4.5.5.0-build.0561.jar)   CTMCorePlugin (CTM-MC1.12.2-1.0.2.31.jar)   FarseekCoreMod (Farseek-1.12-2.5.1.jar)   FutureMC (future-mc-1.12.2-0.2.6.1.jar) Contact their authors BEFORE contacting forge // Surprise! Haha. Well, this is awkward. Time: 9/20/21 10:59 AM Description: Ticking block entity java.lang.NullPointerException: Ticking block entity     at net.minecraftforge.fluids.FluidStack.<init>(FluidStack.java:72)     at ic2.core.block.transport.TileEntityFluidPipe$PipeFluidHandler.drain(TileEntityFluidPipe.java:350)     at ic2.core.util.LiquidUtil.drainTile(LiquidUtil.java:332)     at ic2.core.util.LiquidUtil.drainTile(LiquidUtil.java:323)     at ic2.core.block.machine.tileentity.TileEntityPump.pump(TileEntityPump.java:204)     at ic2.core.block.machine.tileentity.TileEntityPump.operate(TileEntityPump.java:177)     at ic2.core.block.machine.tileentity.TileEntityPump.canoperate(TileEntityPump.java:146)     at ic2.core.block.machine.tileentity.TileEntityPump.updateEntityServer(TileEntityPump.java:123)     at ic2.core.block.TileEntityBlock.func_73660_a(TileEntityBlock.java:326)     at net.minecraft.world.World.func_72939_s(World.java:1838)     at net.minecraft.world.WorldServer.func_72939_s(WorldServer.java:613)     at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:767)     at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:397)     at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:668)     at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:526)     at java.lang.Thread.run(Unknown Source) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Server thread Stacktrace:     at net.minecraftforge.fluids.FluidStack.<init>(FluidStack.java:72)     at ic2.core.block.transport.TileEntityFluidPipe$PipeFluidHandler.drain(TileEntityFluidPipe.java:350)     at ic2.core.util.LiquidUtil.drainTile(LiquidUtil.java:332)     at ic2.core.util.LiquidUtil.drainTile(LiquidUtil.java:323)     at ic2.core.block.machine.tileentity.TileEntityPump.pump(TileEntityPump.java:204)     at ic2.core.block.machine.tileentity.TileEntityPump.operate(TileEntityPump.java:177)     at ic2.core.block.machine.tileentity.TileEntityPump.canoperate(TileEntityPump.java:146)     at ic2.core.block.machine.tileentity.TileEntityPump.updateEntityServer(TileEntityPump.java:123)     at ic2.core.block.TileEntityBlock.func_73660_a(TileEntityBlock.java:326) -- Block entity being ticked -- Details:     Name: ic2:pump // ic2.core.block.machine.tileentity.TileEntityPump     Block type: ID #388 (ic2.te // ic2.core.block.BlockTileEntity // ic2:te)     Block data value: 1 / 0x1 / 0b0001     Block location: World: (137,34,-88), Chunk: (at 9,2,8 in 8,-6; contains blocks 128,0,-96 to 143,255,-81), Region: (0,-1; contains chunks 0,-32 to 31,-1, blocks 0,0,-512 to 511,255,-1)     Actual block type: ID #388 (ic2.te // ic2.core.block.BlockTileEntity // ic2:te)     Actual block data value: 1 / 0x1 / 0b0001 Stacktrace:     at net.minecraft.world.World.func_72939_s(World.java:1838)     at net.minecraft.world.WorldServer.func_72939_s(WorldServer.java:613) -- Affected level -- Details:     Level name: world     All players: 1 total; [EntityPlayerMP['ZtiromDE'/383, l='world', x=136.18, y=35.14, z=-88.54]]     Chunk stats: ServerChunkCache: 137 Drop: 0     Level seed: 6427110845652378783     Level generator: ID 00 - default, ver 1. Features enabled: false     Level generator options:     Level spawn location: World: (0,0,0), Chunk: (at 0,0,0 in 0,0; contains blocks 0,0,0 to 15,255,15), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)     Level time: 0 game time, 0 day time     Level dimension: 0     Level storage version: 0x00000 - Unknown?     Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)     Level game mode: Game mode: survival (ID 0). Hardcore: false. Cheats: false Stacktrace:     at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:767)     at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:397)     at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:668)     at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:526)     at java.lang.Thread.run(Unknown Source) -- System Details -- Details:     Minecraft Version: 1.12.2     Operating System: Windows 10 (amd64) version 10.0     Java Version: 1.8.0_301, Oracle Corporation     Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation     Memory: 2877134552 bytes (2743 MB) / 4130340864 bytes (3939 MB) up to 8388608000 bytes (8000 MB)     JVM Flags: 1 total; -Xmx9000M     IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 7     FML: MCP 9.42 Powered by Forge 14.23.5.2854 58 mods loaded, 58 mods active     States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored     | State  | ID                                           | Version            | Source                                        | Signature                                |     |:------ |:-------------------------------------------- |:------------------ |:--------------------------------------------- |:---------------------------------------- |     | LCHIJA | minecraft                                    | 1.12.2             | minecraft.jar                                 | None                                     |     | LCHIJA | mcp                                          | 9.42               | minecraft.jar                                 | None                                     |     | LCHIJA | FML                                          | 8.0.99.99          | server.jar                                    | e3c3d50c7c986df74c645c0ac54639741c90a557 |     | LCHIJA | forge                                        | 14.23.5.2854       | server.jar                                    | e3c3d50c7c986df74c645c0ac54639741c90a557 |     | LCHIJA | com.elytradev.movingworld.common.asm.coremod |                    | minecraft.jar                                 | None                                     |     | LCHIJA | forgeendertech                               | 1.12.2-4.5.5.0     | ForgeEndertech-1.12.2-4.5.5.0-build.0561.jar  | None                                     |     | LCHIJA | adpoles                                      | 1.12.2-2.0.3.0     | AdPoles-1.12.2-2.0.3.0-build.0552.jar         | None                                     |     | LCHIJA | crafttweaker                                 | 4.1.20             | CraftTweaker2-1.12-4.1.20.660.jar             | None                                     |     | LCHIJA | jei                                          | 4.16.1.301         | jei_1.12.2-4.16.1.301.jar                     | None                                     |     | LCHIJA | quark                                        | r1.6-179           | Quark-r1.6-179.jar                            | None                                     |     | LCHIJA | autoreglib                                   | 1.3-32             | AutoRegLib-1.3-32.jar                         | None                                     |     | LCHIJA | biomesoplenty                                | 7.0.1.2441         | BiomesOPlenty-1.12.2-7.0.1.2441-universal.jar | None                                     |     | LCHIJA | bookshelf                                    | 2.3.590            | Bookshelf-1.12.2-2.3.590.jar                  | d476d1b22b218a10d845928d1665d45fce301b27 |     | LCHIJA | chisel                                       | MC1.12.2-1.0.2.45  | Chisel-MC1.12.2-1.0.2.45.jar                  | None                                     |     | LCHIJA | chiselsandbits                               | 14.33              | chiselsandbits-14.33.jar                      | None                                     |     | LCHIJA | clumps                                       | 3.1.2              | Clumps-3.1.2.jar                              | None                                     |     | LCHIJA | collective                                   | 2.64               | collective-1.12.2-2.64.jar                    | None                                     |     | LCHIJA | cosmeticarmorreworked                        | 1.12.2-v5a         | CosmeticArmorReworked-1.12.2-v5a.jar          | aaaf83332a11df02406e9f266b1b65c1306f0f76 |     | LCHIJA | crafttweakerjei                              | 2.0.3              | CraftTweaker2-1.12-4.1.20.660.jar             | None                                     |     | LCHIJA | movingworld                                  | 1.12-6.353         | movingworld-1.12-6.353-full.jar               | None                                     |     | LCHIJA | davincisvessels                              | @DVESSELSVER@      | davincisvessels-1.12-6.340-full.jar           | None                                     |     | LCHIJA | orelib                                       | 3.6.0.1            | OreLib-1.12.2-3.6.0.1.jar                     | 7a2128d395ad96ceb9d9030fbd41d035b435753a |     | LCHIJA | dsurround                                    | 3.6.1.0            | DynamicSurroundings-1.12.2-3.6.1.0.jar        | 7a2128d395ad96ceb9d9030fbd41d035b435753a |     | LCHIJA | farseek                                      | 2.5.1              | Farseek-1.12-2.5.1.jar                        | None                                     |     | LCHIJA | forgelin                                     | 1.8.4              | Forgelin-1.8.4.jar                            | None                                     |     | LCHIJA | futuremc                                     | 0.2.6              | future-mc-1.12.2-0.2.6.1.jar                  | None                                     |     | LCHIJA | gamestages                                   | 2.0.123            | GameStages-1.12.2-2.0.123.jar                 | d476d1b22b218a10d845928d1665d45fce301b27 |     | LCHIJA | geographicraft                               | 0.8.7              | GeographiCraft-1.12-0.8.9b.jar                | None                                     |     | LCHIJA | grapplemod                                   | 1.12.2-v11.1       | grapplemod-v11.1-1.12.2.jar                   | None                                     |     | LCHIJA | gravestone                                   | 1.10.3             | gravestone-1.10.3.jar                         | None                                     |     | LCHIJA | happytrails                                  | 1.0.0.5            | HappyTrails-1.12.2-1.0.0.5.jar                | None                                     |     | LCHIJA | waila                                        | 1.8.26             | Hwyla-1.8.26-B41_1.12.2.jar                   | None                                     |     | LCHIJA | ichunutil                                    | 7.2.2              | iChunUtil-1.12.2-7.2.2.jar                    | 4db5c2bd1b556f252a5b8b54b256d381b2a0a6b8 |     | LCHIJA | ido                                          | 1.0.6              | ido-1.12.2-1.1.0.jar                          | None                                     |     | LCHIJA | ic2                                          | 2.8.170-ex112      | industrialcraft-2-2.8.170-ex112.jar           | de041f9f6187debbc77034a344134053277aa3b0 |     | LCHIJA | mantle                                       | 1.12-1.3.3.55      | Mantle-1.12-1.3.3.55.jar                      | None                                     |     | LCHIJA | inspirations                                 | 1.12.2-0.2.9       | Inspirations-1.12.2-0.2.9.jar                 | None                                     |     | LCHIJA | ironchest                                    | 1.12.2-7.0.67.844  | ironchest-1.12.2-7.0.72.847.jar               | None                                     |     | LCHIJA | journeymap                                   | 1.12.2-5.7.1       | journeymap-1.12.2-5.7.1.jar                   | None                                     |     | LCHIJA | guilib                                       | $version           | morepaintings-paintings-1.12.2-5.0.1.2.jar    | None                                     |     | LCHIJA | paintingselgui                               | $version           | morepaintings-paintings-1.12.2-5.0.1.2.jar    | None                                     |     | LCHIJA | morepaintings                                | $version           | morepaintings-paintings-1.12.2-5.0.1.2.jar    | None                                     |     | LCHIJA | naturescompass                               | 1.8.5              | NaturesCompass-1.12.2-1.8.5.jar               | None                                     |     | LCHIJA | netherendingores                             | 1.12.2-1.4.2       | Netherending-Ores-1.12.2-1.4.2.jar            | None                                     |     | LCHIJA | examplemod                                   | 1.0                | NuclearCraft-2.18z-1.12.2.jar                 | None                                     |     | LCHIJA | nuclearcraft                                 | 2.18z              | NuclearCraft-2.18z-1.12.2.jar                 | None                                     |     | LCHIJA | pixelmon                                     | 8.2.0              | Pixelmon-1.12.2-8.2.0-universal.jar           | None                                     |     | LCHIJA | placeableitems                               | 3.3                | placeableitems-3.3.jar                        | None                                     |     | LCHIJA | refinedstorage                               | 1.6.16             | refinedstorage-1.6.16.jar                     | 57893d5b90a7336e8c63fe1c1e1ce472c3d59578 |     | LCHIJA | spartanshields                               | 1.5.4              | SpartanShields-1.12.2-1.5.4.jar               | None                                     |     | LCHIJA | spartanweaponry                              | beta 1.3.8         | SpartanWeaponry-1.12.2-beta-1.3.8.jar         | None                                     |     | LCHIJA | streams                                      | 0.4.9              | Streams-1.12-0.4.9.jar                        | None                                     |     | LCHIJA | tinymobfarm                                  | 1.0.5              | TinyMobFarm-1.12.2-1.0.5.jar                  | None                                     |     | LCHIJA | travelersbackpack                            | 1.0.35             | TravelersBackpack-1.12.2-1.0.35.jar           | None                                     |     | LCHIJA | treeharvester                                | 3.2                | treeharvester_1.12.2-3.2.jar                  | None                                     |     | LCHIJA | wailastages                                  | 2.0.23             | WailaStages-1.12.2-2.0.23.jar                 | d476d1b22b218a10d845928d1665d45fce301b27 |     | LCHIJA | waystones                                    | 4.1.0              | Waystones_1.12.2-4.1.0.jar                    | None                                     |     | LCHIJA | rtg                                          | 6.1.0.0-snapshot.1 | RTG-1.12.2-6.1.0.0-snapshot.1.jar             | None                                     |     Loaded coremods (and transformers): TransformLoader (DynamicSurroundings-1.12.2-3.6.1.0.jar)   ForgelinPlugin (Forgelin-1.8.4.jar)   MovingWorldCore (movingworld-1.12-6.353-full.jar)   Quark Plugin (Quark-r1.6-179.jar)   vazkii.quark.base.asm.ClassTransformer CorePlugin (ForgeEndertech-1.12.2-4.5.5.0-build.0561.jar)   CTMCorePlugin (CTM-MC1.12.2-1.0.2.31.jar)   team.chisel.ctm.client.asm.CTMTransformer FarseekCoreMod (Farseek-1.12-2.5.1.jar)   farseek.core.FarseekClassTransformer FutureMC (future-mc-1.12.2-0.2.6.1.jar)   thedarkcolour.futuremc.asm.CoreTransformer     Pulsar/inspirations loaded Pulses:         - InspirationsShared (Enabled/Forced)         - InspirationsBuilding (Enabled/Not Forced)         - InspirationsUtility (Enabled/Not Forced)         - InspirationsTools (Enabled/Not Forced)         - InspirationsRecipes (Enabled/Not Forced)         - InspirationsTweaks (Enabled/Not Forced)         - InspirationsShared (Enabled/Forced)         - WailaPlugin (Enabled/Not Forced)     Profiler Position: N/A (disabled)     Player Count: 2 / 20; [EntityPlayerMP['T3rm1n6t0r'/17, l='world', x=9.98, y=73.00, z=99.44], EntityPlayerMP['ZtiromDE'/383, l='world', x=136.18, y=35.14, z=-88.54]]     Is Modded: Definitely; Server brand changed to 'fml,forge'     Type: Dedicated Server (map_server.txt)
    • Sorry, for the late reply.  Deleting the folders worked perfect thank you so far.  As the log is that big can you tell me what you searched for to find this paths?
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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