Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

1.19.2 Golems not saving their persistant data after spawning from a packet[SOLVED]

Featured Replies

Posted

I am created a packet that spawns 3 golems and adds a timer to their persistant data along with the name of the owner who spawned them.

public boolean handle(Supplier<NetworkEvent.Context> supplier){
        NetworkEvent.Context context = supplier.get();
        context.enqueueWork(()-> {
            Player p = context.getSender();
            if(p.getPersistentData().contains(XprtData.SALUS_CLASS)){
                if(!p.getPersistentData().contains(XprtData.SALUS_DEFENDER_TIMER)){
                    for(int i=0;i<3;i++){
                        IronGolem golem = (IronGolem) EntityType.IRON_GOLEM.spawn(p.createCommandSourceStack().getLevel(), null, null,
                                p.blockPosition(), MobSpawnType.MOB_SUMMONED, true, false);

                        golem.getPersistentData().putInt(XprtData.SALUS_DEFENDER_TIMER, Utils.Seconds(50));
                        golem.getPersistentData().putString(XprtData.SALUS_DEFENDER_OWNER, p.getScoreboardName());
                        golem.setCustomName(Component.literal(ChatFormatting.GOLD + "" + p.getScoreboardName() + "'s Defender"));
                    }

                    p.getPersistentData().putInt(XprtData.SALUS_DEFENDER_TIMER, Utils.Seconds(5));
                } else {
                    int time = p.getPersistentData().getInt(XprtData.SALUS_DEFENDER_TIMER);
                    Utils.Message(p, ChatFormatting.RED + "You cannot summon defenders right now, " + Utils.TicksToSeconds(time) + " seconds remaining.");
                }
            }
        });

        return true;
    }

the problem is when I call upon their data in an external class here

@SubscribeEvent
    public static void onLivingTick(LivingEvent.LivingTickEvent e){
        LivingEntity entity = e.getEntity();
        if(entity instanceof IronGolem){
            if(entity.getPersistentData().contains(XprtData.SALUS_DEFENDER_TIMER)){
                Mob mob = (Mob)entity;
                for(LivingEntity target : Utils.getNear(entity, 8)){
                    if(target instanceof Player || target instanceof Villager || target instanceof Wolf || target instanceof IronGolem){
                        mob.setTarget(null);
                    } else {
                        mob.setTarget(target);
                    }
                }
            }
            if(entity.getPersistentData().contains(XprtData.SALUS_DEFENDER_OWNER)){
                String owner = entity.getPersistentData().getString(XprtData.SALUS_DEFENDER_OWNER);
                for(String pNames : entity.getServer().getPlayerNames()){
                    if(pNames.equals(owner)){
                        Player p = entity.getServer().getPlayerList().getPlayerByName(owner);
                        if(entity.distanceTo(p) >= 7f){
                            entity.teleportTo(p.getBlockX(), p.getBlockY()+1, p.getBlockZ());
                        }
                    }
                }
            }
        }
    }

neither XprtData.SALUS_DEFENDER_TIMER nor XprtData.SALUS_DEFENDER_OWNER contain any data, for the timer it starts off at 0 when it should be (22*50) and defender owner should contain the players name which instead contains a blank.

 

This isnt my first time doing something like this, ive done it will illagers and it worked perfectly but when it comes to golems it doesnt work at all. I could do with it the timer killing them at -(22*50) but it wont help that i still need the owners name to teleport them to the owner if they move to far away. Any Ideas? Im calling this packet from a keybind by the way

 

EDIT: 

I figured out the issue I accidentally had the same String name for both of the Strings so it kept overriding eachother

Edited by ChasePlays

  • ChasePlays changed the title to 1.19.2 Golems not saving their persistant data after spawning from a packet[SOLVED]

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.