Skip to content

Commit

Permalink
fix: bow accepting locked arrows, survivor title with wrong condition…
Browse files Browse the repository at this point in the history
…, crash caused by critical hits, curios keeping the effect. feat: option get aptitude level through KubeJs
  • Loading branch information
Senior-S committed Sep 7, 2024
1 parent 33f6750 commit b623673
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 35 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.1
1.1.2
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Component> tooltipList = new ArrayList();
List<Component> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
}
}
}
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down

0 comments on commit b623673

Please sign in to comment.