Implement translations, datagen, added moonseyetome and other changes
This commit is contained in:
@@ -3,6 +3,7 @@ package net.fretux.ascend;
|
||||
import net.fretux.ascend.command.AscendCommand;
|
||||
import net.fretux.ascend.config.AscendConfig;
|
||||
import net.fretux.ascend.network.PacketHandler;
|
||||
import net.fretux.ascend.registry.ModItems;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
@@ -22,6 +23,7 @@ public class AscendMod {
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
System.out.println("[Ascend] Mod loaded! Side=" + FMLEnvironment.dist);
|
||||
net.minecraftforge.fml.ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, AscendConfig.COMMON_SPEC);
|
||||
ModItems.register(modBus);
|
||||
}
|
||||
|
||||
private void onCommonSetup(final FMLCommonSetupEvent event) {
|
||||
|
||||
@@ -34,8 +34,6 @@ public class StatsScreen extends Screen {
|
||||
"willpower", "charisma",
|
||||
"light_scaling", "medium_scaling", "heavy_scaling", "magic_scaling"
|
||||
};
|
||||
|
||||
// Use translation keys for attribute labels and tooltips
|
||||
private static final Map<String, Component> ATTRIBUTE_TOOLTIPS = new HashMap<>();
|
||||
|
||||
static {
|
||||
@@ -49,10 +47,8 @@ public class StatsScreen extends Screen {
|
||||
super.init();
|
||||
this.leftPos = (this.width - WIDTH) / 2;
|
||||
this.topPos = (this.height - HEIGHT) / 2;
|
||||
|
||||
this.plusButtons.clear();
|
||||
this.clearWidgets();
|
||||
|
||||
int y = topPos + 55;
|
||||
for (String attr : ATTRIBUTES) {
|
||||
final String key = attr;
|
||||
@@ -65,7 +61,6 @@ public class StatsScreen extends Screen {
|
||||
this.plusButtons.put(key, plus);
|
||||
y += 16;
|
||||
}
|
||||
|
||||
Button done = Button.builder(Component.translatable("gui.done"), (btn) -> onClose())
|
||||
.bounds(leftPos + WIDTH / 2 - 40, topPos + HEIGHT - 24, 80, 20)
|
||||
.build();
|
||||
@@ -79,7 +74,6 @@ public class StatsScreen extends Screen {
|
||||
gui.fill(leftPos - 4, topPos - 4, leftPos + WIDTH + 4, topPos + HEIGHT + 4, 0xAA000000);
|
||||
RenderSystem.disableBlend();
|
||||
gui.drawCenteredString(this.font, Component.translatable("ascend.stats.title"), this.width / 2, topPos + 8, 0xFFFFFF);
|
||||
|
||||
hoveredAttributeKey = null;
|
||||
if (mc.player != null) {
|
||||
mc.player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
|
||||
@@ -87,7 +81,6 @@ public class StatsScreen extends Screen {
|
||||
int xp = stats.getAscendXP();
|
||||
int xpNext = stats.getXPToNextAscendLevel();
|
||||
int unspent = stats.getUnspentPoints();
|
||||
|
||||
gui.drawString(font, Component.translatable("ascend.stats.level", level, 20), leftPos + 10, topPos + 24, 0xFFFF55);
|
||||
if (level < 20) {
|
||||
gui.drawString(font, Component.translatable("ascend.stats.xp", xp, xpNext), leftPos + 10, topPos + 36, 0xAAAAAA);
|
||||
@@ -96,7 +89,6 @@ public class StatsScreen extends Screen {
|
||||
}
|
||||
gui.drawString(font, Component.translatable("ascend.stats.unspent", unspent),
|
||||
leftPos + WIDTH - 10 - font.width("Unspent Points: " + unspent), topPos + 24, 0x55FF55);
|
||||
|
||||
int y = topPos + 55;
|
||||
for (String key : ATTRIBUTES) {
|
||||
int attrLevel = stats.getAttributeLevel(key);
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package net.fretux.ascend.datagen;
|
||||
|
||||
import net.fretux.ascend.AscendMod;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.data.event.GatherDataEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = AscendMod.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public class AscendDataGenerators {
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@SubscribeEvent
|
||||
public static void gatherData(GatherDataEvent event) {
|
||||
var generator = event.getGenerator();
|
||||
ExistingFileHelper existingFileHelper = event.getExistingFileHelper();
|
||||
|
||||
if (event.includeClient()) {
|
||||
generator.addProvider(true, new AscendItemModelProvider(generator.getPackOutput(), existingFileHelper));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.fretux.ascend.datagen;
|
||||
|
||||
import net.fretux.ascend.AscendMod;
|
||||
import net.fretux.ascend.registry.ModItems;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraftforge.client.model.generators.ItemModelProvider;
|
||||
import net.minecraftforge.client.model.generators.ModelFile;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AscendItemModelProvider extends ItemModelProvider {
|
||||
|
||||
public AscendItemModelProvider(PackOutput output, ExistingFileHelper existingFileHelper) {
|
||||
super(output, AscendMod.MODID, existingFileHelper);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerModels() {
|
||||
assert ModItems.MOONSEYE_TOME.getId() != null;
|
||||
basicItem(ModItems.MOONSEYE_TOME.getId().getPath());
|
||||
}
|
||||
|
||||
private void basicItem(String name) {
|
||||
getBuilder(name)
|
||||
.parent(new ModelFile.UncheckedModelFile("item/generated"))
|
||||
.texture("layer0", AscendMod.MODID + ":item/" + name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getName() {
|
||||
return "Ascend Item Models";
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,10 @@ public class ActivityEvents {
|
||||
if (event.getSource().getEntity() instanceof Player player && !player.level().isClientSide) {
|
||||
player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
|
||||
stats.addAscendXP((int) (AscendConfig.COMMON.xpPerMobKill.get() * AscendConfig.COMMON.xpMultiplier.get()));
|
||||
LivingEntity mob = event.getEntity();
|
||||
if (mob.getMaxHealth() > 100f || mob.getType().toString().toLowerCase().contains("boss")) {
|
||||
stats.addKnowledge(2);
|
||||
}
|
||||
PlayerStatsProvider.sync(player);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package net.fretux.ascend.item;
|
||||
|
||||
import net.fretux.ascend.player.PlayerStatsProvider;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
public class MoonseyeTome extends Item {
|
||||
public MoonseyeTome(Properties properties) {
|
||||
super(properties.stacksTo(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
|
||||
ItemStack stack = player.getItemInHand(hand);
|
||||
if (level.isClientSide) return InteractionResultHolder.success(stack);
|
||||
player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
|
||||
int gained;
|
||||
if (!stats.hasUsedMoonseye()) {
|
||||
gained = 100;
|
||||
stats.setHasUsedMoonseye(true);
|
||||
} else {
|
||||
gained = 50;
|
||||
}
|
||||
stats.addKnowledge(gained);
|
||||
player.sendSystemMessage(net.minecraft.network.chat.Component.translatable("item.ascend.moonseye_tome.used", gained));
|
||||
player.playSound(SoundEvents.ENCHANTMENT_TABLE_USE, 1.0f, 1.2f);
|
||||
stack.shrink(1);
|
||||
PlayerStatsProvider.sync(player);
|
||||
});
|
||||
return InteractionResultHolder.consume(stack);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ public class PlayerStats {
|
||||
ascendXP -= xpNeeded;
|
||||
ascendLevel++;
|
||||
unspentPoints += POINTS_PER_LEVEL;
|
||||
knowledge += 1;
|
||||
}
|
||||
if (ascendLevel >= MAX_ASCEND_LEVEL) {
|
||||
int xpNeeded = getXPToNextAscendLevel();
|
||||
@@ -97,11 +98,33 @@ public class PlayerStats {
|
||||
return base + intelligence * perPoint;
|
||||
}
|
||||
|
||||
private int knowledge = 0;
|
||||
private boolean hasUsedMoonseye = false; // Moonseye Tome First Use
|
||||
|
||||
public int getKnowledge() {
|
||||
return knowledge;
|
||||
}
|
||||
|
||||
public void addKnowledge(int amount) {
|
||||
knowledge = Math.max(0, knowledge + amount);
|
||||
}
|
||||
|
||||
public boolean hasUsedMoonseye() {
|
||||
return hasUsedMoonseye;
|
||||
}
|
||||
|
||||
public void setHasUsedMoonseye(boolean used) {
|
||||
this.hasUsedMoonseye = used;
|
||||
}
|
||||
|
||||
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putInt("AscendLevel", ascendLevel);
|
||||
tag.putInt("AscendXP", ascendXP);
|
||||
tag.putInt("UnspentPoints", unspentPoints);
|
||||
tag.putInt("Knowledge", knowledge);
|
||||
tag.putBoolean("HasUsedMoonseye", hasUsedMoonseye);
|
||||
CompoundTag attrTag = new CompoundTag();
|
||||
for (Map.Entry<String, Integer> entry : attributes.entrySet()) {
|
||||
attrTag.putInt(entry.getKey(), entry.getValue());
|
||||
@@ -125,5 +148,11 @@ public class PlayerStats {
|
||||
attributes.put(key, Math.max(0, Math.min(loaded, MAX_ATTRIBUTE_POINTS)));
|
||||
}
|
||||
}
|
||||
if (tag.contains("Knowledge")) {
|
||||
knowledge = tag.getInt("Knowledge");
|
||||
}
|
||||
if (tag.contains("HasUsedMoonseye")) {
|
||||
hasUsedMoonseye = tag.getBoolean("HasUsedMoonseye");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.fretux.ascend.registry;
|
||||
|
||||
import net.fretux.ascend.AscendMod;
|
||||
import net.fretux.ascend.item.MoonseyeTome;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Rarity;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
public class ModItems {
|
||||
public static final DeferredRegister<Item> ITEMS =
|
||||
DeferredRegister.create(ForgeRegistries.ITEMS, AscendMod.MODID);
|
||||
public static final DeferredRegister<CreativeModeTab> TABS =
|
||||
DeferredRegister.create(Registries.CREATIVE_MODE_TAB, AscendMod.MODID);
|
||||
public static final RegistryObject<Item> MOONSEYE_TOME = ITEMS.register(
|
||||
"moonseye_tome",
|
||||
() -> new MoonseyeTome(new Item.Properties()
|
||||
.stacksTo(1)
|
||||
.rarity(Rarity.RARE))
|
||||
);
|
||||
public static final RegistryObject<CreativeModeTab> ASCEND_TAB = TABS.register("ascend_tab",
|
||||
() -> CreativeModeTab.builder()
|
||||
.title(Component.translatable("itemGroup.ascend"))
|
||||
.icon(() -> new ItemStack(MOONSEYE_TOME.get()))
|
||||
.displayItems((params, output) -> {
|
||||
output.accept(MOONSEYE_TOME.get());
|
||||
})
|
||||
.build()
|
||||
);
|
||||
|
||||
public static void register(IEventBus eventBus) {
|
||||
ITEMS.register(eventBus);
|
||||
TABS.register(eventBus);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user