Skip to content

Commit

Permalink
Honker - No longer spams horns when nobody's around.
Browse files Browse the repository at this point in the history
- unless of course you enable the new 'When Alone' option.
Go ahead, I won't judge.
  • Loading branch information
0xTas committed Apr 7, 2024
1 parent 204eb44 commit 097e5ac
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/main/java/dev/stardust/modules/Honker.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import dev.stardust.Stardust;
import net.minecraft.util.Hand;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NbtElement;
import net.minecraft.item.ItemStack;
Expand All @@ -15,6 +14,7 @@
import meteordevelopment.orbit.EventHandler;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import net.minecraft.entity.player.PlayerEntity;
import meteordevelopment.meteorclient.utils.Utils;
import net.minecraft.client.network.PlayerListEntry;
import meteordevelopment.meteorclient.settings.Setting;
import net.minecraft.client.network.ClientPlayerEntity;
Expand Down Expand Up @@ -60,7 +60,17 @@ public Honker() {
.name("Horn Spam")
.description("Spam the desired horn as soon as it's done cooling down (every 7 seconds.)")
.defaultValue(false)
.onChanged(it -> {if (it) honkDesiredHorn();})
.onChanged(it -> { if (it) this.ticksSinceUsedHorn = 420; })
.build()
);

private final Setting<Boolean> hornSpamAlone = settings.getDefaultGroup().add(
new BoolSetting.Builder()
.name("When Alone")
.description("If you really want to, I guess..")
.defaultValue(false)
.visible(hornSpam::get)
.onChanged(it -> { if (it) this.ticksSinceUsedHorn = 420; })
.build()
);

Expand Down Expand Up @@ -147,6 +157,10 @@ public void onActivate() {

for (Entity entity : mc.world.getEntities()) {
if (entity instanceof PlayerEntity && !(entity instanceof ClientPlayerEntity)) {
if (ignoreFakes.get()) {
Collection<PlayerListEntry> players = mc.player.networkHandler.getPlayerList();
if (players.stream().noneMatch(entry -> entry.getProfile().getId().equals(entity.getUuid()))) continue;
}
honkDesiredHorn();
break;
}
Expand Down Expand Up @@ -174,10 +188,23 @@ private void onEntityAdd(EntityAddedEvent event) {

@EventHandler
private void onTick(TickEvent.Post event) {
if (!hornSpam.get() || mc.player == null) return;
if (!hornSpam.get() || mc.player == null || mc.world == null) return;

boolean playerNearby = false;
for (Entity entity : mc.world.getEntities()) {
if (entity instanceof PlayerEntity && !(entity instanceof ClientPlayerEntity)) {
if (ignoreFakes.get()) {
Collection<PlayerListEntry> players = mc.player.networkHandler.getPlayerList();
if (players.stream().noneMatch(entry -> entry.getProfile().getId().equals(entity.getUuid()))) continue;
}
playerNearby = true;
break;
}
}

if (!playerNearby && !hornSpamAlone.get()) return;
Item activeItem = mc.player.getActiveItem().getItem();
if (activeItem.isFood() || activeItem == Items.BOW || activeItem == Items.TRIDENT && mc.mouse.wasRightButtonClicked()) return;
if (activeItem.isFood() || Utils.isThrowable(activeItem) && mc.player.getItemUseTime() > 0) return;

++ticksSinceUsedHorn;
if (ticksSinceUsedHorn > 150) {
Expand Down

0 comments on commit 097e5ac

Please sign in to comment.