#Access local lambda variable

9 messages · Page 1 of 1 (latest)

silver ice
#

I am making a modification for another mod (fabric carpet) which spawns fake players.
I need to do two things. Add those players to a team and change their action packs.

In 1.19 I did that by having the instance of the newly created player, but now it seems kinda dificult.

I'd want to access this instancefield inside the lambda, but don't know how to do it (if possible). I am open to new ideas on how to do it, if you have any other
(Code on next message)

#

Here is the (stripped down)code for spawning the players:

    public static boolean createFake(String username, MinecraftServer server, Vec3d pos, double yaw, double pitch, RegistryKey<World> dimensionId, GameMode gamemode, boolean flying)
    {
        String name = gameprofile.getName();
        spawning.add(name);

        fetchGameProfile(name).whenCompleteAsync((p, t) -> {            spawning.remove(name);
            if (t != null)
            {
                return;
            }

            GameProfile current = finalGP;
            if (p.isPresent())
            {
                current = p.get();
            }
            EntityPlayerMPFake instance = new EntityPlayerMPFake(server, worldIn, current, SyncedClientOptions.createDefault(), false);
            instance.fixStartingPosition = () -> instance.refreshPositionAndAngles(pos.x, pos.y, pos.z, (float) yaw, (float) pitch);
            server.getPlayerManager().onPlayerConnect(new FakeClientConnection(NetworkSide.SERVERBOUND), instance, new ConnectedClientData(current, 0, instance.getClientOptions(), false));
            instance.teleport(worldIn, pos.x, pos.y, pos.z, Set.of(), (float) yaw, (float) pitch, true);
            instance.setHealth(20.0F);
            instance.unsetRemoved();
            instance.getAttributeInstance(EntityAttributes.STEP_HEIGHT).setBaseValue(0.6F);
            instance.interactionManager.changeGameMode(gamemode);
            server.getPlayerManager().sendToDimension(new EntitySetHeadYawS2CPacket(instance, (byte) (instance.headYaw * 256 / 360)), dimensionId);//instance.dimension);
            server.getPlayerManager().sendToDimension(EntityPositionSyncS2CPacket.create(instance), dimensionId);
            instance.dataTracker.set(PLAYER_MODEL_PARTS, (byte) 0x7f); // show all model layers (incl. capes)
            instance.getAbilities().flying = flying;
        }, server);
        return true;
    }
wanton vector
#

Are you trying to mixin into the lambda? I'm on mobile, so I can't read the code well

#

Or trying to get a local into the lambda you're mixing in to?

silver ice
#

I am trying to mixin into the lambda, but I couldn't find any way to do so

wanton vector
#

One sec

#

!!mixinlambda

light jasperBOT
#

When mixing into methods, ensure that your target isn't inside a lambda. Java implements lambdas by creating a separate synthetic method containing the bytecode for that lambda. So you need to find the name of that method instead and substitute it for your method = ".., this can be done in intellij like this: https://streamable.com/3vg1d2