Skip to content

Commit f5c2d1e

Browse files
committed
1.2.5.1
1 parent 2cef535 commit f5c2d1e

12 files changed

Lines changed: 122 additions & 44 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ compileJava {
3030
sourceCompatibility = targetCompatibility = "1.8"
3131
}
3232

33-
version = "1.2.5"
33+
version = "1.2.5.1"
3434
group= "net.infstudio.gokistats" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
3535
archivesBaseName = "gokiStats"
3636

src/main/java/net/infstudio/goki/GokiStats.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public void preInit(FMLPreInitializationEvent event) {
7575
public void init(FMLInitializationEvent event) {
7676
packetPipeline.initialise();
7777
packetPipeline.registerPacket(PacketStatSync.class);
78-
packetPipeline.registerPacket(PacketStatAlter.class);
78+
packetPipeline.registerPacket(PacketStatAlter.Up.class);
79+
packetPipeline.registerPacket(PacketStatAlter.Down.class);
7980
packetPipeline.registerPacket(PacketSyncXP.class);
8081
packetPipeline.registerPacket(PacketSyncStatConfig.class);
8182

src/main/java/net/infstudio/goki/client/gui/GuiStatButton.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
import net.minecraft.client.Minecraft;
77
import net.minecraft.client.gui.FontRenderer;
88
import net.minecraft.client.gui.GuiButton;
9+
import net.minecraft.client.gui.GuiScreen;
910
import net.minecraft.entity.player.EntityPlayer;
1011
import org.lwjgl.opengl.GL11;
1112

13+
import javax.annotation.Nonnull;
14+
1215
public class GuiStatButton extends GuiButton {
1316
public StatBase stat;
1417
public EntityPlayer player;
@@ -20,40 +23,45 @@ public GuiStatButton(int id, int x, int y, int width, int height, StatBase stat,
2023
}
2124

2225
@Override
23-
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
26+
public void drawButton(@Nonnull Minecraft mc, int mouseX, int mouseY, float partialTicks) {
2427
if (this.visible) {
25-
int iconu = 0;
26-
int iconv = 24 * (this.stat.imageID % 10);
28+
int iconY = 24 * (this.stat.imageID % 10);
2729
int level = DataHelper.getPlayerStatLevel(this.player, this.stat);
2830
int cost = this.stat.getCost(level);
2931
int playerXP = DataHelper.getXPTotal(this.player);
30-
String message = level + "";
31-
int messageColor = 16777215;
3232

3333
FontRenderer fontrenderer = mc.fontRenderer;
3434
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
3535
this.hovered = isUnderMouse(mouseX, mouseY);
3636
int which = getHoverState(this.hovered);
3737

38+
int iconX = 0;
3839
if (which == 2) {
39-
iconu = 24;
40+
iconX = 24;
4041
}
4142
if (playerXP < cost) {
42-
iconu = 48;
43+
iconX = 48;
4344
}
4445
if (level >= this.stat.getLimit()) {
45-
iconu = 72;
46+
iconX = 72;
47+
}
48+
if (!DataHelper.canPlayerRevertStat(player, this.stat) && GuiScreen.isCtrlKeyDown()) {
49+
iconX = 48;
4650
}
51+
52+
String message = level + "";
4753
if (!this.stat.enabled) {
48-
iconu = 48;
54+
iconX = 48;
4955
message = "X";
5056
}
57+
58+
int messageColor = 16777215;
5159
if (level >= this.stat.getLimit()) {
5260
message = "*" + level + "*";
5361
messageColor = 16763904;
5462
}
5563

56-
iconu += this.stat.imageID % 20 / 10 * 24 * 4;
64+
iconX += this.stat.imageID % 20 / 10 * 24 * 4;
5765

5866
if (this.stat.imageID >= 20) {
5967
mc.getTextureManager().bindTexture(Reference.RPG_ICON_2_TEXTURE_LOCATION);
@@ -63,7 +71,7 @@ public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks)
6371
GL11.glPushMatrix();
6472
GL11.glTranslatef(this.x, this.y, 0.0F);
6573
GL11.glScalef(GuiStats.SCALE, GuiStats.SCALE, 0.0F);
66-
drawTexturedModalRect(0, 0, iconu, iconv, this.width, this.height);
74+
drawTexturedModalRect(0, 0, iconX, iconY, this.width, this.height);
6775

6876
GL11.glPopMatrix();
6977
GL11.glPushMatrix();

src/main/java/net/infstudio/goki/client/gui/GuiStatTooltip.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package net.infstudio.goki.client.gui;
22

3-
import net.infstudio.goki.common.utils.DataHelper;
3+
import net.infstudio.goki.common.config.GokiConfig;
44
import net.infstudio.goki.common.stats.StatBase;
5+
import net.infstudio.goki.common.utils.DataHelper;
56
import net.minecraft.client.Minecraft;
67
import net.minecraft.client.gui.Gui;
7-
import net.minecraft.entity.player.EntityPlayer;
8+
import net.minecraft.client.gui.GuiScreen;
89
import net.minecraft.client.resources.I18n;
10+
import net.minecraft.entity.player.EntityPlayer;
911

1012
import java.util.LinkedHashMap;
1113
import java.util.Map;
@@ -35,7 +37,18 @@ public void draw(int drawX, int drawY, int mouseButton) {
3537
messageColorMap.put(I18n.format("ui.max.name"), -16724737);
3638
else
3739
messageColorMap.put(I18n.format("ui.cost.name") + this.stat.getCost(level) + "xp", -16724737); // Cost
38-
messageColorMap.put(I18n.format("ui.hover.name"), 0xffffffff-0x98fb9800);
40+
41+
int revertLevel = DataHelper.getPlayerRevertStatLevel(player, stat);
42+
if (revertLevel > 0)
43+
messageColorMap.put(I18n.format("ui.reverted.name", revertLevel, GokiConfig.globalModifiers.globalMaxRevertLevel), -16724737); // Reverted
44+
45+
if (GuiScreen.isCtrlKeyDown()) { // Is player reverting?
46+
if (DataHelper.canPlayerRevertStat(player, stat))
47+
messageColorMap.put(I18n.format("ui.revert.name"), 0xff0467ff);
48+
else
49+
messageColorMap.put(I18n.format("ui.norevert.name"), 0xfffb1a00);
50+
} else
51+
messageColorMap.put(I18n.format("ui.hover.name"), 0xff0467ff);
3952

4053
messageColorMap.forEach((text, color) -> {
4154
widthAtomic.set(Math.max(widthAtomic.get(), this.mc.fontRenderer.getStringWidth(text)));

src/main/java/net/infstudio/goki/client/gui/GuiStats.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ protected void actionPerformed(GuiButton button) {
100100
if ((button instanceof GuiStatButton)) {
101101
GuiStatButton statButton = (GuiStatButton) button;
102102
if (!GuiScreen.isCtrlKeyDown())
103-
GokiStats.packetPipeline.sendToServer(new PacketStatAlter(StatBase.stats.indexOf(statButton.stat), 1));
103+
GokiStats.packetPipeline.sendToServer(new PacketStatAlter.Up(StatBase.stats.indexOf(statButton.stat), 1));
104104
else
105-
GokiStats.packetPipeline.sendToServer(new PacketStatAlter(StatBase.stats.indexOf(statButton.stat), -1));
105+
GokiStats.packetPipeline.sendToServer(new PacketStatAlter.Down(StatBase.stats.indexOf(statButton.stat), 1));
106106
}
107107
}
108108
}

src/main/java/net/infstudio/goki/common/config/GokiConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static class GlobalModifiers {
4141
public float loseStatsMultiplier = 1;
4242

4343
@Config.Name("Maximum revertable skill level")
44-
@Config.Comment("An integer that constrains the max number of level of the skill can be reverted. -1 for no limit.")
44+
@Config.Comment("An integer that constrains the max number of level of the skill can be reverted. -1 for no limit. 0 to disable reverting.")
4545
public int globalMaxRevertLevel = -1;
4646

4747
@Config.Name("Revert Factor")

src/main/java/net/infstudio/goki/common/handlers/CommonHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public void entityHurt(LivingHurtEvent event) {
293293
}
294294

295295
@SubscribeEvent
296-
public void configChanged(ConfigChangedEvent event) {
296+
public void configChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
297297
if (event.getModID().equals(Reference.MODID)) {
298298
ConfigManager.sync(Reference.MODID, Config.Type.INSTANCE);
299299
}

src/main/java/net/infstudio/goki/common/network/packet/PacketStatAlter.java

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
import io.netty.buffer.ByteBuf;
44
import io.netty.channel.ChannelHandlerContext;
55
import net.infstudio.goki.GokiStats;
6-
import net.infstudio.goki.common.utils.DataHelper;
76
import net.infstudio.goki.common.config.GokiConfig;
87
import net.infstudio.goki.common.stats.StatBase;
98
import net.infstudio.goki.common.stats.StatMaxHealth;
9+
import net.infstudio.goki.common.utils.DataHelper;
1010
import net.minecraft.entity.SharedMonsterAttributes;
1111
import net.minecraft.entity.player.EntityPlayer;
1212
import net.minecraft.entity.player.EntityPlayerMP;
1313

14+
import javax.annotation.Nonnegative;
15+
1416
public class PacketStatAlter implements GokiPacket {
15-
private int stat;
16-
private int amount;
17+
protected int stat;
18+
protected int amount;
1719

1820
public PacketStatAlter() {
1921
}
@@ -43,11 +45,23 @@ public void handleClientSide(EntityPlayer player) {
4345
public void handleServerSide(EntityPlayer player) {
4446
if (player == null)
4547
return;
46-
StatBase stat = StatBase.stats.get(this.stat);
47-
if (!stat.enabled)
48-
return;
49-
int level = DataHelper.getPlayerStatLevel(player, stat);
50-
if (this.amount > 0) {
48+
}
49+
50+
public static class Up extends PacketStatAlter {
51+
public Up() {
52+
}
53+
54+
public Up(int stat, @Nonnegative int amount) {
55+
super(stat, amount);
56+
}
57+
58+
@Override
59+
public void handleServerSide(EntityPlayer player) {
60+
super.handleServerSide(player);
61+
StatBase stat = StatBase.stats.get(this.stat);
62+
if (!stat.enabled)
63+
return;
64+
int level = DataHelper.getPlayerStatLevel(player, stat);
5165

5266
if (level + this.amount > stat.getLimit()) {
5367
this.amount = stat.getLimit() - level;
@@ -72,26 +86,44 @@ public void handleServerSide(EntityPlayer player) {
7286

7387
GokiStats.packetPipeline.sendTo(new PacketStatSync(player), (EntityPlayerMP) player);
7488
GokiStats.packetPipeline.sendTo(new PacketSyncXP(player), (EntityPlayerMP) player);
75-
} else if (DataHelper.getPlayerStatLevel(player, stat) > 0) {
89+
}
90+
}
91+
92+
public static class Down extends PacketStatAlter {
93+
public Down() {
94+
}
7695

77-
int reverted = DataHelper.getPlayerRevertStatLevel(player, stat);
78-
int maxRevert = GokiConfig.globalModifiers.globalMaxRevertLevel;
96+
public Down(int stat, @Nonnegative int amount) {
97+
super(stat, amount);
98+
}
7999

80-
if (maxRevert > 0 && reverted + (-this.amount) > maxRevert) { // check if we limit the max revert, and if the revert overflow the value
81-
this.amount = -(maxRevert - reverted); // ceil the value for max revert
82-
}
100+
@Override
101+
public void handleServerSide(EntityPlayer player) {
102+
super.handleServerSide(player);
103+
StatBase stat = StatBase.stats.get(this.stat);
104+
if (!stat.enabled)
105+
return;
106+
int level = DataHelper.getPlayerStatLevel(player, stat);
107+
if (DataHelper.getPlayerStatLevel(player, stat) > 0) {
108+
int reverted = DataHelper.getPlayerRevertStatLevel(player, stat);
109+
int maxRevert = GokiConfig.globalModifiers.globalMaxRevertLevel;
83110

84-
reverted += (-this.amount);
85-
DataHelper.setPlayerRevertStatLevel(player, stat, reverted);
111+
if (maxRevert >= 0 && reverted + this.amount > maxRevert) { // check if we limit the max revert, and if the revert overflow the value
112+
this.amount += maxRevert - reverted; // ceil the value for max revert
113+
}
86114

87-
player.addExperience((int) (stat.getCost(level + this.amount - 2) * GokiConfig.globalModifiers.globalRevertFactor));
88-
DataHelper.setPlayerStatLevel(player, stat, level + this.amount);
89-
if (stat instanceof StatMaxHealth) {
90-
player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20 + level + this.amount);
91-
}
115+
reverted += this.amount;
116+
DataHelper.setPlayerRevertStatLevel(player, stat, reverted);
92117

93-
GokiStats.packetPipeline.sendTo(new PacketStatSync(player), (EntityPlayerMP) player);
94-
GokiStats.packetPipeline.sendTo(new PacketSyncXP(player), (EntityPlayerMP) player);
118+
player.addExperience((int) (stat.getCost(level - this.amount - 2) * GokiConfig.globalModifiers.globalRevertFactor));
119+
DataHelper.setPlayerStatLevel(player, stat, level - this.amount);
120+
if (stat instanceof StatMaxHealth) {
121+
player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20 + level - this.amount);
122+
}
123+
124+
GokiStats.packetPipeline.sendTo(new PacketStatSync(player), (EntityPlayerMP) player);
125+
GokiStats.packetPipeline.sendTo(new PacketSyncXP(player), (EntityPlayerMP) player);
126+
}
95127
}
96128
}
97129
}

src/main/java/net/infstudio/goki/common/network/packet/PacketStatSync.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@
88

99
public class PacketStatSync implements GokiPacket {
1010
private int[] statLevels;
11+
private int[] revertedStatLevels;
1112

1213
public PacketStatSync() {
1314
}
1415

1516
public PacketStatSync(EntityPlayer player) {
1617
this.statLevels = new int[StatBase.stats.size()];
18+
this.revertedStatLevels = new int[StatBase.stats.size()];
1719
for (int i = 0; i < this.statLevels.length; i++) {
1820
if (StatBase.stats.get(i) != null) {
1921
this.statLevels[i] = DataHelper.getPlayerStatLevel(player,
2022
StatBase.stats.get(i));
23+
this.revertedStatLevels[i] = DataHelper.getPlayerRevertStatLevel(player, StatBase.stats.get(i));
2124
}
2225
}
2326
}
@@ -26,13 +29,20 @@ public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
2629
for (int statLevel : this.statLevels) {
2730
buffer.writeInt(statLevel);
2831
}
32+
for (int revertedStatLevel: this.revertedStatLevels) {
33+
buffer.writeInt(revertedStatLevel);
34+
}
2935
}
3036

3137
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
3238
this.statLevels = new int[StatBase.stats.size()];
39+
this.revertedStatLevels = new int[StatBase.stats.size()];
3340
for (int i = 0; i < this.statLevels.length; i++) {
3441
this.statLevels[i] = buffer.readInt();
3542
}
43+
for (int i = 0; i < this.revertedStatLevels.length; i++) {
44+
this.revertedStatLevels[i] = buffer.readInt();
45+
}
3646
}
3747

3848
public void handleClientSide(EntityPlayer player) {
@@ -41,6 +51,9 @@ public void handleClientSide(EntityPlayer player) {
4151
StatBase.stats.get(i),
4252
this.statLevels[i]);
4353
}
54+
for (int i = 0; i < this.revertedStatLevels.length; i++) {
55+
DataHelper.setPlayerRevertStatLevel(player, StatBase.stats.get(i), this.revertedStatLevels[i]);
56+
}
4457
}
4558

4659
public void handleServerSide(EntityPlayer player) {

src/main/java/net/infstudio/goki/common/utils/DataHelper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.infstudio.goki.common.utils;
22

3+
import net.infstudio.goki.common.config.GokiConfig;
34
import net.infstudio.goki.common.stats.StatBase;
45
import net.minecraft.enchantment.EnchantmentHelper;
56
import net.minecraft.entity.Entity;
@@ -24,6 +25,10 @@ public static NBTTagCompound getPlayerPersistentNBT(EntityPlayer player) {
2425
return nbt;
2526
}
2627

28+
public static boolean canPlayerRevertStat(EntityPlayer player, StatBase stat) {
29+
return GokiConfig.globalModifiers.globalMaxRevertLevel >= 0 && getPlayerRevertStatLevel(player, stat) < GokiConfig.globalModifiers.globalMaxRevertLevel && getPlayerStatLevel(player, stat) > 0;
30+
}
31+
2732
public static int getPlayerRevertStatLevel(EntityPlayer player, StatBase stat) {
2833
NBTTagCompound nbt = getPlayerPersistentNBT(player);
2934
if (nbt.hasKey("gokistats_Stats")) {

0 commit comments

Comments
 (0)