1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
package dev.mayaqq.ygasi.gui.common;
import dev.mayaqq.ygasi.gui.BranchGui;
import dev.mayaqq.ygasi.util.AdvUtils;
import eu.pb4.sgui.api.elements.GuiElementBuilder;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
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;
import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS;
public class GuiCommon {
public static void setDoneItem(SkillGui gui, int index, Item item, String nameKey, Boolean glow) {
GuiElementBuilder builder = new GuiElementBuilder();
builder.setItem(item);
builder.hideFlag(ItemStack.TooltipSection.MODIFIERS);
builder.setName(Text.translatable(nameKey));
if (glow) {
builder.glow();
}
builder.addLoreLine(Text.translatable(nameKey + ".lore"));
gui.setSlot(index, builder.build());
}
public static void filler(SkillGui gui, int index, Boolean done) {
if (done) {
gui.setSlot(index, new GuiElementBuilder()
.setItem(Items.LIME_STAINED_GLASS_PANE)
.setName(Text.of(" "))
);
} else {
gui.setSlot(index, new GuiElementBuilder()
.setItem(Items.RED_STAINED_GLASS_PANE)
.setName(Text.of(" "))
);
}
}
public static void setSkillSlot(SkillGui gui, ServerPlayerEntity player, int itemIndex, Item item, String nameKey, int cost, Class<?> skillClass, Class<?> guiClass) {
String advName = nameKey.split("\\.")[3];
gui.setSlot(itemIndex, new GuiElementBuilder()
.setItem(item)
.hideFlag(ItemStack.TooltipSection.MODIFIERS)
.setName(Text.translatable(nameKey))
.addLoreLine(Text.translatable(nameKey + ".lore"))
.addLoreLine(Text.translatable("gui.ygasi.branch.cost", Text.of("§8" + cost)))
.setCallback((index, clickType, actionType) -> {
if (player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)) >= cost) {
try {
if (AdvUtils.hasBeforeAdvancements(player, "minecraft", "ygasi/"+ advName)) {
skillClass.getMethod("give", ServerPlayerEntity.class).invoke(null, player);
player.getStatHandler().setStat(player, Stats.CUSTOM.getOrCreateStat(SKILL_POINTS), player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)) - cost);
guiClass.getMethod("gui", ServerPlayerEntity.class).invoke(null, player);
player.playSound(SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE, SoundCategory.PLAYERS, 1.0F, 1.0F);
} else {
player.playSound(SoundEvents.BLOCK_ANVIL_BREAK, SoundCategory.PLAYERS, 1.0F, 1.0F);
player.sendMessage(Text.translatable("gui.ygasi.branches.no.previous"), true);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
player.sendMessage(Text.translatable("gui.ygasi.branches.no.skill"), false);
}
}
));
}
public static void background(SkillGui gui) {
for (int x = 0; x <= 53; x++) {
gui.setSlot(x, new GuiElementBuilder()
.setItem(Items.GRAY_STAINED_GLASS_PANE)
.setName(Text.of(" "))
);
}
for (int i = 48; i <= 50; i++) {
gui.setSlot(i, new GuiElementBuilder()
.setItem(Items.LIME_STAINED_GLASS_PANE)
.setName(Text.of(" "))
);
}
gui.setSlot(45, new GuiElementBuilder()
.setItem(Items.ARROW)
.setName(Text.translatable("gui.ygasi.branches.back"))
.setCallback((index, clickType, actionType) -> {
BranchGui.gui(gui.getPlayer());
})
);
}
}
|