Skip to content

Commit

Permalink
feat: add argument for aptitudes command, titles prefix, kubejs new e…
Browse files Browse the repository at this point in the history
…vent.

fix: scholar skill not disabling correctly, convergence item list performance issues.
  • Loading branch information
Senior-S committed Sep 16, 2024
1 parent b623673 commit a3b2543
Show file tree
Hide file tree
Showing 16 changed files with 179 additions and 12 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.2
1.1.3
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.2
mod_version=1.1.3
# 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 @@ -12,6 +12,7 @@
import com.seniors.justlevelingfork.network.ServerNetworking;
import com.seniors.justlevelingfork.registry.*;
import com.seniors.justlevelingfork.registry.aptitude.Aptitude;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraftforge.common.MinecraftForge;
Expand Down Expand Up @@ -50,6 +51,9 @@ public static Logger getLOGGER() {

public static MutablePair<Boolean, String> UpdatesAvailable = new MutablePair<>(false, "");

// Required for the titles prefix
public static MinecraftServer server;

public JustLevelingFork() {
IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
eventBus.addListener(this::attributeSetup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.seniors.justlevelingfork.handler.HandlerCommonConfig;
import com.seniors.justlevelingfork.handler.HandlerConfigClient;
import com.seniors.justlevelingfork.handler.HandlerResources;
import com.seniors.justlevelingfork.integration.KubeJSIntegration;
import com.seniors.justlevelingfork.network.packet.common.*;
import com.seniors.justlevelingfork.registry.RegistryAptitudes;
import com.seniors.justlevelingfork.registry.RegistryTitles;
Expand Down Expand Up @@ -449,7 +450,17 @@ public void drawSkills(GuiGraphics matrixStack, int x, int y, int mouseX, int mo
this.isMouseCheck = true;
if (this.checkMouse) {
Utils.playSound();
AptitudeLevelUpSP.send(aptitude);
if (KubeJSIntegration.isModLoaded()) {
boolean cancelled = KubeJSIntegration.postLevelUpEvent(client.player, aptitude);

if (!cancelled) {
AptitudeLevelUpSP.send(aptitude);
}
}
else {
AptitudeLevelUpSP.send(aptitude);
}

this.checkMouse = false;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
.then(Commands.literal("set")
.then(Commands.argument("level", IntegerArgumentType.integer(1, HandlerCommonConfig.HANDLER.instance().aptitudeMaxLevel))
.executes(source -> setAptitude(source, EntityArgument.getPlayer(source, "player"), source.getArgument("aptitude", String.class), IntegerArgumentType.getInteger(source, "level")))
))
)
.then(Commands.literal(("add")))
.then(Commands.argument("level", IntegerArgumentType.integer(1, HandlerCommonConfig.HANDLER.instance().aptitudeMaxLevel))
.executes(source -> addAptitude(source, EntityArgument.getPlayer(source, "player"), source.getArgument("aptitude", String.class), IntegerArgumentType.getInteger(source, "level"))))
)
)
)
);
Expand Down Expand Up @@ -66,6 +70,28 @@ public static int setAptitude(CommandContext<CommandSourceStack> source, ServerP

return 0;
}

public static int addAptitude(CommandContext<CommandSourceStack> source, ServerPlayer player, String aptitudeKey, int addLevel) {
Aptitude aptitude = RegistryAptitudes.getAptitude(aptitudeKey);

if (player != null && aptitude != null) {
AptitudeCapability capability = AptitudeCapability.get(player);
int actualLevel = capability.getAptitudeLevel(aptitude);

capability.setAptitudeLevel(aptitude,
(actualLevel + addLevel) > HandlerCommonConfig.HANDLER.instance().aptitudeMaxLevel
? HandlerCommonConfig.HANDLER.instance().aptitudeMaxLevel : (actualLevel + addLevel));

SyncAptitudeCapabilityCP.send(player);

source.getSource().sendSuccess(() -> Component.translatable("commands.message.aptitude.set", player.getName().copy().withStyle(ChatFormatting.BOLD), Component.literal(String.valueOf(capability.getAptitudeLevel(aptitude))).withStyle(ChatFormatting.BOLD), Component.translatable(aptitude.getKey()).withStyle(ChatFormatting.BOLD)), false);


return 1;
}

return 0;
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public class HandlerCommonConfig {
@Boolean(formatter = Boolean.Formatter.ON_OFF)
public boolean logSpellIds = false;

@SerialEntry(comment = "If true this will display the player titles as prefixes when a player chat.")
@AutoGen(category = "common", group = "general")
@Boolean(formatter = Boolean.Formatter.TRUE_FALSE)
public boolean displayTitlesAsPrefix = true;

// Passive options
@SerialEntry(comment = "Attack Damage passive value at max level")
@AutoGen(category = "common", group = "passives")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.seniors.justlevelingfork.integration;

import com.seniors.justlevelingfork.kubejs.events.CustomEvents;
import com.seniors.justlevelingfork.kubejs.events.LevelUpEvent;
import com.seniors.justlevelingfork.registry.aptitude.Aptitude;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.fml.ModList;

public class KubeJSIntegration {

public static boolean isModLoaded() {
return ModList.get().isLoaded("kubejs");
}

public static boolean postLevelUpEvent(Player player, Aptitude aptitude) {
LevelUpEvent event = new LevelUpEvent(player, aptitude);
CustomEvents.APTITUDE_LEVELUP.post(event);
return event.getCancelled();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
import net.minecraft.world.item.Tier;
import net.minecraftforge.common.ToolAction;
import se.mickelus.tetra.items.modular.ItemModularHandheld;
import se.mickelus.tetra.module.data.VariantData;
import se.mickelus.tetra.util.TierHelper;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;

public class TetraIntegration {
private static final String _prefix = "tetra*tier*";
public static final List<String> TetraItems = List.of("tetra:modular_double", "tetra:modular_sword");
public static final List<String> TetraItems = List.of("tetra:modular_double", "tetra:modular_single", "tetra:modular_sword", "tetra:modular_shield", "tetra:modular_bow", "tetra:modular_crossbow");

/**
* Get a list of formatted modules.
Expand All @@ -29,6 +31,7 @@ public static List<String> GetItemTypes(ItemStack item) {
for (int i = 0; i < toolActions.size(); i++) {
ToolAction action = toolActions.stream().toList().get(i);
String actionName = action.name();

Tier tier = TierHelper.getTier(modularHandheld.getHarvestTier(item, action));

if(tier == null){
Expand All @@ -53,7 +56,14 @@ public static List<String> GetItemTypes(ItemStack item) {
list.add(String.format("%shoe:%s", _prefix, tier.toString().toLowerCase()));
break;
case "cut":
list.add(String.format("%scut:%s", _prefix, tier.toString().toLowerCase()));
modularHandheld.getAllModules(item).stream().filter(c -> c.getKey().startsWith("sword/")).forEach(c -> {
VariantData variantData = c.getVariantData(item);
if (variantData != null && !Objects.equals(variantData.category, "misc")){
String material = variantData.key.split("/")[1];
list.add(String.format("%ssword:%s", _prefix, material.toLowerCase()));
}
});

break;
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/seniors/justlevelingfork/kubejs/Plugin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.seniors.justlevelingfork.kubejs;

import com.seniors.justlevelingfork.client.core.ValueType;
import com.seniors.justlevelingfork.kubejs.events.CustomEvents;
import com.seniors.justlevelingfork.registry.aptitude.Aptitude;
import dev.latvian.mods.kubejs.KubeJSPlugin;
import dev.latvian.mods.kubejs.script.BindingsEvent;

Expand All @@ -10,5 +12,11 @@ public class Plugin extends KubeJSPlugin {
public void registerBindings(BindingsEvent event) {
super.registerBindings(event);
event.add("ValueType", ValueType.class);
event.add("Aptitude", Aptitude.class);
}

@Override
public void registerEvents() {
CustomEvents.GROUP.register();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.seniors.justlevelingfork.kubejs.events;

import dev.latvian.mods.kubejs.event.EventGroup;
import dev.latvian.mods.kubejs.event.EventHandler;

public interface CustomEvents {
EventGroup GROUP = EventGroup.of("JLForkEvents");

EventHandler APTITUDE_LEVELUP = GROUP.client("aptitudeLevelUp", () -> LevelUpEvent.class);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.seniors.justlevelingfork.kubejs.events;

import com.seniors.justlevelingfork.registry.aptitude.Aptitude;
import dev.latvian.mods.kubejs.event.EventJS;
import net.minecraft.world.entity.player.Player;

public class LevelUpEvent extends EventJS {
private final Player player;
private final Aptitude aptitude;

private boolean cancelled = false;

public LevelUpEvent(Player player, Aptitude aptitude) {
this.player = player;
this.aptitude = aptitude;
}

public Player getPlayer() {
return player;
}

public Aptitude getAptitude(){
return aptitude;
}

public boolean getCancelled(){
return cancelled;
}

public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private static void appendEnchantmentNames(List<Component> list, ListTag tags, C
for (int i = 0; i < tags.size(); i++) {
CompoundTag nbt = tags.getCompound(i);

if (RegistrySkills.SCHOLAR != null && RegistrySkills.SCHOLAR.get().isEnabled()) {
if (RegistrySkills.SCHOLAR == null || (RegistrySkills.SCHOLAR.get().isEnabled())) {
ForgeRegistries.ENCHANTMENTS.getDelegate(EnchantmentHelper.getEnchantmentId(nbt)).ifPresent(enchantment -> list.add(enchantment.get().getFullname(EnchantmentHelper.getEnchantmentLevel(nbt))));
} else {
ForgeRegistries.ENCHANTMENTS.getDelegate(EnchantmentHelper.getEnchantmentId(nbt)).ifPresent(enchantment -> list.add(Component.translatable("tooltip.skill.scholar.lock_item").withStyle(ChatFormatting.GRAY)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class CommonConfigSyncCP {
private final int aptitudeFirstCostLevel;
private final boolean closeCraftingMenu;
private final boolean dropLockedItems;
private final boolean displayTitlesAsPrefix;

// Passive
private final float attackDamageValue;
Expand Down Expand Up @@ -79,6 +80,7 @@ public CommonConfigSyncCP() {
aptitudeFirstCostLevel = HandlerCommonConfig.HANDLER.instance().aptitudeFirstCostLevel;
closeCraftingMenu = HandlerCommonConfig.HANDLER.instance().closeCraftingMenu;
dropLockedItems = HandlerCommonConfig.HANDLER.instance().dropLockedItems;
displayTitlesAsPrefix = HandlerCommonConfig.HANDLER.instance().displayTitlesAsPrefix;
attackDamageValue = HandlerCommonConfig.HANDLER.instance().attackDamageValue;
attackKnockbackValue = HandlerCommonConfig.HANDLER.instance().attackKnockbackValue;
maxHealthValue = HandlerCommonConfig.HANDLER.instance().maxHealthValue;
Expand Down Expand Up @@ -131,6 +133,7 @@ public CommonConfigSyncCP(FriendlyByteBuf buffer) {
aptitudeFirstCostLevel = buffer.readInt();
closeCraftingMenu = buffer.readBoolean();
dropLockedItems = buffer.readBoolean();
displayTitlesAsPrefix = buffer.readBoolean();
attackDamageValue = buffer.readFloat();
attackKnockbackValue = buffer.readFloat();
maxHealthValue = buffer.readFloat();
Expand Down Expand Up @@ -207,6 +210,7 @@ public void toBytes(FriendlyByteBuf buffer) {
buffer.writeInt(this.aptitudeFirstCostLevel);
buffer.writeBoolean(this.closeCraftingMenu);
buffer.writeBoolean(this.dropLockedItems);
buffer.writeBoolean(this.displayTitlesAsPrefix);
buffer.writeFloat(this.attackDamageValue);
buffer.writeFloat(this.attackKnockbackValue);
buffer.writeFloat(this.maxHealthValue);
Expand Down Expand Up @@ -282,6 +286,7 @@ public void handle(Supplier<NetworkEvent.Context> supplier) {
HandlerCommonConfig.HANDLER.instance().aptitudeFirstCostLevel = this.aptitudeFirstCostLevel;
HandlerCommonConfig.HANDLER.instance().closeCraftingMenu = this.closeCraftingMenu;
HandlerCommonConfig.HANDLER.instance().dropLockedItems = this.dropLockedItems;
HandlerCommonConfig.HANDLER.instance().displayTitlesAsPrefix = displayTitlesAsPrefix;
HandlerCommonConfig.HANDLER.instance().attackDamageValue = this.attackDamageValue;
HandlerCommonConfig.HANDLER.instance().attackKnockbackValue = this.attackKnockbackValue;
HandlerCommonConfig.HANDLER.instance().maxHealthValue = this.maxHealthValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package com.seniors.justlevelingfork.registry;

import com.seniors.justlevelingfork.JustLevelingFork;
import com.seniors.justlevelingfork.client.core.Aptitudes;
import com.seniors.justlevelingfork.common.capability.AptitudeCapability;
import com.seniors.justlevelingfork.handler.HandlerAptitude;
import com.seniors.justlevelingfork.handler.HandlerCommonConfig;
import com.seniors.justlevelingfork.integration.TetraIntegration;
import com.seniors.justlevelingfork.registry.aptitude.Aptitude;
import com.seniors.justlevelingfork.registry.title.Title;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModList;
Expand All @@ -24,6 +29,24 @@
* registry CLIENT events into the forge mod bus.
*/
public class RegistryClientEvents {

@SubscribeEvent
public void onClientChatReceivedEvent(ClientChatReceivedEvent event){
if (HandlerCommonConfig.HANDLER.instance().displayTitlesAsPrefix) {
ServerPlayer serverPlayer = JustLevelingFork.server.getPlayerList().getPlayer(event.getSender());
if(serverPlayer == null) return;
AptitudeCapability capability = AptitudeCapability.get(serverPlayer);
if(capability == null) return;
Title titleKey = RegistryTitles.getTitle(capability.getPlayerTitle());
String title = (titleKey != null) ? Component.translatable(RegistryTitles.getTitle(AptitudeCapability.get().getPlayerTitle()).getKey()).getString() : "";

if(!title.isEmpty()){
String originalMessage = event.getMessage().getString();
event.setMessage(Component.literal(String.format("[%s] %s", title, originalMessage)));
}
}
}

@SubscribeEvent
public void onTooltipDisplay(ItemTooltipEvent event) {
if ((Minecraft.getInstance()).player != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public void onServerStarting(final ServerStartingEvent event) { // Let's migrate
HandlerCommonConfig.HANDLER.instance().usingNewConfig = true;
HandlerCommonConfig.HANDLER.save();
}

JustLevelingFork.server = event.getServer();
}

@SubscribeEvent
Expand Down Expand Up @@ -364,6 +366,10 @@ else if (!provider.canUseItem(player, item)) {
}
}

if(event.isCanceled()){
return;
}

if (RegistrySkills.LIMIT_BREAKER != null){
int random = (int) Math.floor(Math.random() * RegistrySkills.LIMIT_BREAKER.get().getValue()[0]);

Expand All @@ -378,6 +384,7 @@ else if (!provider.canUseItem(player, item)) {
}
}


player.getCapability(RegistryCapabilities.APTITUDE).ifPresent(capability -> {
AptitudeCapability aptitudeCapability = AptitudeCapability.get(player);
if (aptitudeCapability.getCounterAttack()) {
Expand Down
Loading

0 comments on commit a3b2543

Please sign in to comment.