Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, modid = XLifeHealth.MOD_ID)
- public class HealthEvents {
- private float maxHealth = 0;
- public float getMaxHealth() {
- return maxHealth;
- }
- public void setMaxHealth(float maxHealth) {
- this.maxHealth = maxHealth;
- }
- @SubscribeEvent
- public void onPlayerDie(LivingDeathEvent event) {
- if (event.getEntityLiving() instanceof PlayerEntity) {
- PlayerEntity player = (PlayerEntity) event.getEntityLiving();
- setMaxHealth(player.getMaxHealth());
- }
- }
- @SubscribeEvent
- public void onRespawn(PlayerEvent.PlayerRespawnEvent event) {
- PlayerEntity player = event.getPlayer();
- SecurityCheck.securityCheck(player);
- setHealthAfterDeath(player);
- }
- @SubscribeEvent
- public void onEnterNether(PlayerEvent.PlayerChangedDimensionEvent event) {
- PlayerEntity player = event.getPlayer();
- SecurityCheck.securityCheck(player);
- applyMaxHealthModifier(player, 0f);
- }
- @SubscribeEvent
- public void onFirstJoin(PlayerEvent.PlayerLoggedInEvent event){
- PlayerEntity player = event.getPlayer();
- CompoundNBT entityData = player.getPersistentData();
- if(!entityData.getBoolean("xlifehealth.firstJoin") && player.getMaxHealth() == 20f) {
- entityData.putBoolean("xlifehealth.firstJoin", true);
- removeMaxHealthModifiers(player);
- applyMaxHealthModifier(player, -18f);
- SendMessage.sendMessage(player, TextFormatting.YELLOW + "=====================================");
- SendMessage.sendMessage(player, " ");
- SendMessage.sendMessage(player, TextFormatting.GOLD + "Welcome to X Life!");
- SendMessage.sendMessage(player, " ");
- SendMessage.sendMessage(player, TextFormatting.WHITE + "You'll start off with only one heart.");
- SendMessage.sendMessage(player, TextFormatting.WHITE + "Every time you die, a heart will be added.");
- SendMessage.sendMessage(player, TextFormatting.WHITE + "When you die with 10 hearts, you will be banned!");
- SendMessage.sendMessage(player, " ");
- SendMessage.sendMessage(player, TextFormatting.GOLD + "Good Luck!");
- SendMessage.sendMessage(player, " ");
- SendMessage.sendMessage(player, TextFormatting.YELLOW + "=====================================");
- }
- }
- public void setHealthAfterDeath(PlayerEntity player) {
- if (getMaxHealth() >= 2 && getMaxHealth() <= 18) {
- float maxHealth = getMaxHealth();
- int lives = (int) (10 - (maxHealth / 2));
- int modifierAmount = (lives * 2 - 2) - ((lives * 2 - 2) + (lives * 2 - 2));
- removeMaxHealthModifiers(player);
- applyMaxHealthModifier(player, modifierAmount);
- if (lives < 10) {
- if (lives == 9) {
- SendMessage.sendMessage(player, TextFormatting.RED + "You have 9 lives remaining . . .");
- setBlueHearts();
- }
- if (lives == 8) {
- SendMessage.sendMessage(player, TextFormatting.RED + "You have 8 lives remaining . . .");
- setGreenHearts();
- }
- if (lives == 7) {
- SendMessage.sendMessage(player, TextFormatting.RED + "You have 7 lives remaining . . .");
- }
- if (lives == 6) {
- SendMessage.sendMessage(player, TextFormatting.RED + "You have 6 lives remaining . . .");
- }
- if (lives == 5) {
- SendMessage.sendMessage(player, TextFormatting.RED + "You have 5 lives remaining . . .");
- }
- if (lives == 4) {
- SendMessage.sendMessage(player, TextFormatting.RED + "You have 4 lives remaining . . .");
- }
- if (lives == 3) {
- SendMessage.sendMessage(player, TextFormatting.RED + "You have 3 lives remaining . . .");
- }
- if (lives == 2) {
- SendMessage.sendMessage(player, TextFormatting.RED + "You have 2 lives remaining . . .");
- }
- if (lives == 1) {
- SendMessage.sendMessage(player, TextFormatting.DARK_RED + "You have 1 life remaining . . .");
- }
- }
- } else if (getMaxHealth() == 20) {
- player.setGameType(GameType.SPECTATOR);
- SendMessage.sendMessage(player,TextFormatting.RED + "You have died with 10 hearts remaining.");
- SendMessage.sendMessage(player,TextFormatting.RED + "You have been put in spectator mode.");
- removeMaxHealthModifiers(player);
- applyMaxHealthModifier(player, 0);
- } else {
- removeMaxHealthModifiers(player);
- applyMaxHealthModifier(player, -18);
- }
- }
- public static final ResourceLocation BLUE_HEARTS = new ResourceLocation("xlifehealth:textures/gui/blue_hearts.png");
- public static final ResourceLocation GREEN_HEARTS = new ResourceLocation("xlifehealth:textures/gui/green_hearts.png");
- public static final ResourceLocation ORANGE_HEARTS = new ResourceLocation("xlifehealth:textures/gui/orange_hearts.png");
- public static final ResourceLocation PINK_HEARTS = new ResourceLocation("xlifehealth:textures/gui/pink_hearts.png");
- public static final ResourceLocation PURPLE_HEARTS = new ResourceLocation("xlifehealth:textures/gui/purple_hearts.png");
- public static final ResourceLocation YELLOW_HEARTS = new ResourceLocation("xlifehealth:textures/gui/yellow_hearts.png");
- public static final ResourceLocation CYAN_HEARTS = new ResourceLocation("xlifehealth:textures/gui/cyan_hearts.png");
- public static final ResourceLocation MAGENTA_HEARTS = new ResourceLocation("xlifehealth:textures/gui/magenta_hearts.png");
- public static final ResourceLocation BLACK_HEARTS = new ResourceLocation("xlifehealth:textures/gui/black_hearts.png");
- @SubscribeEvent
- public void setHeartColors(RenderGameOverlayEvent.Pre evt) {
- if (evt.getType().equals(RenderGameOverlayEvent.ElementType.HEALTH)) {
- evt.setCanceled(true);
- Minecraft mc = Minecraft.getInstance();
- mc.getTextureManager().bindTexture(BLUE_HEARTS);
- mc.getTextureManager().bindTexture(GREEN_HEARTS);
- mc.getTextureManager().bindTexture(ORANGE_HEARTS);
- mc.getTextureManager().bindTexture(PINK_HEARTS);
- mc.getTextureManager().bindTexture(PURPLE_HEARTS);
- mc.getTextureManager().bindTexture(YELLOW_HEARTS);
- mc.getTextureManager().bindTexture(CYAN_HEARTS);
- mc.getTextureManager().bindTexture(MAGENTA_HEARTS);
- mc.getTextureManager().bindTexture(BLACK_HEARTS);
- }
- }
- public void setBlueHearts() {
- Minecraft mc = Minecraft.getInstance();
- mc.getTextureManager().bindTexture(BLUE_HEARTS);
- bind(BLUE_HEARTS);
- }
- public void setGreenHearts() {
- Minecraft mc = Minecraft.getInstance();
- mc.getTextureManager().bindTexture(GREEN_HEARTS);
- bind(GREEN_HEARTS);
- }
- public void setOrangeHearts() {
- Minecraft mc = Minecraft.getInstance();
- mc.getTextureManager().bindTexture(ORANGE_HEARTS);
- bind(ORANGE_HEARTS);
- }
- public void setPinkHearts() {
- Minecraft mc = Minecraft.getInstance();
- mc.getTextureManager().bindTexture(PINK_HEARTS);
- bind(PINK_HEARTS);
- }
- public void setPurpleHearts() {
- Minecraft mc = Minecraft.getInstance();
- mc.getTextureManager().bindTexture(PURPLE_HEARTS);
- bind(PURPLE_HEARTS);
- }
- public void setYellowHearts() {
- Minecraft mc = Minecraft.getInstance();
- mc.getTextureManager().bindTexture(YELLOW_HEARTS);
- bind(YELLOW_HEARTS);
- }
- public void setCyanHearts() {
- Minecraft mc = Minecraft.getInstance();
- mc.getTextureManager().bindTexture(CYAN_HEARTS);
- bind(CYAN_HEARTS);
- }
- public void setMagentaHearts() {
- Minecraft mc = Minecraft.getInstance();
- mc.getTextureManager().bindTexture(MAGENTA_HEARTS);
- bind(MAGENTA_HEARTS);
- }
- public void setBlackHearts() {
- Minecraft mc = Minecraft.getInstance();
- mc.getTextureManager().bindTexture(BLACK_HEARTS);
- bind(BLACK_HEARTS);
- }
- private static void bind(ResourceLocation res) {
- Minecraft mc = Minecraft.getInstance();
- mc.getTextureManager().bindTexture(res);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement