Skip to content

Commit 57fa71c

Browse files
committed
[fix][feature] improved CA break with async break, and hot fixed CA stuff
1 parent c33bb26 commit 57fa71c

File tree

2 files changed

+57
-107
lines changed

2 files changed

+57
-107
lines changed

src/main/java/rina/onepop/club/client/module/combat/autocrystalrewrite/ModuleAutoCrystalRewrite.java

Lines changed: 49 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import rina.onepop.club.api.social.management.SocialManager;
3434
import rina.onepop.club.api.social.type.SocialType;
3535
import rina.onepop.club.api.strict.StrictUtilityInjector;
36+
import rina.onepop.club.api.util.chat.ChatUtil;
3637
import rina.onepop.club.api.util.client.NullUtil;
3738
import rina.onepop.club.api.util.entity.EntityUtil;
3839
import rina.onepop.club.api.util.item.SlotUtil;
@@ -74,11 +75,12 @@ public class ModuleAutoCrystalRewrite extends Module {
7475
public static ValueBoolean settingWallCheck = new ValueBoolean("Wall Check", "WallCheck", "Enable wall check.", false);
7576
public static ValueNumber settingWallRange = new ValueNumber("Wall Range", "WallRange", "Prevents blocks in wall.", 4f, 2f, 5f);
7677
public static ValueBoolean settingBreakAnimation = new ValueBoolean("Break Animation", "BreakAnimation", "idk mwmw", false);
77-
public static ValueNumber settingBreakPriority = new ValueNumber("Break Priority", "BreakPriority", "Break priority for needed time.", 0, 0, 3);
7878
public static ValueNumber settingBreakRange = new ValueNumber("Break Range", "BreakRange", "Sets break range.", 4f, 2f, 6f);
7979
public static ValueNumber settingPlaceRange = new ValueNumber("Place Range", "PlaceRange", "Sets place range.", 4f, 2f, 6f);
80-
public static ValueNumber settingPlaceDelay = new ValueNumber("Place Delay", "PlaceDelay", "Sets place delay.", 33, 0, 50);
81-
public static ValueNumber settingBreakDelay = new ValueNumber("Break Delay", "BreakDelay", "Sets break delay.", 33, 0, 50);
80+
public static ValueNumber settingPlaceDelay = new ValueNumber("Place Delay", "PlaceDelay", "Sets place delay.", 33, 0, 500);
81+
public static ValueBoolean settingPlaceAnimation = new ValueBoolean("Place Animation", "PlaceAnimation", "sends place animation to server", true);
82+
public static ValueNumber settingBreakDelay = new ValueNumber("Break Delay", "BreakDelay", "Sets break delay.", 33, 0, 500);
83+
public static ValueNumber settingBreakAsyncDelay = new ValueNumber("Async Break Delay", "AsyncBreakDelay", "Sets break delay.", 33, 0, 500);
8284
public static ValueNumber settingSelfDamage = new ValueNumber("Self Damage", "SelfDamage", "Self damage.", 9, 1, 36);
8385
public static ValueNumber settingMinimumDamage = new ValueNumber("Min. Damage", "Min. Damage", "Sets minimum damage.", 4, 0, 36);
8486
public static ValueNumber settingFacingY = new ValueNumber("Facing Y", "FacingY", "Sets the facing Y from place.", 1f, 0f, 1f);
@@ -96,6 +98,7 @@ public class ModuleAutoCrystalRewrite extends Module {
9698

9799
private final TurokTick rotationDelayMS = new TurokTick();
98100
private final TurokTick cooldownDelayMS = new TurokTick();
101+
private final TurokTick asyncBreakDelayMS = new TurokTick();
99102
private boolean multiConnection;
100103

101104
private float yaw;
@@ -106,6 +109,7 @@ public class ModuleAutoCrystalRewrite extends Module {
106109

107110
private EntityPlayer entity;
108111
private BlockPos position;
112+
private BlockPos lastPlaceBreakedPos;
109113

110114
private boolean isCrystalInOffhand;
111115
private boolean isCrystalInMainHand;
@@ -149,8 +153,8 @@ public void onSetting() {
149153
settingBreakRange.setEnabled(settingTab.getValue() == Tab.CRYSTAL);
150154
settingPlaceRange.setEnabled(settingTab.getValue() == Tab.CRYSTAL);
151155
settingPlaceDelay.setEnabled(settingTab.getValue() == Tab.CRYSTAL);
152-
settingBreakPriority.setEnabled(settingTab.getValue() == Tab.CRYSTAL);
153156
settingBreakAnimation.setEnabled(settingTab.getValue() == Tab.CRYSTAL);
157+
settingBreakAsyncDelay.setEnabled(settingTab.getValue() == Tab.CRYSTAL && settingPredict.getValue());
154158
settingBreakDelay.setEnabled(settingTab.getValue() == Tab.CRYSTAL);
155159
settingWallCheck.setEnabled(settingTab.getValue() == Tab.CRYSTAL);
156160
settingWallRange.setEnabled(settingTab.getValue() == Tab.CRYSTAL && settingWallCheck.getValue());
@@ -191,17 +195,6 @@ public void onDirectDraw3D() {
191195

192196
@Listener
193197
public void onPacketSend(PacketEvent.Send event) {
194-
int priority = settingBreakPriority.getValue().intValue();
195-
if (event.getPacket() instanceof CPacketUseEntity && priority > 0 && priority != 3) {
196-
CPacketUseEntity useEntity = (CPacketUseEntity) event.getPacket();
197-
useEntity.hand = this.handAttack;
198-
if ((useEntity.entityId = this.findCrystal()) == -1) {
199-
event.setCanceled(true);
200-
} else {
201-
this.hitCount.add(useEntity.entityId);
202-
}
203-
}
204-
205198
if (event.getPacket() instanceof CPacketPlayerTryUseItemOnBlock && settingStrictPriority.getValue() == Priority.HIGH && this.entity != null) {
206199
final CPacketPlayerTryUseItemOnBlock packet = (CPacketPlayerTryUseItemOnBlock) event.getPacket();
207200
event.setCanceled(!CrystalUtil.isCrystalPlaceable(packet.getPos(), settingPlace113.getValue(), true));
@@ -213,19 +206,24 @@ public void onPacketSend(PacketEvent.Send event) {
213206
}
214207

215208
public void doBreakCrystal(SPacketSpawnObject packet) {
209+
if (this.entity == null || !this.breakDelayMS.isPassedMS(settingBreakDelay.getValue().intValue())) {
210+
return;
211+
}
212+
216213
CPacketUseEntity attack = new CPacketUseEntity();
217214
attack.entityId = packet.getEntityID();
218215
attack.action = CPacketUseEntity.Action.ATTACK;
219216
attack.hand = this.handAttack;
220217

221218
BlockPos pos = new BlockPos(packet.getX(), packet.getY(), packet.getZ());
222-
boolean mustBreak = false;
219+
boolean in = this.placeCount.contains(pos.down());
220+
boolean mustBreak = this.placeCount.contains(pos.down());
223221

224222
if (!mustBreak) {
225223
float damage = 0.5f;
226224

227225
if (mc.player.getDistance(pos.x, pos.y, pos.z) < settingBreakRange.getValue().floatValue()) {
228-
float entityDamage = CrystalUtil.calculateDamage(pos.z, pos.y, pos.z, this.entity);
226+
float entityDamage = CrystalUtil.calculateDamage(pos.x, pos.y, pos.z, this.entity);
229227
float selfDamage = CrystalUtil.calculateDamage(pos.x, pos.y, pos.z, mc.player);
230228

231229
if (entityDamage > damage && selfDamage < settingSelfDamage.getValue().floatValue()) {
@@ -244,53 +242,21 @@ public void doBreakCrystal(SPacketSpawnObject packet) {
244242
mc.player.connection.sendPacket(new CPacketAnimation(EnumHand.MAIN_HAND));
245243
}
246244

247-
this.hitCount.add(attack.entityId);
248-
this.placeCount.remove(pos);
249-
}
250-
251-
@Listener(priority = ListenerPriority.HIGHEST)
252-
public void onPacketReceive(PacketEvent.Receive event) {
253-
if (event.getPacket() instanceof SPacketSpawnObject && settingPredict.getValue()) {
254-
final SPacketSpawnObject packet = (SPacketSpawnObject) event.getPacket();
255-
final BlockPos pos = new BlockPos(packet.getX(), packet.getY(), packet.getZ()).down();
256-
257-
if (packet.getType() == 51 && this.placeCount.contains(pos)) {
258-
final CPacketUseEntity attack = new CPacketUseEntity();
259-
260-
attack.entityId = packet.getEntityID();
261-
attack.action = CPacketUseEntity.Action.ATTACK;
262-
attack.hand = this.handAttack;
263-
264-
mc.player.connection.sendPacket(attack);
265-
mc.player.connection.sendPacket(new CPacketAnimation(EnumHand.MAIN_HAND));
266-
267-
this.hitCount.add(packet.getEntityID());
268-
269-
this.placeCount.remove(pos);
270-
this.placeDelayMS.reset();
271-
this.breakDelayMS.reset();
272-
}
245+
if (in) {
246+
this.placeCount.remove(pos.down());
273247
}
274248

275-
if (event.getPacket() instanceof SPacketSoundEffect && settingNoSoundDelay.getValue()) {
276-
final SPacketSoundEffect packet = (SPacketSoundEffect) event.getPacket();
277-
278-
if (packet.getCategory() == SoundCategory.BLOCKS && packet.getSound() == SoundEvents.ENTITY_GENERIC_EXPLODE) {
279-
boolean hitList = false;
249+
this.breakDelayMS.reset();
250+
}
280251

281-
for (Entity entities : ISLClass.mc.world.loadedEntityList) {
282-
if (entities instanceof EntityEnderCrystal) {
283-
if (entities.getDistance(packet.getX(), packet.getY(), packet.getZ()) <= 6.0f) {
284-
entities.setDead();
285-
hitList = true;
286-
}
252+
public void doCleanCrystals(SPacketSoundEffect packet) {
253+
if (packet.getCategory() == SoundCategory.BLOCKS && packet.getSound() == SoundEvents.ENTITY_GENERIC_EXPLODE) {
254+
for (Entity entities : ISLClass.mc.world.loadedEntityList) {
255+
if (entities instanceof EntityEnderCrystal) {
256+
if (entities.getDistance(packet.getX(), packet.getY(), packet.getZ()) <= 6.0f) {
257+
entities.setDead();
287258
}
288259
}
289-
290-
if (hitList) {
291-
this.placeCount.clear();
292-
this.hitCount.clear();
293-
}
294260
}
295261
}
296262
}
@@ -307,6 +273,11 @@ public void onDirectTick() {
307273
if (!settingIncreaseTicks.getValue() && (this.isCrystalInMainHand || this.isCrystalInOffhand) && this.isEntityTargeted(this.entity)) {
308274
this.update();
309275
}
276+
277+
if (this.lastPlaceBreakedPos != null) {
278+
this.placeCount.remove(this.lastPlaceBreakedPos);
279+
this.lastPlaceBreakedPos = null;
280+
}
310281
}
311282

312283
@Listener(priority = ListenerPriority.LOW)
@@ -358,52 +329,23 @@ public void onClientTickEvent(ClientTickEvent event) {
358329
}
359330

360331
protected void update() {
361-
if (this.breakDelayMS.isPassedMS(settingBreakDelay.getValue().floatValue())) {
362-
switch (settingBreakPriority.getValue().intValue()) {
363-
case 1: {
364-
this.breakPacket.entityId = -1;
365-
this.breakPacket.action = CPacketUseEntity.Action.ATTACK;
366-
this.breakPacket.hand = this.handAttack;
367-
mc.player.connection.sendPacket(this.breakPacket);
368-
this.breakDelayMS.reset();
369-
break;
370-
}
371-
case 3: {
372-
if (this.breakDelayMS.isPassedMS(settingBreakDelay.getValue().floatValue() * 5)) {
373-
this.entityID = this.findCrystalBreak();
374-
if (this.entityID != -1) {
375-
this.breakPacket.entityId = this.entityID;
376-
this.breakPacket.action = CPacketUseEntity.Action.ATTACK;
377-
this.breakPacket.hand = this.handAttack;
378-
379-
mc.player.connection.sendPacket(this.breakPacket);
380-
if (settingBreakAnimation.getValue()) {
381-
mc.player.connection.sendPacket(new CPacketAnimation(EnumHand.MAIN_HAND));
382-
}
383-
384-
//this.hitCount.add(this.breakPacket.entityId);
385-
this.breakDelayMS.reset();
386-
}
387-
}
388-
break;
332+
boolean predict = settingPredict.getValue();
333+
TurokTick breakDelay = predict ? this.asyncBreakDelayMS : this.breakDelayMS;
334+
int delay = predict ? settingBreakAsyncDelay.getValue().intValue() : settingBreakDelay.getValue().intValue();
335+
336+
if (breakDelay.isPassedMS(delay)) {
337+
this.entityID = this.findCrystalBreak();
338+
if (this.entityID != -1) {
339+
this.breakPacket.entityId = this.entityID;
340+
this.breakPacket.action = CPacketUseEntity.Action.ATTACK;
341+
this.breakPacket.hand = this.handAttack;
342+
343+
mc.player.connection.sendPacket(this.breakPacket);
344+
if (settingBreakAnimation.getValue()) {
345+
mc.player.connection.sendPacket(new CPacketAnimation(EnumHand.MAIN_HAND));
389346
}
390-
default: {
391-
this.entityID = this.findCrystalBreak();
392-
if (this.entityID != -1) {
393-
this.breakPacket.entityId = this.entityID;
394-
this.breakPacket.action = CPacketUseEntity.Action.ATTACK;
395-
this.breakPacket.hand = this.handAttack;
396-
397-
mc.player.connection.sendPacket(this.breakPacket);
398-
if (settingBreakAnimation.getValue()) {
399-
mc.player.connection.sendPacket(new CPacketAnimation(EnumHand.MAIN_HAND));
400-
}
401347

402-
this.hitCount.add(this.breakPacket.entityId);
403-
this.breakDelayMS.reset();
404-
}
405-
break;
406-
}
348+
breakDelay.reset();
407349
}
408350
}
409351

@@ -433,7 +375,10 @@ protected void update() {
433375
this.placePacket.position = this.position;
434376

435377
mc.player.connection.sendPacket(this.placePacket);
436-
mc.player.connection.sendPacket(new CPacketAnimation(this.placePacket.getHand()));
378+
379+
if (settingPlaceAnimation.getValue()) {
380+
mc.player.connection.sendPacket(new CPacketAnimation(this.placePacket.getHand()));
381+
}
437382

438383
this.placeCount.add(this.position);
439384
this.placeDelayMS.reset();

src/main/java/rina/onepop/club/mixin/mixins/network/MixinNetworkManager.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package rina.onepop.club.mixin.mixins.network;
22

33
import net.minecraft.network.play.client.CPacketUseEntity;
4+
import net.minecraft.network.play.server.SPacketSoundEffect;
45
import net.minecraft.network.play.server.SPacketSpawnObject;
56
import rina.onepop.club.Onepop;
7+
import rina.onepop.club.api.util.chat.ChatUtil;
68
import rina.onepop.club.client.event.network.PacketEvent;
79
import io.netty.channel.ChannelHandlerContext;
810
import net.minecraft.network.NetworkManager;
@@ -13,7 +15,7 @@
1315
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1416
import rina.onepop.club.client.module.combat.autocrystalrewrite.ModuleAutoCrystalRewrite;
1517

16-
import static rina.onepop.club.client.module.combat.autocrystalrewrite.ModuleAutoCrystalRewrite.settingBreakPriority;
18+
import static rina.onepop.club.client.module.combat.autocrystalrewrite.ModuleAutoCrystalRewrite.*;
1719

1820
/**
1921
* @author SrRina
@@ -34,12 +36,15 @@ public void onSendPacket(Packet<?> packet, CallbackInfo callbackInfo) {
3436

3537
@Inject(method = "channelRead0", at = @At("HEAD"), cancellable = true)
3638
public void onReceivePacket(ChannelHandlerContext context, Packet<?> packet, CallbackInfo callbackInfo) {
37-
if (packet instanceof SPacketSpawnObject && ((SPacketSpawnObject) packet).getEntityID() == 51 && settingBreakPriority.getValue().intValue() == 3) {
39+
if (settingPredict.getValue() && packet instanceof SPacketSpawnObject && ((SPacketSpawnObject) packet).getType() == 51) {
3840
ModuleAutoCrystalRewrite.INSTANCE.doBreakCrystal((SPacketSpawnObject) packet);
3941
}
4042

41-
final PacketEvent event = new PacketEvent.Receive(packet);
43+
if (settingNoSoundDelay.getValue() && packet instanceof SPacketSoundEffect) {
44+
ModuleAutoCrystalRewrite.INSTANCE.doCleanCrystals((SPacketSoundEffect) packet);
45+
}
4246

47+
final PacketEvent event = new PacketEvent.Receive(packet);
4348
Onepop.getPomeloEventManager().dispatchEvent(event);
4449

4550
if (event.isCanceled()) {

0 commit comments

Comments
 (0)