Jump to content
  • Home
  • Files
  • Docs
Status Updates
  • All Content

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • LK1905

LK1905

Members
 View Profile  See their activity
  • Content Count

    29
  • Joined

    March 18, 2018
  • Last visited

    8 hours ago

Community Reputation

0 Neutral

About LK1905

  • Rank
    Tree Puncher

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. LK1905

    [SOLVED][1.16.4] Changing an entity's max health

    LK1905 replied to LK1905's topic in Modder Support

    I solved the problem. The problem as that I didn't have the getMaxHealth() method saved within my serializeNBT() method, so the game still thought the value was zero. Saving that value fixed the problem.
    • Yesterday at 12:03 PM
    • 2 replies
  2. LK1905 started following [SOLVED][1.16.4] Changing an entity's max health Yesterday at 08:27 AM
  3. LK1905

    [SOLVED][1.16.4] Changing an entity's max health

    LK1905 posted a topic in Modder Support

    I'm trying to modify an entity's max health based on a stat, but either its not working or my client isn't acknowledging the change. The method for the change. Full class here. @Override public void modifyMaxHealth(LivingEntity entity) { if(entity == null) { return; } entity = getEntity(); final float newAmount = getMaxHealth(); final float oldAmount; final UUID MODIFIER_ID = UUID.fromString("d5d0d878-b3c2-469b-ba89-ac01c0635a9c"); final ModifiableAttributeInstance health = entity.getAttribute(Attributes.MAX_HEALTH); final AttributeModifier mod = new AttributeModifier(MODIFIER_ID, "Max Health", newAmount, AttributeModifier.Operation.ADDITION); final AttributeModifier oldMod = health.getModifier(MODIFIER_ID); if(oldMod != null) { health.removeModifier(oldMod); oldAmount = (float) oldMod.getAmount(); }else { oldAmount = 0; } health.applyPersistentModifier(mod); final float amountToHeal = newAmount - oldAmount; if(amountToHeal > 0) { entity.heal(amountToHeal); } } The sync method: @Override public void sync(ServerPlayerEntity player) { if(entity instanceof ServerPlayerEntity) { PacketHandler.sendTo(new SkillsPacket(serializeNBT()), player); if(!player.world.isRemote) { ModifiableAttributeInstance attribute = player.getAttribute(Attributes.MAX_HEALTH); SEntityPropertiesPacket packet = new SEntityPropertiesPacket(player.getEntityId(), Collections.singleton(attribute)); ((ServerWorld) player.getEntityWorld()).getChunkProvider().sendToTrackingAndSelf(player, packet); } } } My player event class: package lk1905.gielinorcraft.events; import lk1905.gielinorcraft.Gielinorcraft; import lk1905.gielinorcraft.api.skill.ISkills; import lk1905.gielinorcraft.capability.skill.SkillCapability; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.event.entity.player.PlayerEvent.PlayerChangedDimensionEvent; import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent; import net.minecraftforge.event.entity.player.PlayerEvent.PlayerRespawnEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber(modid = Gielinorcraft.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class PlayerEventHandler { @SubscribeEvent public static void onPlayerClone(PlayerEvent.Clone event) { if(!event.isWasDeath()) { return; } ISkills oldSkills = event.getOriginal().getCapability(SkillCapability.SKILL_CAP, null).orElse(null); ISkills newSkills = event.getPlayer().getCapability(SkillCapability.SKILL_CAP, null).orElse(null); if(oldSkills != null) { if(newSkills != null) { for(int i = 0; i < 26; i++) { newSkills.setXp(i, oldSkills.getXp(i)); newSkills.setStaticLevel(i, oldSkills.getStaticLevel(i)); newSkills.setLevel(i, oldSkills.getLevel(i)); } } } } @SubscribeEvent public static void onPlayerChangedDimensionEvent(PlayerChangedDimensionEvent event) { ServerPlayerEntity player = (ServerPlayerEntity) event.getPlayer(); if(!player.world.isRemote) { player.getCapability(SkillCapability.SKILL_CAP).ifPresent(c -> c.sync(player)); player.getCapability(SkillCapability.SKILL_CAP).ifPresent(c -> c.modifyMaxHealth(player)); } } @SubscribeEvent public static void onRespawnEvent(PlayerRespawnEvent event) { ServerPlayerEntity player = (ServerPlayerEntity) event.getPlayer(); if(!player.world.isRemote) { player.getCapability(SkillCapability.SKILL_CAP).ifPresent(c -> c.sync(player)); player.getCapability(SkillCapability.SKILL_CAP).ifPresent(c -> c.modifyMaxHealth(player)); } } @SubscribeEvent public static void onPlayerConnect(PlayerLoggedInEvent event) { ServerPlayerEntity player = (ServerPlayerEntity) event.getPlayer(); if(!player.world.isRemote) { player.getCapability(SkillCapability.SKILL_CAP).ifPresent(c -> c.sync(player)); player.getCapability(SkillCapability.SKILL_CAP).ifPresent(c -> c.modifyMaxHealth(player)); } } } Full repo here, if you need to look at anything else.
    • Yesterday at 08:27 AM
    • 2 replies
  4. LK1905

    [Solved][1.16.4] How do I correctly sync capability data between Client and server?

    LK1905 replied to LK1905's topic in Modder Support

    I've changed the serializeNBT and deserialize methods so the value of i is in the key: @Override public CompoundNBT serializeNBT() { CompoundNBT data = new CompoundNBT(); for(int i = 0; i < 26; i++) { data.putInt("xp_" + i, (int) xp[i]); data.putInt("dynamic_" + i, dynamicLevels[i]); data.putInt("static_" + i, staticLevels[i]); } return data; } @Override public void deserializeNBT(CompoundNBT data) { for(int i = 0; i < 26; i++) { xp[i] = data.getInt("xp_" + i); dynamicLevels[i] = data.getInt("dynamic_" + i); staticLevels[i] = data.getInt("static_" + i); } } And now it works, thank you! (I think thats what the first person to reply to this post was trying to tell me to do but I didn't understand at the time).
    • January 23
    • 28 replies
  5. LK1905

    [Solved][1.16.4] How do I correctly sync capability data between Client and server?

    LK1905 replied to LK1905's topic in Modder Support

    Okay, I believe I've done what you have told me, and my gui does update me gaining xp. However, theres something wrong with my sync method, as whenever it is called, it resets all xp values to zero. So the values in my gui are lost when reloading the world. Heres the sync method in my Skills class: @Override public void sync(ServerPlayerEntity player) { if(entity instanceof ServerPlayerEntity) { PacketHandler.sendTo(new SkillsPacket(serializeNBT()), player); } } Heres my attempt at syncing on login, in my player event handler: @SubscribeEvent public static void onPlayerConnect(PlayerLoggedInEvent event) { ServerPlayerEntity player = (ServerPlayerEntity) event.getPlayer(); if(!player.world.isRemote) { player.getCapability(SkillCapability.SKILL_CAP).ifPresent(c -> c.sync(player)); } } Updated my git repo, here.
    • January 23
    • 28 replies
  6. LK1905

    [Solved][1.16.4] How do I correctly sync capability data between Client and server?

    LK1905 replied to LK1905's topic in Modder Support

    Then I'm not sure what you mean by "Pass in the player", sorry.
    • January 18
    • 28 replies
  7. LK1905

    [Solved][1.16.4] How do I correctly sync capability data between Client and server?

    LK1905 replied to LK1905's topic in Modder Support

    Did you mean replace EntityLiving in the Object instanceof part with PlayerEntity? Because I just tried that and it made no difference.
    • January 18
    • 28 replies
  8. LK1905

    [Solved][1.16.4] How do I correctly sync capability data between Client and server?

    LK1905 replied to LK1905's topic in Modder Support

    Sorry for the late response. Another stupid question, but how do I set the the entity so that it's not null?
    • January 17
    • 28 replies
  9. LK1905

    [Solved][1.16.4] How do I correctly sync capability data between Client and server?

    LK1905 replied to LK1905's topic in Modder Support

    Is that this part? public static void register() { CapabilityManager.INSTANCE.register(ISkills.class, new SkillStorage(), () -> new Skills(null)); } If so, isn't that part supposed to be null? Every other capability I've seen from other people that had an entity/player there had it set to null.
    • January 4
    • 28 replies
  10. LK1905

    [Solved][1.16.4] How do I correctly sync capability data between Client and server?

    LK1905 replied to LK1905's topic in Modder Support

    https://github.com/LK1905/GielinorCraft
    • January 4
    • 28 replies
  11. LK1905

    [Solved][1.16.4] How do I correctly sync capability data between Client and server?

    LK1905 replied to LK1905's topic in Modder Support

    But as far as I know, my packet and event handler are already supposed to sync it. Which is why I made this thread, to ask why they aren't.
    • January 3
    • 28 replies
  12. LK1905

    [Solved][1.16.4] How do I correctly sync capability data between Client and server?

    LK1905 replied to LK1905's topic in Modder Support

    My GUI doesn't update the xp values. This is how I reference the player in my GUI: private PlayerEntity player = Minecraft.getInstance().player; private LazyOptional<ISkills> cap = player.getCapability(SkillCapability.SKILL_CAP); private ISkills skills = cap.orElse(null); Do I need to reference the Server Player instead? If so, how? Or Is the client player already supposed to know my server player data from my events/packets? If so, why aren't they working? They're in the OP.
    • January 3
    • 28 replies
  13. LK1905

    [Solved][1.16.4] How do I correctly sync capability data between Client and server?

    LK1905 replied to LK1905's topic in Modder Support

    I changed that part to this: PlayerEntity player = (PlayerEntity) event.getSource().getTrueSource(); LazyOptional<ISkills> cap = player.getCapability(SkillCapability.SKILL_CAP); ISkills skills = cap.orElse(null); But now I can't gain xp at all. Is that the correct way of doing it?
    • January 2
    • 28 replies
  14. LK1905

    [Solved][1.16.4] How do I correctly sync capability data between Client and server?

    LK1905 replied to LK1905's topic in Modder Support

    I added it into the AddXP method like this: if(entity instanceof PlayerEntity) { sync((ServerPlayerEntity) entity); } That didn't make any difference. Is that what you meant?
    • January 1
    • 28 replies
  15. LK1905

    [Solved][1.16.4] How do I correctly sync capability data between Client and server?

    LK1905 replied to LK1905's topic in Modder Support

    This is probably a stupid question, but how would I do that? I tried adding it to SkillStorage the same way I have the getXP, getLevel and getStaticLevel methods, but that made no difference. Is that what you meant, or something different?
    • December 31, 2020
    • 28 replies
  16. LK1905

    [Solved][1.16.4] How do I correctly sync capability data between Client and server?

    LK1905 replied to LK1905's topic in Modder Support

    I don't think there's anything wrong with the SkillStorage, as I can gain xp just fine, in the correct skills, the data is just reset to zero when i close and reopen the world. I also have the "Hitpoints" skill set to level 10 and 1154 xp by default. If I comment out my PlayerLoggedInEvent, the skill is correctly set to those values in game, and is reset to those values when I leave the world. But with the event enabled, both the level and xp values are set to 1 and 0.
    • December 31, 2020
    • 28 replies
  • All Activity
  • Home
  • LK1905
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community