Skip to content

Commit 909ade0

Browse files
committed
implemented 1.16-pre5 support (nothing changed, lol)
implemented auto-respawn (only tested in 1.16) #27 #35 first attempts of forge handshake #38
1 parent 6775340 commit 909ade0

File tree

14 files changed

+209
-76
lines changed

14 files changed

+209
-76
lines changed

pom.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<groupId>systems.kinau</groupId>
1313
<artifactId>FishingBot</artifactId>
14-
<version>2.7</version>
14+
<version>2.7.1</version>
1515
<name>FishingBot</name>
1616
<description>An AFK fishing bot for minecraft</description>
1717

@@ -36,6 +36,7 @@
3636
<scope>provided</scope>
3737
</dependency>
3838
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
39+
<!-- TODO: Replace with json-simple -->
3940
<dependency>
4041
<groupId>com.google.code.gson</groupId>
4142
<artifactId>gson</artifactId>
@@ -51,7 +52,7 @@
5152
<dependency>
5253
<groupId>org.apache.httpcomponents</groupId>
5354
<artifactId>httpclient</artifactId>
54-
<version>4.5.10</version>
55+
<version>4.5.12</version>
5556
</dependency>
5657
<dependency>
5758
<groupId>org.bouncycastle</groupId>
@@ -61,7 +62,7 @@
6162
<dependency>
6263
<groupId>com.flowpowered</groupId>
6364
<artifactId>flow-nbt</artifactId>
64-
<version>LATEST</version>
65+
<version>1.0.0</version>
6566
</dependency>
6667
<dependency>
6768
<groupId>com.github.MrPowerGamerBR</groupId>

src/main/java/systems/kinau/fishingbot/bot/Player.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import systems.kinau.fishingbot.fishing.AnnounceType;
1616
import systems.kinau.fishingbot.network.protocol.ProtocolConstants;
1717
import systems.kinau.fishingbot.network.protocol.play.PacketOutChat;
18+
import systems.kinau.fishingbot.network.protocol.play.PacketOutClientStatus;
1819
import systems.kinau.fishingbot.network.protocol.play.PacketOutTeleportConfirm;
1920

2021
public class Player implements Listener {
@@ -79,5 +80,16 @@ public void onUpdateSlot(UpdateSlotEvent event) {
7980
@EventHandler
8081
public void onJoinGame(JoinGameEvent event) {
8182
setEntityID(event.getEid());
83+
respawn();
84+
}
85+
86+
@EventHandler
87+
public void onUpdateHealth(UpdateHealthEvent event) {
88+
if (event.getHealth() <= 0)
89+
respawn();
90+
}
91+
92+
public void respawn() {
93+
FishingBot.getInstance().getNet().sendPacket(new PacketOutClientStatus(PacketOutClientStatus.Action.PERFORM_RESPAWN));
8294
}
8395
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package systems.kinau.fishingbot.event.play;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
import systems.kinau.fishingbot.event.Event;
6+
7+
@AllArgsConstructor
8+
public class UpdateHealthEvent extends Event {
9+
10+
@Getter private float health;
11+
@Getter private int food;
12+
@Getter private float saturation;
13+
14+
}

src/main/java/systems/kinau/fishingbot/fishing/ItemHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public ItemHandler(int protocolId) {
6464
break;
6565
}
6666
case ProtocolConstants.MINECRAFT_1_16_PRE_2:
67+
case ProtocolConstants.MINECRAFT_1_16_PRE_5:
6768
default: {
6869
root = new JsonParser().parse(new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream("registries_1_16.json")));
6970
root = root.getAsJsonObject().get("minecraft:item").getAsJsonObject().get("entries").getAsJsonObject();

src/main/java/systems/kinau/fishingbot/modules/ClientDefaultsModule.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
public class ClientDefaultsModule extends Module implements Listener {
2323

2424
@Getter private Thread positionThread;
25+
@Getter private boolean joined;
2526

2627
@Override
2728
public void onEnable() {
@@ -37,6 +38,9 @@ public void onDisable() {
3738

3839
@EventHandler
3940
public void onSetDifficulty(DifficultySetEvent event) {
41+
if (isJoined())
42+
return;
43+
this.joined = true;
4044
new Thread(() -> {
4145
try {
4246
Thread.sleep(1500);

src/main/java/systems/kinau/fishingbot/modules/FishingModule.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ public void onSpawnObject(SpawnObjectEvent event) {
352352
break;
353353
}
354354
case ProtocolConstants.MINECRAFT_1_16_PRE_2:
355+
case ProtocolConstants.MINECRAFT_1_16_PRE_5:
355356
default: {
356357
if(event.getType() == 106) { //106 = bobber
357358
if(FishingBot.getInstance().getPlayer().getEntityID() == -1 || event.getObjectData() == FishingBot.getInstance().getPlayer().getEntityID())

src/main/java/systems/kinau/fishingbot/modules/LoginModule.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public void onSetCompression(SetCompressionEvent event) {
8484

8585
@EventHandler
8686
public void onLoginPluginRequest(LoginPluginRequestEvent event) {
87+
System.out.println(event.getMsgId() + " >> " + event.getChannel());
8788
FishingBot.getInstance().getNet().sendPacket(new PacketOutLoginPluginResponse(event.getMsgId(), false, null));
8889
}
8990

src/main/java/systems/kinau/fishingbot/network/protocol/NetworkHandler.java

Lines changed: 77 additions & 57 deletions
Large diffs are not rendered by default.

src/main/java/systems/kinau/fishingbot/network/protocol/ProtocolConstants.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package systems.kinau.fishingbot.network.protocol;
77

88
import java.util.Arrays;
9+
import java.util.Comparator;
910
import java.util.List;
1011

1112
public class ProtocolConstants {
@@ -33,6 +34,7 @@ public class ProtocolConstants {
3334
public static final int MINECRAFT_1_15_1 = 575;
3435
public static final int MINECRAFT_1_15_2 = 578;
3536
public static final int MINECRAFT_1_16_PRE_2 = 722;
37+
public static final int MINECRAFT_1_16_PRE_5 = 729;
3638

3739
public static final List<String> SUPPORTED_VERSIONS = Arrays.asList(
3840
"1.8.x",
@@ -69,7 +71,8 @@ public class ProtocolConstants {
6971
ProtocolConstants.MINECRAFT_1_15,
7072
ProtocolConstants.MINECRAFT_1_15_1,
7173
ProtocolConstants.MINECRAFT_1_15_2,
72-
ProtocolConstants.MINECRAFT_1_16_PRE_2
74+
ProtocolConstants.MINECRAFT_1_16_PRE_2,
75+
ProtocolConstants.MINECRAFT_1_16_PRE_5
7376
);
7477

7578
public static String getVersionString(int protocolId) {
@@ -97,6 +100,7 @@ public static String getVersionString(int protocolId) {
97100
case MINECRAFT_1_15_1: return "1.15.1";
98101
case MINECRAFT_1_15_2: return "1.15.2";
99102
case MINECRAFT_1_16_PRE_2: return "1.16-pre2";
103+
case MINECRAFT_1_16_PRE_5: return "1.16-pre5";
100104
default: return "Unknown version";
101105
}
102106
}
@@ -125,7 +129,12 @@ public static int getProtocolId(String versionString) {
125129
case "1.15.1": return MINECRAFT_1_15_1;
126130
case "1.15.2": return MINECRAFT_1_15_2;
127131
case "1.16-pre2": return MINECRAFT_1_16_PRE_2;
132+
case "1.16-pre5": return MINECRAFT_1_16_PRE_5;
128133
default: return MINECRAFT_1_8;
129134
}
130135
}
136+
137+
public static int getLatest() {
138+
return SUPPORTED_VERSION_IDS.stream().max(Comparator.naturalOrder()).orElse(0);
139+
}
131140
}

src/main/java/systems/kinau/fishingbot/network/protocol/handshake/PacketOutHandshake.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class PacketOutHandshake extends Packet {
2121
@Override
2222
public void write(ByteArrayDataOutput out, int protocolId) {
2323
writeVarInt(FishingBot.getInstance().getServerProtocol(), out);
24-
writeString(serverName, out);
24+
writeString(serverName + "\0FML\0", out);
2525
out.writeShort(serverPort);
2626
writeVarInt(2, out); //next State = 2 -> LOGIN
2727
}

0 commit comments

Comments
 (0)