Skip to content

Commit a283791

Browse files
committed
1.21.2 fixes
1 parent 807ef59 commit a283791

File tree

10 files changed

+96
-45
lines changed

10 files changed

+96
-45
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
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.12.5</version>
14+
<version>2.12.6</version>
1515
<name>FishingBot</name>
1616
<description>An AFK fishing bot for Minecraft</description>
1717

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public void shiftToInventory(int slotId, Inventory inventory) {
328328
FishingBot.getInstance().getCurrentBot().getNet().sendPacket(
329329
new PacketOutClickWindow(
330330
/* player inventory */ inventory.getWindowId(),
331-
/* the clicked slot */ (short) (slotId + (inventory.getContent().size() == 63 ? 18 : 45)),
331+
/* the clicked slot */ (short) (slotId + (inventory.getContent().size() - 45)),
332332
/* use right click */ (byte) 0,
333333
/* action count starting at 1 */ inventory.getActionCounter(),
334334
/* shift click mode */ 1,
@@ -445,7 +445,7 @@ public void setHeldSlot(int heldSlot) {
445445
public void setHeldSlot(int heldSlot, boolean sendPacket) {
446446
if (sendPacket)
447447
FishingBot.getInstance().getCurrentBot().getNet().sendPacket(new PacketOutHeldItemChange(heldSlot));
448-
this.heldSlot = heldSlot;
448+
this.heldSlot = heldSlot + 36;
449449
}
450450

451451
public void use() {

src/main/java/systems/kinau/fishingbot/modules/command/commands/CommandRightClick.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void register(LiteralArgumentBuilder<CommandExecutor> builder) {
2222
source.sendTranslatedMessages("command-rightclick-invalid-slot", slot + 1);
2323
return 0;
2424
}
25-
FishingBot.getInstance().getCurrentBot().getPlayer().setHeldSlot(slot + 36);
25+
FishingBot.getInstance().getCurrentBot().getPlayer().setHeldSlot(slot);
2626
try {
2727
Thread.sleep(50);
2828
} catch (InterruptedException e) {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ private void updateInventory(Slot slot, int slotId) {
363363
}
364364
// check current fishing rod value and swap if a better one is in inventory
365365
if (ItemUtils.isFishingRod(slot) && !FishingBot.getInstance().getCurrentBot().getConfig().isDisableRodChecking()) {
366-
FishingBot.getLog().info("Found rod at: " + slotId + " (current: " + FishingBot.getInstance().getCurrentBot().getPlayer().getHeldSlot() + ")");
367366
swapWithBestFishingRod();
368367
}
369368

src/main/java/systems/kinau/fishingbot/network/item/datacomponent/components/FoodComponent.java

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ public void write(ByteArrayDataOutput out, int protocolId) {
3636
Packet.writeVarInt(nutrition, out);
3737
out.writeFloat(saturation);
3838
out.writeBoolean(canAlwaysEat);
39-
out.writeFloat(eatSeconds);
40-
if (protocolId >= ProtocolConstants.MC_1_21) {
41-
out.writeBoolean(usingConvertsTo.isPresent());
42-
usingConvertsTo.ifPresent(slot -> Packet.writeSlot(slot, out, protocolId));
43-
}
44-
Packet.writeVarInt(possibleEffects.size(), out);
45-
for (PossibleEffect effect : possibleEffects) {
46-
effect.write(out, protocolId);
39+
if (protocolId < ProtocolConstants.MC_1_21_2) {
40+
out.writeFloat(eatSeconds);
41+
if (protocolId == ProtocolConstants.MC_1_21) {
42+
out.writeBoolean(usingConvertsTo.isPresent());
43+
usingConvertsTo.ifPresent(slot -> Packet.writeSlot(slot, out, protocolId));
44+
}
45+
Packet.writeVarInt(possibleEffects.size(), out);
46+
for (PossibleEffect effect : possibleEffects) {
47+
effect.write(out, protocolId);
48+
}
4749
}
4850
}
4951

@@ -52,26 +54,28 @@ public void read(ByteArrayDataInputWrapper in, int protocolId) {
5254
this.nutrition = Packet.readVarInt(in);
5355
this.saturation = in.readFloat();
5456
this.canAlwaysEat = in.readBoolean();
55-
this.eatSeconds = in.readFloat();
56-
if (protocolId >= ProtocolConstants.MC_1_21) {
57-
if (in.readBoolean()) {
58-
if (FishingBot.getInstance().getConfig().isLogItemData()) {
59-
FishingBot.getLog().info("Start reading food component usingConvertsTo");
57+
if (protocolId < ProtocolConstants.MC_1_21_2) {
58+
this.eatSeconds = in.readFloat();
59+
if (protocolId == ProtocolConstants.MC_1_21) {
60+
if (in.readBoolean()) {
61+
if (FishingBot.getInstance().getConfig().isLogItemData()) {
62+
FishingBot.getLog().info("Start reading food component usingConvertsTo");
63+
}
64+
this.usingConvertsTo = Optional.of(Packet.readSlot(in, protocolId, dataComponentRegistry));
65+
if (FishingBot.getInstance().getConfig().isLogItemData()) {
66+
FishingBot.getLog().info("End of reading food component usingConvertsTo");
67+
}
68+
} else {
69+
this.usingConvertsTo = Optional.empty();
6070
}
61-
this.usingConvertsTo = Optional.of(Packet.readSlot(in, protocolId, dataComponentRegistry));
62-
if (FishingBot.getInstance().getConfig().isLogItemData()) {
63-
FishingBot.getLog().info("End of reading food component usingConvertsTo");
64-
}
65-
} else {
66-
this.usingConvertsTo = Optional.empty();
6771
}
68-
}
69-
this.possibleEffects = new LinkedList<>();
70-
int count = Packet.readVarInt(in);
71-
for (int i = 0; i < count; i++) {
72-
PossibleEffect possibleEffect = new PossibleEffect();
73-
possibleEffect.read(in, protocolId);
74-
possibleEffects.add(possibleEffect);
72+
this.possibleEffects = new LinkedList<>();
73+
int count = Packet.readVarInt(in);
74+
for (int i = 0; i < count; i++) {
75+
PossibleEffect possibleEffect = new PossibleEffect();
76+
possibleEffect.read(in, protocolId);
77+
possibleEffects.add(possibleEffect);
78+
}
7579
}
7680
}
7781
}

src/main/java/systems/kinau/fishingbot/network/item/datacomponent/components/PotionContentsComponent.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import systems.kinau.fishingbot.network.item.datacomponent.DataComponent;
55
import systems.kinau.fishingbot.network.item.datacomponent.components.parts.Effect;
66
import systems.kinau.fishingbot.network.protocol.Packet;
7+
import systems.kinau.fishingbot.network.protocol.ProtocolConstants;
78
import systems.kinau.fishingbot.network.utils.ByteArrayDataInputWrapper;
89

910
import java.util.Collections;
@@ -16,6 +17,7 @@ public class PotionContentsComponent extends DataComponent {
1617
private Optional<Integer> potionId;
1718
private Optional<Integer> customColor;
1819
private List<Effect> effects = Collections.emptyList();
20+
private Optional<String> customName;
1921

2022
public PotionContentsComponent(int componentTypeId) {
2123
super(componentTypeId);
@@ -31,6 +33,10 @@ public void write(ByteArrayDataOutput out, int protocolId) {
3133
for (Effect effect : effects) {
3234
effect.write(out, protocolId);
3335
}
36+
if (protocolId >= ProtocolConstants.MC_1_21_2) {
37+
out.writeBoolean(customName.isPresent());
38+
customName.ifPresent(s -> Packet.writeString(s, out));
39+
}
3440
}
3541

3642
@Override
@@ -54,5 +60,13 @@ public void read(ByteArrayDataInputWrapper in, int protocolId) {
5460
effect.read(in, protocolId);
5561
effects.add(effect);
5662
}
63+
64+
if (protocolId >= ProtocolConstants.MC_1_21_2) {
65+
if (in.readBoolean()) {
66+
customName = Optional.of(Packet.readString(in));
67+
} else {
68+
customName = Optional.empty();
69+
}
70+
}
5771
}
5872
}

src/main/java/systems/kinau/fishingbot/network/item/datacomponent/components/parts/instrument/Instrument.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import systems.kinau.fishingbot.network.item.datacomponent.DataComponentPart;
77
import systems.kinau.fishingbot.network.item.datacomponent.components.parts.SoundEvent;
88
import systems.kinau.fishingbot.network.protocol.Packet;
9+
import systems.kinau.fishingbot.network.protocol.ProtocolConstants;
910
import systems.kinau.fishingbot.network.utils.ByteArrayDataInputWrapper;
11+
import systems.kinau.fishingbot.utils.nbt.NBTTag;
1012

1113
@Getter
1214
@NoArgsConstructor
@@ -15,15 +17,22 @@ public class Instrument implements DataComponentPart {
1517
private int instrumentId;
1618
private SoundEvent soundEvent;
1719
private int useDuration;
20+
private float useDurationNew;
1821
private float range;
22+
private NBTTag description;
1923

2024
@Override
2125
public void write(ByteArrayDataOutput out, int protocolId) {
2226
Packet.writeVarInt(instrumentId, out);
2327
if (instrumentId == 0) {
2428
soundEvent.write(out, protocolId);
25-
Packet.writeVarInt(useDuration, out);
29+
if (protocolId >= ProtocolConstants.MC_1_21_2)
30+
out.writeFloat(useDurationNew);
31+
else
32+
Packet.writeVarInt(useDuration, out);
2633
out.writeFloat(range);
34+
if (protocolId >= ProtocolConstants.MC_1_21_2)
35+
Packet.writeNBT(description, out);
2736
}
2837
}
2938

@@ -33,8 +42,13 @@ public void read(ByteArrayDataInputWrapper in, int protocolId) {
3342
if (instrumentId == 0) {
3443
this.soundEvent = new SoundEvent();
3544
soundEvent.read(in, protocolId);
36-
this.useDuration = Packet.readVarInt(in);
45+
if (protocolId >= ProtocolConstants.MC_1_21_2)
46+
this.useDurationNew = in.readFloat();
47+
else
48+
this.useDuration = Packet.readVarInt(in);
3749
this.range = in.readFloat();
50+
if (protocolId >= ProtocolConstants.MC_1_21_2)
51+
this.description = Packet.readNBT(in, protocolId);
3852
}
3953
}
4054
}

src/main/java/systems/kinau/fishingbot/network/item/datacomponent/components/parts/trim/TrimMaterial.java

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import lombok.NoArgsConstructor;
66
import systems.kinau.fishingbot.network.item.datacomponent.DataComponentPart;
77
import systems.kinau.fishingbot.network.protocol.Packet;
8+
import systems.kinau.fishingbot.network.protocol.ProtocolConstants;
89
import systems.kinau.fishingbot.network.utils.ByteArrayDataInputWrapper;
910
import systems.kinau.fishingbot.utils.nbt.NBTTag;
1011

@@ -20,6 +21,7 @@ public class TrimMaterial implements DataComponentPart {
2021
private int ingredient;
2122
private float itemModelIndex;
2223
private Map<Integer, String> overrideArmorMaterials = new HashMap<>();
24+
private Map<String, String> overrideArmorMaterialsNew = new HashMap<>();
2325
private NBTTag description;
2426

2527
@Override
@@ -29,11 +31,19 @@ public void write(ByteArrayDataOutput out, int protocolId) {
2931
Packet.writeString(assetName, out);
3032
Packet.writeVarInt(ingredient, out);
3133
out.writeFloat(itemModelIndex);
32-
Packet.writeVarInt(overrideArmorMaterials.size(), out);
33-
overrideArmorMaterials.forEach((key, value) -> {
34-
Packet.writeVarInt(key, out);
35-
Packet.writeString(value, out);
36-
});
34+
if (protocolId >= ProtocolConstants.MC_1_21_2) {
35+
Packet.writeVarInt(overrideArmorMaterialsNew.size(), out);
36+
overrideArmorMaterialsNew.forEach((key, value) -> {
37+
Packet.writeString(key, out);
38+
Packet.writeString(value, out);
39+
});
40+
} else {
41+
Packet.writeVarInt(overrideArmorMaterials.size(), out);
42+
overrideArmorMaterials.forEach((key, value) -> {
43+
Packet.writeVarInt(key, out);
44+
Packet.writeString(value, out);
45+
});
46+
}
3747
Packet.writeNBT(description, out);
3848
}
3949
}
@@ -45,12 +55,21 @@ public void read(ByteArrayDataInputWrapper in, int protocolId) {
4555
this.assetName = Packet.readString(in);
4656
this.ingredient = Packet.readVarInt(in);
4757
this.itemModelIndex = in.readFloat();
48-
this.overrideArmorMaterials = new HashMap<>();
58+
if (protocolId >= ProtocolConstants.MC_1_21_2)
59+
this.overrideArmorMaterialsNew = new HashMap<>();
60+
else
61+
this.overrideArmorMaterials = new HashMap<>();
4962
int count = Packet.readVarInt(in);
5063
for (int i = 0; i < count; i++) {
51-
int key = Packet.readVarInt(in);
52-
String value = Packet.readString(in);
53-
overrideArmorMaterials.put(key, value);
64+
if (protocolId >= ProtocolConstants.MC_1_21_2) {
65+
String key = Packet.readString(in);
66+
String value = Packet.readString(in);
67+
overrideArmorMaterialsNew.put(key, value);
68+
} else {
69+
int key = Packet.readVarInt(in);
70+
String value = Packet.readString(in);
71+
overrideArmorMaterials.put(key, value);
72+
}
5473
}
5574
this.description = Packet.readNBT(in, protocolId);
5675
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public static String getVersionString(int protocolId) {
141141
case MC_1_20_2: return "1.20.2";
142142
case MC_1_20_3: return "1.20.3 / 1.20.4";
143143
case MC_1_20_5: return "1.20.5 / 1.20.6";
144-
case MC_1_21: return "1.21";
144+
case MC_1_21: return "1.21 / 1.21.1";
145145
case MC_1_21_2: return "1.21.2";
146146
default: return "Unknown version";
147147
}
@@ -212,7 +212,9 @@ public static int getProtocolId(String versionString) {
212212
case "1.20.5":
213213
case "1.20.6":
214214
case "1.20.5 / 1.20.6": return MC_1_20_5;
215-
case "1.21": return MC_1_21;
215+
case "1.21":
216+
case "1.21.1":
217+
case "1.21 / 1.21.1": return MC_1_21;
216218
case "1.21.2": return MC_1_21_2;
217219
default: return MC_1_8;
218220
}

src/main/java/systems/kinau/fishingbot/network/protocol/play/PacketInHeldItemChange.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public void write(ByteArrayDataOutput out, int protocolId) {
2828
@Override
2929
public void read(ByteArrayDataInputWrapper in, NetworkHandler networkHandler, int length, int protocolId) {
3030
this.heldItemSlot = in.readByte() + 36;
31-
FishingBot.getLog().info("Received set held item: " + heldItemSlot);
3231

3332
FishingBot.getInstance().getCurrentBot().getEventManager().callEvent(new SetHeldItemEvent(heldItemSlot));
3433
}

0 commit comments

Comments
 (0)