From b62367306d709c7ca3eb530e4fe1b2515fd0a1ae Mon Sep 17 00:00:00 2001 From: Senior-S Date: Sat, 7 Sep 2024 12:12:48 -0300 Subject: [PATCH] fix: bow accepting locked arrows, survivor title with wrong condition, crash caused by critical hits, curios keeping the effect. feat: option get aptitude level through KubeJs --- VERSION | 2 +- gradle.properties | 2 +- .../client/screen/JustLevelingScreen.java | 3 +- .../common/capability/AptitudeCapability.java | 4 ++ .../handler/HandlerCurios.java | 15 ++--- .../handler/HandlerTitlesConfig.java | 2 +- .../registry/RegistryCommonEvents.java | 57 ++++++++++++------- 7 files changed, 50 insertions(+), 35 deletions(-) diff --git a/VERSION b/VERSION index 8cfbc90..8428158 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.1 \ No newline at end of file +1.1.2 \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 9f55969..bbdfa5c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -47,7 +47,7 @@ mod_name=JustLevelingFork # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=APACHE # The mod version. See https://semver.org/ -mod_version=1.1.1 +mod_version=1.1.2 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/com/seniors/justlevelingfork/client/screen/JustLevelingScreen.java b/src/main/java/com/seniors/justlevelingfork/client/screen/JustLevelingScreen.java index ddf0382..b7a9721 100644 --- a/src/main/java/com/seniors/justlevelingfork/client/screen/JustLevelingScreen.java +++ b/src/main/java/com/seniors/justlevelingfork/client/screen/JustLevelingScreen.java @@ -61,7 +61,6 @@ public JustLevelingScreen() { super(Component.translatable("screen.aptitude.title")); } - protected void init() { int x = (this.width - 176) / 2; int y = (this.height - 166) / 2; @@ -203,7 +202,7 @@ public void drawTitles(GuiGraphics matrixStack, int x, int y, int mouseX, int mo matrixStack.blit(HandlerResources.SKILL_PAGE[1], x + 16, y + 144, 30, 167, 11, 11); if (Utils.checkMouse(x + 16, y + 144, mouseX, mouseY, 11, 11) && !this.scrollingDropDown) { matrixStack.blit(HandlerResources.SKILL_PAGE[1], x + 16, y + 144, 30, 179, 11, 11); - List tooltipList = new ArrayList(); + List tooltipList = new ArrayList<>(); tooltipList.add(Component.translatable("tooltip.sort.button.mod_names").withStyle(ChatFormatting.DARK_AQUA)); tooltipList.add(Component.translatable("tooltip.sort.button.true").withStyle((Boolean) HandlerConfigClient.showTitleModName.get() ? ChatFormatting.GREEN : ChatFormatting.DARK_GRAY)); tooltipList.add(Component.translatable("tooltip.sort.button.false").withStyle(!(Boolean) HandlerConfigClient.showTitleModName.get() ? ChatFormatting.GREEN : ChatFormatting.DARK_GRAY)); diff --git a/src/main/java/com/seniors/justlevelingfork/common/capability/AptitudeCapability.java b/src/main/java/com/seniors/justlevelingfork/common/capability/AptitudeCapability.java index fda1aa7..1306419 100644 --- a/src/main/java/com/seniors/justlevelingfork/common/capability/AptitudeCapability.java +++ b/src/main/java/com/seniors/justlevelingfork/common/capability/AptitudeCapability.java @@ -108,6 +108,10 @@ public int getAptitudeLevel(Aptitude aptitude) { return this.aptitudeLevel.get(aptitude.getName()); } + public int getAptitudeLevel(String aptitudeName) { + return this.aptitudeLevel.get(aptitudeName); + } + public void setAptitudeLevel(Aptitude aptitude, int lvl) { this.aptitudeLevel.put(aptitude.getName(), lvl); } diff --git a/src/main/java/com/seniors/justlevelingfork/handler/HandlerCurios.java b/src/main/java/com/seniors/justlevelingfork/handler/HandlerCurios.java index 4f6ca08..d5b1d0b 100644 --- a/src/main/java/com/seniors/justlevelingfork/handler/HandlerCurios.java +++ b/src/main/java/com/seniors/justlevelingfork/handler/HandlerCurios.java @@ -6,11 +6,12 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.GameType; import net.minecraftforge.event.entity.player.PlayerEvent; +import net.minecraftforge.eventbus.api.Event; import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.ModList; import top.theillusivec4.curios.api.CuriosApi; -import top.theillusivec4.curios.api.event.CurioChangeEvent; +import top.theillusivec4.curios.api.event.CurioEquipEvent; import top.theillusivec4.curios.api.type.inventory.IDynamicStackHandler; public class HandlerCurios { @@ -19,21 +20,15 @@ public static boolean isModLoaded() { } @SubscribeEvent(priority = EventPriority.HIGHEST) - public void onChangeCurio(CurioChangeEvent event) { + public void onCurioCanEquipEvent(CurioEquipEvent event){ LivingEntity livingEntity = event.getEntity(); if (livingEntity instanceof Player player) { if (!player.isCreative()) { - ItemStack item1 = event.getTo(); - ItemStack item2 = event.getFrom(); + ItemStack item1 = event.getStack(); AptitudeCapability aptitudeCapability = AptitudeCapability.get(player); if (!aptitudeCapability.canUseItem(player, item1)) { - player.drop(item1.copy(), false); - item1.setCount(0); - } - if (!aptitudeCapability.canUseItem(player, item2)) { - player.drop(item2.copy(), false); - item2.setCount(0); + event.setResult(Event.Result.DENY); } } } diff --git a/src/main/java/com/seniors/justlevelingfork/handler/HandlerTitlesConfig.java b/src/main/java/com/seniors/justlevelingfork/handler/HandlerTitlesConfig.java index 2b7f83d..afc24c9 100644 --- a/src/main/java/com/seniors/justlevelingfork/handler/HandlerTitlesConfig.java +++ b/src/main/java/com/seniors/justlevelingfork/handler/HandlerTitlesConfig.java @@ -54,7 +54,7 @@ public class HandlerTitlesConfig { new TitleModel("enchanter", List.of("stat/enchant_item/greater_or_equal/10"), false), new TitleModel("enchanter_great", List.of("stat/enchant_item/greater_or_equal/100"), false), new TitleModel("enchanter_master", List.of("stat/enchant_item/greater_or_equal/1000"), false), - new TitleModel("survivor", List.of("stat/time_since_death/greater_or_equal/100"), false), + new TitleModel("survivor", List.of("stat/time_since_death/greater_or_equal/2400000"), false), new TitleModel("businessman", List.of("stat/traded_with_villager/greater_or_equal/100"), false), new TitleModel("driver_boat", List.of("stat/boat_one_cm/greater_or_equal/1000000"), false), new TitleModel("driver_cart", List.of("stat/minecart_one_cm/greater_or_equal/1000000"), false), diff --git a/src/main/java/com/seniors/justlevelingfork/registry/RegistryCommonEvents.java b/src/main/java/com/seniors/justlevelingfork/registry/RegistryCommonEvents.java index af007bf..d9b57e3 100644 --- a/src/main/java/com/seniors/justlevelingfork/registry/RegistryCommonEvents.java +++ b/src/main/java/com/seniors/justlevelingfork/registry/RegistryCommonEvents.java @@ -42,10 +42,7 @@ import net.minecraftforge.event.entity.living.LivingDropsEvent; import net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; -import net.minecraftforge.event.entity.player.AttackEntityEvent; -import net.minecraftforge.event.entity.player.CriticalHitEvent; -import net.minecraftforge.event.entity.player.PlayerEvent; -import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import net.minecraftforge.event.entity.player.*; import net.minecraftforge.event.level.BlockEvent; import net.minecraftforge.event.server.ServerStartingEvent; import net.minecraftforge.eventbus.api.Event; @@ -419,25 +416,32 @@ public static void onPlayerCriticalHit(CriticalHitEvent event) { float attribute = (float) event.getEntity().getAttributeValue(RegistryAttributes.CRITICAL_DAMAGE.get()); event.setDamageModifier(damage + attribute); - if (RegistrySkills.BERSERKER != null & RegistrySkills.BERSERKER.get().isEnabled(player) && player.getHealth() <= player.getMaxHealth() * (float) (RegistrySkills.BERSERKER.get().getValue()[0] / 100.0D)) { - float newDamage = event.getDamageModifier(); - if (player.onGround() || player.isInWater()) { - event.setResult(Event.Result.ALLOW); - event.setDamageModifier(newDamage * 1.5F); + if (RegistrySkills.BERSERKER != null && RegistrySkills.BERSERKER.isPresent()){ + if (RegistrySkills.BERSERKER.get().isEnabled(player) && player.getHealth() <= player.getMaxHealth() * (float) (RegistrySkills.BERSERKER.get().getValue()[0] / 100.0D)) { + float newDamage = event.getDamageModifier(); + if (player.onGround() || player.isInWater()) { + event.setResult(Event.Result.ALLOW); + event.setDamageModifier(newDamage * 1.5F); + } } } if (player instanceof ServerPlayer serverPlayer) { - if (RegistrySkills.CRITICAL_ROLL != null && RegistrySkills.CRITICAL_ROLL.get().isEnabled(serverPlayer) && (event.isVanillaCritical() || (RegistrySkills.BERSERKER != null && RegistrySkills.BERSERKER.get().isEnabled(player) && player.getHealth() <= player.getMaxHealth() * (float) (RegistrySkills.BERSERKER.get().getValue()[0] / 100.0D)))) { - float newDamage = event.getDamageModifier(); - int dice = (int) Math.floor(Math.random() * 7.0D); - if (dice == 1) { - PlayerMessagesCP.send(serverPlayer, "overlay.skill.justlevelingfork.critical_roll_1", 0); - event.setDamageModifier(newDamage / (1.0F + 1.0F / (float) RegistrySkills.CRITICAL_ROLL.get().getValue()[1])); - } - if (dice == 6) { - PlayerMessagesCP.send(serverPlayer, "overlay.skill.justlevelingfork.critical_roll_6", 0); - event.setDamageModifier(newDamage * (float) RegistrySkills.CRITICAL_ROLL.get().getValue()[0]); + if(RegistrySkills.CRITICAL_ROLL != null && RegistrySkills.CRITICAL_ROLL.isPresent()){ + if(RegistrySkills.CRITICAL_ROLL.get().isEnabled(serverPlayer)){ + + if(event.isVanillaCritical() || (RegistrySkills.BERSERKER != null && RegistrySkills.BERSERKER.isPresent() && RegistrySkills.BERSERKER.get().isEnabled(player) && player.getHealth() <= player.getMaxHealth() * (float) (RegistrySkills.BERSERKER.get().getValue()[0] / 100.0D))){ + float newDamage = event.getDamageModifier(); + int dice = (int) Math.floor(Math.random() * 7.0D); + if (dice == 1) { + PlayerMessagesCP.send(serverPlayer, "overlay.skill.justlevelingfork.critical_roll_1", 0); + event.setDamageModifier(newDamage / (1.0F + 1.0F / (float) RegistrySkills.CRITICAL_ROLL.get().getValue()[1])); + } + if (dice == 6) { + PlayerMessagesCP.send(serverPlayer, "overlay.skill.justlevelingfork.critical_roll_6", 0); + event.setDamageModifier(newDamage * (float) RegistrySkills.CRITICAL_ROLL.get().getValue()[0]); + } + } } } } @@ -490,7 +494,7 @@ else if (!provider.canUseItem(player, item)) { public void onPlayerShootArrow(ProjectileImpactEvent event) { Projectile projectile = event.getProjectile(); if (projectile instanceof Arrow arrow) { - Entity entity = event.getProjectile().getOwner(); + Entity entity = projectile.getOwner(); if (entity instanceof Player player) { double baseDamage = arrow.getBaseDamage(); double arrowDamage = baseDamage + player.getAttributeValue(RegistryAttributes.PROJECTILE_DAMAGE.get()) / 5.0D; @@ -505,7 +509,20 @@ public void onPlayerShootArrow(ProjectileImpactEvent event) { (new RegistryEffects.addEffect(serverPlayer, (RegistrySkills.QUICK_REPOSITION != null && RegistrySkills.QUICK_REPOSITION.get().isEnabled(serverPlayer)), MobEffects.MOVEMENT_SPEED)).add((int) (10.0D + 20.0D * RegistrySkills.QUICK_REPOSITION.get().getValue()[1]), (int) (RegistrySkills.QUICK_REPOSITION.get().getValue()[0] - 1.0D)); } } + } + + @SubscribeEvent(priority = EventPriority.HIGHEST) + public void onArrowNockEvent(ArrowNockEvent event) { + Player player = event.getEntity(); + if(player == null){ + return; + } + ItemStack projectile = player.getProjectile(event.getBow()); + AptitudeCapability provider = AptitudeCapability.get(player); + if (!provider.canUseItem(player, projectile)) { + event.setCanceled(true); + } } @SubscribeEvent(priority = EventPriority.HIGHEST)