Skip to content

Commit 852c1f0

Browse files
committed
Fix dedicated server crashes, v0.4.4
1 parent e4b7476 commit 852c1f0

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ btw_version = 3.0.0
66
yarn_mappings = 1.6.4+build.420
77
loader_version = 0.14.19
88

9-
mod_version = 0.4.3+BTW3.0.0
9+
mod_version = 0.4.4+BTW3.0.0
1010
maven_group = net.fabricmc
1111
archives_base_name = rpg-addon
1212

src/main/java/btw/community/arminias/rpg/RPGAddon.java

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
import api.AddonHandler;
55
import api.BTWAddon;
6+
import api.network.CustomPacketHandler;
7+
import net.fabricmc.api.EnvType;
8+
import net.fabricmc.api.Environment;
69
import net.minecraft.server.MinecraftServer;
710
import net.minecraft.src.*;
811

9-
import java.io.ByteArrayInputStream;
10-
import java.io.ByteArrayOutputStream;
11-
import java.io.DataInputStream;
12-
import java.io.DataOutputStream;
12+
import java.io.*;
1313
import java.util.List;
1414

1515
public class RPGAddon extends BTWAddon {
@@ -43,19 +43,6 @@ public RPGAddon() {
4343
@Override
4444
public void initialize() {
4545
AddonHandler.logMessage(this.getName() + " Version " + this.getVersionString() + " Initializing...");
46-
registerPacketHandler("rpg|StatsC", (packet, player_) -> {
47-
// 1.5
48-
// Client-Side: You get a packet with the stats of the player
49-
DataInputStream data = new DataInputStream(new ByteArrayInputStream(packet.data));
50-
((RPGStats) Minecraft.getMinecraft().thePlayer).doReinit(new RPGPointsAllocation(data));
51-
});
52-
registerPacketHandler("rpg|Screen", (packet, player_) -> {
53-
// Client-Side: You get a packet to open the stats screen
54-
EntityPlayer player;
55-
Minecraft.getMinecraft().displayGuiScreen(new GuiRPGStats(Minecraft.getMinecraft().currentScreen,
56-
(player = Minecraft.getMinecraft().thePlayer) != null ? ((RPGStats) player).getAllocation() : RPGPointsAllocation.defaultAllocation(RPGPointsAllocation.DEFAULT_POINTS),
57-
true));
58-
});
5946
AddonHandler.registerCommand(new CommandBase() {
6047
@Override
6148
public String getCommandName() {
@@ -91,6 +78,16 @@ public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[]
9178
}
9279

9380
}, false);
81+
82+
if (!MinecraftServer.getIsServer()) {
83+
registerClientPacketHandlers();
84+
}
85+
}
86+
87+
@Environment(EnvType.CLIENT)
88+
private void registerClientPacketHandlers() {
89+
registerPacketHandler("rpg|StatsC", new ClientStatPacketHandler());
90+
registerPacketHandler("rpg|Screen", new ClientRPGGuiPacketHandler());
9491
}
9592

9693
public static void sendStatAllocationScreenToPlayer(EntityPlayerMP player) {
@@ -139,6 +136,7 @@ public static void sendStatAllocationToPlayer(NetServerHandler serverHandler, En
139136
}
140137
}
141138

139+
@Environment(EnvType.CLIENT)
142140
public static void sendStatAllocationToServer(RPGPointsAllocation pointsAllocation, boolean force) {
143141
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
144142
DataOutputStream dataStream = new DataOutputStream(byteStream);
@@ -154,4 +152,26 @@ public static RPGAddon getInstance() {
154152
return instance;
155153
}
156154

155+
@Environment(EnvType.CLIENT)
156+
private static class ClientStatPacketHandler implements CustomPacketHandler {
157+
@Override
158+
public void handleCustomPacket(Packet250CustomPayload packet, EntityPlayer player_) throws IOException {
159+
// 1.5
160+
// Client-Side: You get a packet with the stats of the player
161+
DataInputStream data = new DataInputStream(new ByteArrayInputStream(packet.data));
162+
((RPGStats) Minecraft.getMinecraft().thePlayer).doReinit(new RPGPointsAllocation(data));
163+
}
164+
}
165+
166+
@Environment(EnvType.CLIENT)
167+
private static class ClientRPGGuiPacketHandler implements CustomPacketHandler {
168+
@Override
169+
public void handleCustomPacket(Packet250CustomPayload packet, EntityPlayer player_) throws IOException {
170+
// Client-Side: You get a packet to open the stats screen
171+
EntityPlayer player;
172+
Minecraft.getMinecraft().displayGuiScreen(new GuiRPGStats(Minecraft.getMinecraft().currentScreen,
173+
(player = Minecraft.getMinecraft().thePlayer) != null ? ((RPGStats) player).getAllocation() : RPGPointsAllocation.defaultAllocation(RPGPointsAllocation.DEFAULT_POINTS),
174+
true));
175+
}
176+
}
157177
}

0 commit comments

Comments
 (0)