InfinityStudio / GokiStats

GokiStats, a Minecraft mod, RPG
GNU General Public License v3.0
25 stars 12 forks source link

Max Health death reset issue fixed #102

Open TsuneZebra opened 12 months ago

TsuneZebra commented 12 months ago

Only added a respawn listening event

In the MainClass:

public GokiStats() { instance = this; IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus(); eventBus.addListener(this::construct); GokiPacketHandler.registerMessages();

    MinecraftForge.EVENT_BUS.addListener(this::onPlayerRespawn); //Add this
}

//add this private void onPlayerRespawn(PlayerEvent.Clone event) { if (event.isWasDeath() && event.getOriginal() instanceof ServerPlayerEntity) { ServerPlayerEntity originalPlayer = (ServerPlayerEntity) event.getOriginal(); ServerPlayerEntity newPlayer = (ServerPlayerEntity) event.getPlayer();

        StatBase stat = StatBase.stats.get(21);
        final int level = DataHelper.getPlayerStatLevel(originalPlayer, stat);
        if (stat.isEnabled()) {
            newPlayer.getAttribute(Attributes.MAX_HEALTH)
                    .setBaseValue(20 + stat.getBonus(level));
        }
    }
}