aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/dev
diff options
context:
space:
mode:
authorMaximusbarcz <maxim.baranek@gmail.com>2022-12-24 14:00:57 +0100
committerMaximusbarcz <maxim.baranek@gmail.com>2022-12-24 14:00:57 +0100
commitb1d919ad2ebf0b176953d57edef8e75835c633e3 (patch)
treef3f754a46d475493711bab31310cd36344b312bd /src/main/java/dev
parentf7ca47ba8132addd94928aa8615448c47a6b3d7b (diff)
downloadygasi-b1d919ad2ebf0b176953d57edef8e75835c633e3.tar.gz
ygasi-b1d919ad2ebf0b176953d57edef8e75835c633e3.tar.bz2
ygasi-b1d919ad2ebf0b176953d57edef8e75835c633e3.zip
Last christmas I gave you my commit
But the very next day you pushed it This year, to save me from conflicts I'll give it to github directly
Diffstat (limited to 'src/main/java/dev')
-rw-r--r--src/main/java/dev/mayaqq/ygasi/Ygasi.java13
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java36
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java3
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java5
-rw-r--r--src/main/java/dev/mayaqq/ygasi/items/SkillBookItem.java1
-rw-r--r--src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java12
-rw-r--r--src/main/java/dev/mayaqq/ygasi/registry/dataGen/DataGenRegistry.java (renamed from src/main/java/dev/mayaqq/ygasi/registry/advancements/dataGen/DataGenRegistry.java)5
-rw-r--r--src/main/java/dev/mayaqq/ygasi/registry/dataGen/advancements/AdvancementProvider.java (renamed from src/main/java/dev/mayaqq/ygasi/registry/advancements/dataGen/AdvancementProvider.java)6
-rw-r--r--src/main/java/dev/mayaqq/ygasi/registry/dataGen/advancements/Advancements.java (renamed from src/main/java/dev/mayaqq/ygasi/registry/advancements/Advancements.java)7
-rw-r--r--src/main/java/dev/mayaqq/ygasi/registry/dataGen/recipes/YgasiRecipes.java28
10 files changed, 74 insertions, 42 deletions
diff --git a/src/main/java/dev/mayaqq/ygasi/Ygasi.java b/src/main/java/dev/mayaqq/ygasi/Ygasi.java
index ebfec85..4d13d53 100644
--- a/src/main/java/dev/mayaqq/ygasi/Ygasi.java
+++ b/src/main/java/dev/mayaqq/ygasi/Ygasi.java
@@ -4,15 +4,16 @@ import dev.mayaqq.ygasi.items.SkillBookItem;
import dev.mayaqq.ygasi.registry.CommandRegistry;
import dev.mayaqq.ygasi.registry.ConfigRegistry;
import dev.mayaqq.ygasi.registry.StatRegistry;
+import dev.mayaqq.ygasi.util.GrantAdvancementCriterion;
+import eu.pb4.polymer.api.item.PolymerItemGroup;
import eu.pb4.polymer.api.resourcepack.PolymerModelData;
import eu.pb4.polymer.api.resourcepack.PolymerRPUtils;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
-import net.fabricmc.fabric.impl.resource.loader.ModResourcePackUtil;
import net.minecraft.item.Item;
-import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
+import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import org.slf4j.Logger;
@@ -21,25 +22,29 @@ import org.slf4j.LoggerFactory;
public class Ygasi implements ModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("ygasi");
- public static final SkillBookItem SKILL_BOOK = new SkillBookItem(new Item.Settings().group(ItemGroup.MISC).maxCount(1), Items.BOOK);
+ public static final PolymerItemGroup YGASI_GROUP = PolymerItemGroup.create(new Identifier("ygasi"), Text.translatable("creative.ygasi.group"), () -> new ItemStack(Items.BOOK));
+
+ public static final SkillBookItem SKILL_BOOK = new SkillBookItem(new Item.Settings().group(YGASI_GROUP).maxCount(1), Items.BOOK);
@Override
public void onInitialize() {
StatRegistry.skillRegister();
CommandRegistry.RegisterCommands();
ConfigRegistry.load();
- LOGGER.info("You've got a skill issue!");
PolymerRPUtils.addAssetSource("ygasi");
PolymerModelData modelData = PolymerRPUtils.requestModel(Items.BOOK, new Identifier("ygasi", "item/skill_book"));
Registry.register(Registry.ITEM, "ygasi:skill_book", SKILL_BOOK);
+ LOGGER.info("You've got a skill issue!");
+
if (ConfigRegistry.CONFIG.enableSkillBook) {
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
if (!handler.player.getScoreboardTags().contains("ygasi:skill_book_unlocked")) {
handler.player.addScoreboardTag("ygasi:skill_book_unlocked");
handler.player.getInventory().offerOrDrop(new ItemStack(SKILL_BOOK));
+ GrantAdvancementCriterion.grantAdvancementCriterion(handler.player, new Identifier("ygasi", "skill_book"), "opened_skill_menu");
}
});
}
diff --git a/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java b/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java
index 535d37e..ca02eec 100644
--- a/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java
+++ b/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java
@@ -3,14 +3,11 @@ package dev.mayaqq.ygasi.gui;
import dev.mayaqq.ygasi.util.GetAdvancementProgress;
import dev.mayaqq.ygasi.util.GrantAdvancementCriterion;
import eu.pb4.sgui.api.elements.*;
-import eu.pb4.sgui.api.gui.SimpleGui;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity;
-import net.minecraft.sound.SoundCategory;
-import net.minecraft.sound.SoundEvents;
import net.minecraft.stat.Stats;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
@@ -23,37 +20,40 @@ import net.minecraft.util.Identifier;
public class BranchGui {
public static void gui(ServerPlayerEntity player) {
+ int skillPoints = player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS));
+
try {
SkillGui gui = new SkillGui(ScreenHandlerType.GENERIC_9X3, player, false) {};
- gui.setTitle(Text.of("§3Skill Points: " + player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS))));
+ gui.setTitle(Text.of("§3Skill Points: " + skillPoints));
//background items
- for (int x = 0; x <= 17; x++) {
+ for (int x = 0; x <= 26; x++) {
gui.setSlot(x, new GuiElementBuilder()
.setItem(Items.GRAY_STAINED_GLASS_PANE)
.setName(Text.of(" "))
);
}
- for (int x = 18; x <= 26; x++) {
+ for (int x = 10; x <= 16; x++) {
gui.setSlot(x, new GuiElementBuilder()
- .setItem(Items.RED_STAINED_GLASS_PANE)
+ .setItem(Items.LIGHT_BLUE_STAINED_GLASS_PANE)
.setName(Text.of(" "))
);
}
-
- //close button
- gui.setSlot(22, new GuiElementBuilder()
- .setItem(Items.BARRIER)
- .setName(Text.literal("Close")
- .setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.DARK_RED)))
- .setCallback((index, clickType, actionType) -> close(player))
- );
+ for (int x = 0; x <= 2; x++) {
+ for (int y = 2; y <= 6; y+=2) {
+ gui.setSlot(x * 9 + y, new GuiElementBuilder()
+ .setItem(Items.LIGHT_BLUE_STAINED_GLASS_PANE)
+ .setName(Text.of(" "))
+ );
+ }
+ }
//branch items
if (!GetAdvancementProgress.get(player, "mercenary")) {
gui.setSlot(11, new GuiElementBuilder()
.setItem(Items.IRON_SWORD)
+ .setCustomModelData(1)
.hideFlag(ItemStack.TooltipSection.MODIFIERS)
.addLoreLine(Text.literal("Cost: " + ConfigRegistry.CONFIG.branchCost).setStyle(Style.EMPTY.withFormatting(Formatting.DARK_GRAY)))
.setName(Text.literal("Mercenary")
@@ -130,12 +130,8 @@ public class BranchGui {
}
} else {
- player.sendMessage(Text.literal("You don't have enough skill points to unlock this branch!").setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.RED)), false);
+ player.sendMessage(Text.translatable("gui.ygasi.no.skill").setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.RED)), false);
player.closeHandledScreen();
}
}
- public static void close(ServerPlayerEntity player) {
- player.playSound(SoundEvents.ITEM_BOOK_PAGE_TURN, SoundCategory.PLAYERS, 1.0F, 1.0F);
- player.closeHandledScreen();
- }
} \ No newline at end of file
diff --git a/src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java b/src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java
index 2b865f2..d2be67e 100644
--- a/src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java
+++ b/src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java
@@ -2,12 +2,9 @@ package dev.mayaqq.ygasi.gui;
import dev.mayaqq.ygasi.util.GetAdvancementProgress;
import eu.pb4.sgui.api.elements.GuiElementBuilder;
-import eu.pb4.sgui.api.gui.SimpleGui;
import net.minecraft.item.Items;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity;
-import net.minecraft.sound.SoundCategory;
-import net.minecraft.sound.SoundEvents;
import net.minecraft.stat.Stats;
import net.minecraft.text.Text;
diff --git a/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java b/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java
index c3e89b1..ea75c43 100644
--- a/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java
+++ b/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java
@@ -2,12 +2,9 @@ package dev.mayaqq.ygasi.gui;
import dev.mayaqq.ygasi.util.GetAdvancementProgress;
import eu.pb4.sgui.api.elements.GuiElementBuilder;
-import eu.pb4.sgui.api.gui.SimpleGui;
import net.minecraft.item.Items;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity;
-import net.minecraft.sound.SoundCategory;
-import net.minecraft.sound.SoundEvents;
import net.minecraft.stat.Stats;
import net.minecraft.text.Text;
@@ -30,6 +27,8 @@ public class MercenaryGui {
.setName(Text.of(" "))
);
}
+
+
gui.open();
}
} catch (Exception e) {
diff --git a/src/main/java/dev/mayaqq/ygasi/items/SkillBookItem.java b/src/main/java/dev/mayaqq/ygasi/items/SkillBookItem.java
index ce4143f..c96de2a 100644
--- a/src/main/java/dev/mayaqq/ygasi/items/SkillBookItem.java
+++ b/src/main/java/dev/mayaqq/ygasi/items/SkillBookItem.java
@@ -29,7 +29,6 @@ public class SkillBookItem extends SimplePolymerItem {
public ItemStack getPolymerItemStack(ItemStack itemStack, ServerPlayerEntity player) {
ItemStack out = PolymerItemUtils.createItemStack(itemStack, player);
out.addEnchantment(Enchantments.LURE, 0);
- out.setCustomName(Text.translatable("item.ygasi.skill_book").formatted(Formatting.GOLD).formatted(Formatting.BOLD));
return out;
}
diff --git a/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java b/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java
index a2c1330..58e8353 100644
--- a/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java
+++ b/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java
@@ -1,11 +1,7 @@
package dev.mayaqq.ygasi.mixin;
import dev.mayaqq.ygasi.registry.ConfigRegistry;
-import net.minecraft.advancement.Advancement;
-import net.minecraft.advancement.AdvancementDisplay;
-import net.minecraft.advancement.AdvancementFrame;
import net.minecraft.advancement.AdvancementRewards;
-import net.minecraft.server.ServerAdvancementLoader;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Final;
@@ -20,12 +16,16 @@ import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS;
@Mixin(AdvancementRewards.class)
public class AdvancementRewardsMixin {
+
@Shadow @Final private Identifier[] recipes;
+ @Shadow @Final private int experience;
@Inject(method = "apply", at = @At("HEAD"))
- private void inject(ServerPlayerEntity player, CallbackInfo ci) {
- if (recipes.length == 0) {
+ private void apply(ServerPlayerEntity player, CallbackInfo ci) {
+ if (recipes.length == 0 && experience != 1) {
player.increaseStat(SKILL_POINTS, ConfigRegistry.CONFIG.pointsRewarded);
+ } else if (experience == 1) {
+ player.addExperience(-1);
}
}
}
diff --git a/src/main/java/dev/mayaqq/ygasi/registry/advancements/dataGen/DataGenRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/dataGen/DataGenRegistry.java
index 9bba67d..8cd9b6e 100644
--- a/src/main/java/dev/mayaqq/ygasi/registry/advancements/dataGen/DataGenRegistry.java
+++ b/src/main/java/dev/mayaqq/ygasi/registry/dataGen/DataGenRegistry.java
@@ -1,5 +1,7 @@
-package dev.mayaqq.ygasi.registry.advancements.dataGen;
+package dev.mayaqq.ygasi.registry.dataGen;
+import dev.mayaqq.ygasi.registry.dataGen.advancements.AdvancementProvider;
+import dev.mayaqq.ygasi.registry.dataGen.recipes.YgasiRecipes;
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
@@ -7,5 +9,6 @@ public class DataGenRegistry implements DataGeneratorEntrypoint {
@Override
public void onInitializeDataGenerator(FabricDataGenerator dataGenerator) {
dataGenerator.addProvider(AdvancementProvider::new);
+ dataGenerator.addProvider(YgasiRecipes::new);
}
}
diff --git a/src/main/java/dev/mayaqq/ygasi/registry/advancements/dataGen/AdvancementProvider.java b/src/main/java/dev/mayaqq/ygasi/registry/dataGen/advancements/AdvancementProvider.java
index a9b1a64..6a91296 100644
--- a/src/main/java/dev/mayaqq/ygasi/registry/advancements/dataGen/AdvancementProvider.java
+++ b/src/main/java/dev/mayaqq/ygasi/registry/dataGen/advancements/AdvancementProvider.java
@@ -1,6 +1,6 @@
-package dev.mayaqq.ygasi.registry.advancements.dataGen;
+package dev.mayaqq.ygasi.registry.dataGen.advancements;
-import dev.mayaqq.ygasi.registry.advancements.Advancements;
+import dev.mayaqq.ygasi.registry.dataGen.advancements.Advancements;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricAdvancementProvider;
import net.minecraft.advancement.Advancement;
@@ -8,7 +8,7 @@ import net.minecraft.advancement.Advancement;
import java.util.function.Consumer;
public class AdvancementProvider extends FabricAdvancementProvider {
- protected AdvancementProvider(FabricDataGenerator dataGenerator) {
+ public AdvancementProvider(FabricDataGenerator dataGenerator) {
super(dataGenerator);
}
@Override
diff --git a/src/main/java/dev/mayaqq/ygasi/registry/advancements/Advancements.java b/src/main/java/dev/mayaqq/ygasi/registry/dataGen/advancements/Advancements.java
index ac33abe..6cd5665 100644
--- a/src/main/java/dev/mayaqq/ygasi/registry/advancements/Advancements.java
+++ b/src/main/java/dev/mayaqq/ygasi/registry/dataGen/advancements/Advancements.java
@@ -1,8 +1,9 @@
-package dev.mayaqq.ygasi.registry.advancements;
+package dev.mayaqq.ygasi.registry.dataGen.advancements;
import de.dafuqs.revelationary.advancement_criteria.AdvancementGottenCriterion;
import net.minecraft.advancement.Advancement;
import net.minecraft.advancement.AdvancementFrame;
+import net.minecraft.advancement.AdvancementRewards;
import net.minecraft.advancement.criterion.ImpossibleCriterion;
import net.minecraft.item.Items;
import net.minecraft.predicate.entity.EntityPredicate;
@@ -28,6 +29,7 @@ public class Advancements implements Consumer<Consumer<Advancement>> {
)
// The first string used in criterion is the name referenced by other advancements when they want to have 'requirements'
.criterion("opened_skill_menu", new ImpossibleCriterion.Conditions())
+ .rewards(AdvancementRewards.Builder.experience(1))
.build(consumer, "ygasi" + "/root");
Advancement mercenary = Advancement.Builder.create().parent(rootAdvancement)
@@ -43,6 +45,7 @@ public class Advancements implements Consumer<Consumer<Advancement>> {
)
.criterion("unlocked_mercenary", new ImpossibleCriterion.Conditions())
.criterion("gotten_previous", new AdvancementGottenCriterion.Conditions(EntityPredicate.Extended.EMPTY, rootAdvancement.getId()))
+ .rewards(AdvancementRewards.Builder.experience(1))
.build(consumer, "ygasi" + "/mercenary");
Advancement wizardry = Advancement.Builder.create().parent(rootAdvancement)
.display(
@@ -57,6 +60,7 @@ public class Advancements implements Consumer<Consumer<Advancement>> {
)
.criterion("unlocked_wizardry", new ImpossibleCriterion.Conditions())
.criterion("gotten_previous", new AdvancementGottenCriterion.Conditions(EntityPredicate.Extended.EMPTY, rootAdvancement.getId()))
+ .rewards(AdvancementRewards.Builder.experience(1))
.build(consumer, "ygasi" + "/wizardry");
Advancement druidry = Advancement.Builder.create().parent(rootAdvancement)
.display(
@@ -71,6 +75,7 @@ public class Advancements implements Consumer<Consumer<Advancement>> {
)
.criterion("unlocked_druidry", new ImpossibleCriterion.Conditions())
.criterion("gotten_previous", new AdvancementGottenCriterion.Conditions(EntityPredicate.Extended.EMPTY, rootAdvancement.getId()))
+ .rewards(AdvancementRewards.Builder.experience(1))
.build(consumer, "ygasi" + "/druidry");
}
} \ No newline at end of file
diff --git a/src/main/java/dev/mayaqq/ygasi/registry/dataGen/recipes/YgasiRecipes.java b/src/main/java/dev/mayaqq/ygasi/registry/dataGen/recipes/YgasiRecipes.java
new file mode 100644
index 0000000..75afdfe
--- /dev/null
+++ b/src/main/java/dev/mayaqq/ygasi/registry/dataGen/recipes/YgasiRecipes.java
@@ -0,0 +1,28 @@
+package dev.mayaqq.ygasi.registry.dataGen.recipes;
+
+import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
+import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;
+import net.minecraft.advancement.criterion.ImpossibleCriterion;
+import net.minecraft.data.server.recipe.RecipeJsonProvider;
+import net.minecraft.data.server.recipe.ShapelessRecipeJsonBuilder;
+import net.minecraft.item.Items;
+import net.minecraft.tag.ItemTags;
+
+import java.util.function.Consumer;
+
+import static dev.mayaqq.ygasi.Ygasi.SKILL_BOOK;
+
+public class YgasiRecipes extends FabricRecipeProvider {
+ public YgasiRecipes(FabricDataGenerator dataGenerator) {
+ super(dataGenerator);
+ }
+
+ @Override
+ public void generateRecipes(Consumer<RecipeJsonProvider> exporter) {
+ ShapelessRecipeJsonBuilder.create(SKILL_BOOK)
+ .criterion("has_book", new ImpossibleCriterion.Conditions())
+ .input(Items.BOOK)
+ .input(ItemTags.SAPLINGS)
+ .offerTo(exporter);
+ }
+} \ No newline at end of file