| 1 | package com.jellypudding.offlineclient.modules.combat;
|
| 2 |
|
| 3 | import com.jellypudding.offlineclient.OfflineClient;
|
| 4 | import com.jellypudding.offlineclient.event.Subscribe;
|
| 5 | import com.jellypudding.offlineclient.event.events.EntityAddedEvent;
|
| 6 | import com.jellypudding.offlineclient.event.events.PacketSendEvent;
|
| 7 | import com.jellypudding.offlineclient.event.events.Render2DEvent;
|
| 8 | import com.jellypudding.offlineclient.event.events.Render3DEvent;
|
| 9 | import com.jellypudding.offlineclient.event.events.TickEvent;
|
| 10 | import com.jellypudding.offlineclient.module.Category;
|
| 11 | import com.jellypudding.offlineclient.module.Module;
|
| 12 | import com.jellypudding.offlineclient.render.BoxStyle;
|
| 13 | import com.jellypudding.offlineclient.render.DrawBatch;
|
| 14 | import com.jellypudding.offlineclient.render.WorldToScreen;
|
| 15 | import com.jellypudding.offlineclient.setting.BoolSetting;
|
| 16 | import com.jellypudding.offlineclient.setting.ChoiceListSetting;
|
| 17 | import com.jellypudding.offlineclient.setting.ColorSetting;
|
| 18 | import com.jellypudding.offlineclient.setting.EnumSetting;
|
| 19 | import com.jellypudding.offlineclient.setting.KeybindSetting;
|
| 20 | import com.jellypudding.offlineclient.setting.NumberSetting;
|
| 21 | import com.jellypudding.offlineclient.setting.RegistryListSetting;
|
| 22 | import com.jellypudding.offlineclient.util.BlockUtil;
|
| 23 | import com.jellypudding.offlineclient.util.ColorUtil;
|
| 24 | import com.jellypudding.offlineclient.util.EntityUtil;
|
| 25 | import com.jellypudding.offlineclient.util.ExplosionUtil;
|
| 26 | import com.jellypudding.offlineclient.util.InventoryUtil;
|
| 27 | import com.jellypudding.offlineclient.util.InventoryUtil.HotbarLoan;
|
| 28 | import com.jellypudding.offlineclient.util.InventoryUtil.SlotSwap;
|
| 29 | import com.jellypudding.offlineclient.util.ItemUtil;
|
| 30 | import com.jellypudding.offlineclient.util.RenderUtil;
|
| 31 | import com.jellypudding.offlineclient.util.RotationManager;
|
| 32 | import com.jellypudding.offlineclient.util.RotationPriority;
|
| 33 | import com.jellypudding.offlineclient.util.SwingMode;
|
| 34 | import com.jellypudding.offlineclient.util.TickRate;
|
| 35 | import net.minecraft.core.BlockPos;
|
| 36 | import net.minecraft.core.Direction;
|
| 37 | import net.minecraft.core.registries.BuiltInRegistries;
|
| 38 | import net.minecraft.network.protocol.game.ServerboundAttackPacket;
|
| 39 | import net.minecraft.network.protocol.game.ServerboundSetCarriedItemPacket;
|
| 40 | import net.minecraft.world.InteractionHand;
|
| 41 | import net.minecraft.world.entity.Entity;
|
| 42 | import net.minecraft.world.entity.EntityType;
|
| 43 | import net.minecraft.world.entity.EntityTypes;
|
| 44 | import net.minecraft.world.entity.EquipmentSlot;
|
| 45 | import net.minecraft.world.entity.LivingEntity;
|
| 46 | import net.minecraft.world.entity.ai.attributes.Attributes;
|
| 47 | import net.minecraft.world.entity.boss.enderdragon.EndCrystal;
|
| 48 | import net.minecraft.world.entity.player.Player;
|
| 49 | import net.minecraft.world.item.BowItem;
|
| 50 | import net.minecraft.world.item.ItemStack;
|
| 51 | import net.minecraft.world.item.Items;
|
| 52 | import net.minecraft.world.level.block.Block;
|
| 53 | import net.minecraft.world.level.block.Blocks;
|
| 54 | import net.minecraft.world.phys.AABB;
|
| 55 | import net.minecraft.world.phys.BlockHitResult;
|
| 56 | import net.minecraft.world.phys.Vec3;
|
| 57 |
|
| 58 | import java.util.ArrayList;
|
| 59 | import java.util.HashMap;
|
| 60 | import java.util.List;
|
| 61 | import java.util.Locale;
|
| 62 | import java.util.Map;
|
| 63 |
|
| 64 | // Every candidate spot is scored with the game's own explosion maths against every target.
|
| 65 | public final class CrystalAura extends Module {
|
| 66 |
|
| 67 | public enum Switch { NORMAL, SILENT, NONE }
|
| 68 |
|
| 69 | public enum Support { OFF, ACCURATE, FAST }
|
| 70 |
|
| 71 | public enum Pause { BOTH, PLACE, BREAK, NONE }
|
| 72 |
|
| 73 | public enum YawSteps { BREAK, ALL }
|
| 74 |
|
| 75 | public enum RenderMode { NORMAL, SMOOTH, FADING, GRADIENT, NONE }
|
| 76 |
|
| 77 | // How far ahead of a moving target the damage is scored.
|
| 78 | private static final double LEAD_TICKS = 1;
|
| 79 |
|
| 80 | // Ticks a placed spot stays on the own crystal list.
|
| 81 | private static final int OWN_MEMORY = 100;
|
| 82 |
|
| 83 | // Ticks between attempts to pull crystals up from the backpack.
|
| 84 | private static final int REFILL_DELAY = 4;
|
| 85 |
|
| 86 | // Ticks a hit crystal is treated as already gone before a retry.
|
| 87 | private static final int REMOVED_MEMORY = 3;
|
| 88 |
|
| 89 | // Ticks that other combat modules stand aside for after a real action.
|
| 90 | private static final int BUSY_TICKS = 8;
|
| 91 |
|
| 92 | // How far around a target a support block may be laid.
|
| 93 | private static final int SUPPORT_REACH = 3;
|
| 94 | private static final int SUPPORT_RISE = 2;
|
| 95 |
|
| 96 | private final NumberSetting targetRange = new NumberSetting("Target range",
|
| 97 | "How far away targets are considered.", 10, 2, 16, 0.5, " blocks");
|
| 98 | private final BoolSetting players = new BoolSetting("Players",
|
| 99 | "Attack other players.", true);
|
| 100 | private final RegistryListSetting<EntityType<?>> mobs = new RegistryListSetting<>("Mobs",
|
| 101 | "Other kinds of entity to attack.", BuiltInRegistries.ENTITY_TYPE,
|
| 102 | List.of(EntityTypes.WARDEN, EntityTypes.WITHER));
|
| 103 | private final BoolSetting ignoreNakeds = new BoolSetting("Ignore nakeds",
|
| 104 | "Leaves players with no armour and empty hands alone.", false);
|
| 105 |
|
| 106 | private final NumberSetting placeRange = new NumberSetting("Place range",
|
| 107 | "Reach for placing crystals.", 4.5, 1, 6, 0.1, " blocks");
|
| 108 | private final NumberSetting placeWallsRange = new NumberSetting("Place walls range",
|
| 109 | "Reach for placing on a spot hidden behind blocks.", 3.5, 0, 6, 0.1, " blocks");
|
| 110 | private final NumberSetting breakRange = new NumberSetting("Break range",
|
| 111 | "Reach for hitting crystals.", 4.5, 1, 6, 0.1, " blocks");
|
| 112 | private final NumberSetting breakWallsRange = new NumberSetting("Break walls range",
|
| 113 | "Reach for crystals hidden behind blocks.", 3.5, 0, 6, 0.1, " blocks");
|
| 114 |
|
| 115 | private final BoolSetting doPlace = new BoolSetting("Place",
|
| 116 | "Place crystals near targets.", true);
|
| 117 | private final NumberSetting placeDelay = new NumberSetting("Place delay",
|
| 118 | "Ticks to wait between placements.", 2, 0, 10, 1, " ticks")
|
| 119 | .under(doPlace);
|
| 120 | private final BoolSetting multiPlace = new BoolSetting("Multi place",
|
| 121 | "Place another crystal whilst one worth hitting is still up.", false)
|
| 122 | .under(doPlace);
|
| 123 | private final BoolSetting oldPlacement = new BoolSetting("Old placement",
|
| 124 | "Require two air blocks above the base like older servers.", false)
|
| 125 | .under(doPlace);
|
| 126 | private final EnumSetting<Support> support = new EnumSetting<>("Support",
|
| 127 | "Places obsidian under a target when there is nothing to crystal. Taken from the inventory when the hotbar has none.", Support.ACCURATE)
|
| 128 | .describe(Support.OFF, "Never places support blocks.")
|
| 129 | .describe(Support.ACCURATE, "Scores support spots against every target.")
|
| 130 | .describe(Support.FAST, "Scores support spots against the nearest target only.")
|
| 131 | .under(doPlace);
|
| 132 | private final NumberSetting supportDelay = new NumberSetting("Support delay",
|
| 133 | "Ticks to wait after a support block before the crystal goes on it. Zero does both in one tick.", 1, 0, 10, 1, " ticks")
|
| 134 | .under(support, Support.ACCURATE, Support.FAST);
|
| 135 |
|
| 136 | private final BoolSetting doBreak = new BoolSetting("Break",
|
| 137 | "Hit crystals to set them off.", true);
|
| 138 | private final NumberSetting breakDelay = new NumberSetting("Break delay",
|
| 139 | "Ticks to wait between hits.", 1, 0, 10, 1, " ticks")
|
| 140 | .under(doBreak);
|
| 141 | private final NumberSetting attackFrequency = new NumberSetting("Attack frequency",
|
| 142 | "Most hits a second.", 25, 1, 30, 1)
|
| 143 | .under(doBreak);
|
| 144 | private final NumberSetting breakAttempts = new NumberSetting("Break attempts",
|
| 145 | "Gives up on a crystal after this many hits.", 2, 1, 5, 1)
|
| 146 | .under(doBreak);
|
| 147 | private final NumberSetting ticksExisted = new NumberSetting("Ticks existed",
|
| 148 | "Youngest a crystal may be before it is hit.", 0, 0, 20, 1, " ticks")
|
| 149 | .under(doBreak);
|
| 150 | private final BoolSetting fastBreak = new BoolSetting("Fast break",
|
| 151 | "Hits a crystal the moment it appears rather than on the next tick.", true)
|
| 152 | .under(doBreak);
|
| 153 | private final BoolSetting smartDelay = new BoolSetting("Smart delay",
|
| 154 | "Skip a hit whilst the target is still in damage immunity.", true)
|
| 155 | .under(doBreak);
|
| 156 | private final BoolSetting antiWeakness = new BoolSetting("Anti weakness",
|
| 157 | "Swap to a tool that still breaks crystals whilst you have weakness.", true)
|
| 158 | .under(doBreak);
|
| 159 | private final BoolSetting onlyOwn = new BoolSetting("Only own",
|
| 160 | "Only hit crystals you placed yourself.", false)
|
| 161 | .under(doBreak);
|
| 162 |
|
| 163 | private final NumberSetting minDamage = new NumberSetting("Min damage",
|
| 164 | "Only act when a target would take at least this much.", 6, 0, 20, 0.5);
|
| 165 | private final NumberSetting maxSelfDamage = new NumberSetting("Max self damage",
|
| 166 | "Never take more than this from your own crystal.", 8, 0, 20, 0.5);
|
| 167 | private final BoolSetting antiSuicide = new BoolSetting("Anti suicide",
|
| 168 | "Never touch a crystal that could kill you.", true);
|
| 169 | private final BoolSetting predict = new BoolSetting("Predict",
|
| 170 | "Score the damage where a moving target is heading.", true);
|
| 171 |
|
| 172 | private final BoolSetting finisher = new BoolSetting("Finisher",
|
| 173 | "Drops the minimum damage once a target is nearly dead or their armour is about to give out.", true);
|
| 174 | private final NumberSetting finisherHealth = new NumberSetting("Finisher health",
|
| 175 | "Health plus absorption at or below this counts as nearly dead.", 8, 1, 20, 0.5)
|
| 176 | .under(finisher);
|
| 177 | private final NumberSetting finisherArmour = new NumberSetting("Finisher armour",
|
| 178 | "Armour durability at or below this counts as giving out.", 15, 1, 100, 1, "%")
|
| 179 | .under(finisher);
|
| 180 | private final BoolSetting finisherMissing = new BoolSetting("Finisher missing armour",
|
| 181 | "An empty armour slot also counts.", false)
|
| 182 | .under(finisher);
|
| 183 | private final KeybindSetting finisherKey = new KeybindSetting("Finisher key",
|
| 184 | "Holding this key forces the finisher on.", KeybindSetting.UNBOUND);
|
| 185 |
|
| 186 | private final EnumSetting<Switch> autoSwitch = new EnumSetting<>("Auto switch",
|
| 187 | "How crystals get into your hand.", Switch.SILENT)
|
| 188 | .describe(Switch.NORMAL, "Swaps to the crystals and stays on them.")
|
| 189 | .describe(Switch.SILENT, "Swaps for the placement and straight back.")
|
| 190 | .describe(Switch.NONE, "Never swaps. Only places whilst you hold crystals.");
|
| 191 | private final NumberSetting switchDelay = new NumberSetting("Switch delay",
|
| 192 | "Ticks to wait after a hotbar swap before hitting.", 0, 0, 10, 1, " ticks")
|
| 193 | .under(autoSwitch, Switch.NORMAL, Switch.SILENT);
|
| 194 | private final BoolSetting noGapSwitch = new BoolSetting("No gap switch",
|
| 195 | "Never swaps away from a golden apple in either hand.", true)
|
| 196 | .under(autoSwitch, Switch.NORMAL);
|
| 197 | private final BoolSetting noBowSwitch = new BoolSetting("No bow switch",
|
| 198 | "Never swaps away from a bow in either hand.", true)
|
| 199 | .under(autoSwitch, Switch.NORMAL);
|
| 200 |
|
| 201 | private final EnumSetting<Pause> pauseOnUse = new EnumSetting<>("Pause on use",
|
| 202 | "What to hold off whilst eating or drawing a bow.", Pause.BOTH)
|
| 203 | .describe(Pause.BOTH, "Neither places nor hits.")
|
| 204 | .describe(Pause.PLACE, "Stops placing but still hits.")
|
| 205 | .describe(Pause.BREAK, "Stops hitting but still places.")
|
| 206 | .describe(Pause.NONE, "Carries on regardless.");
|
| 207 | private final EnumSetting<Pause> pauseOnMine = new EnumSetting<>("Pause on mine",
|
| 208 | "What to hold off whilst you mine a block.", Pause.NONE)
|
| 209 | .describe(Pause.BOTH, "Neither places nor hits.")
|
| 210 | .describe(Pause.PLACE, "Stops placing but still hits.")
|
| 211 | .describe(Pause.BREAK, "Stops hitting but still places.")
|
| 212 | .describe(Pause.NONE, "Carries on regardless.");
|
| 213 | private final BoolSetting pauseOnLag = new BoolSetting("Pause on lag",
|
| 214 | "Holds off whilst the server has stopped ticking.", true);
|
| 215 | private final NumberSetting lagLimit = new NumberSetting("Lag limit",
|
| 216 | "How long the server may go quiet before that counts as lag.", 1000, 250, 5000, 250, " ms")
|
| 217 | .under(pauseOnLag);
|
| 218 | private final ChoiceListSetting pauseModules = new ChoiceListSetting("Pause modules",
|
| 219 | "Holds off whilst any of these modules is on.", CrystalAura::moduleNames);
|
| 220 | private final NumberSetting pauseHealth = new NumberSetting("Pause health",
|
| 221 | "Holds off whilst your health plus absorption is at or below this. Zero never pauses.", 5, 0, 36, 0.5);
|
| 222 |
|
| 223 | private final BoolSetting rotate = new BoolSetting("Rotate",
|
| 224 | "Send a look packet towards the crystal spot.", true);
|
| 225 | private final NumberSetting yawSteps = new NumberSetting("Yaw steps",
|
| 226 | "Most degrees the server rotation turns in one tick.", 180, 1, 180, 1, " degrees")
|
| 227 | .under(rotate);
|
| 228 | private final EnumSetting<YawSteps> yawStepsMode = new EnumSetting<>("Yaw steps mode",
|
| 229 | "Which turns the yaw steps limit applies to.", YawSteps.BREAK)
|
| 230 | .describe(YawSteps.BREAK, "Only the turn to hit a crystal.")
|
| 231 | .describe(YawSteps.ALL, "Placing turns too.")
|
| 232 | .under(rotate);
|
| 233 | private final EnumSetting<SwingMode> swing = SwingMode.setting(SwingMode.BOTH);
|
| 234 |
|
| 235 | private final EnumSetting<RenderMode> renderMode = new EnumSetting<>("Render",
|
| 236 | "How the placement box is drawn.", RenderMode.NORMAL)
|
| 237 | .describe(RenderMode.NORMAL, "A box on the base block.")
|
| 238 | .describe(RenderMode.SMOOTH, "The box slides between spots.")
|
| 239 | .describe(RenderMode.FADING, "The box fades out after a placement.")
|
| 240 | .describe(RenderMode.GRADIENT, "A box that fades towards its top.")
|
| 241 | .describe(RenderMode.NONE, "Nothing is drawn.");
|
| 242 | private final BoxStyle boxStyle = new BoxStyle(BoxStyle.Shape.BOTH, 280);
|
| 243 | private final BoolSetting renderPlace = new BoolSetting("Show placements",
|
| 244 | "Keeps the box on the spot just placed on.", true)
|
| 245 | .under(renderMode, RenderMode.NORMAL, RenderMode.SMOOTH, RenderMode.FADING, RenderMode.GRADIENT);
|
| 246 | private final NumberSetting placeTime = new NumberSetting("Place time",
|
| 247 | "Ticks the box stays after a placement.", 10, 0, 20, 1, " ticks")
|
| 248 | .under(renderPlace);
|
| 249 | private final BoolSetting renderBreak = new BoolSetting("Show breaks",
|
| 250 | "Also draws the base of the crystal just hit.", false)
|
| 251 | .under(renderMode, RenderMode.NORMAL, RenderMode.SMOOTH, RenderMode.FADING, RenderMode.GRADIENT);
|
| 252 | private final NumberSetting breakTime = new NumberSetting("Break time",
|
| 253 | "Ticks the box stays after a hit.", 13, 0, 20, 1, " ticks")
|
| 254 | .under(renderBreak);
|
| 255 | private final NumberSetting smoothness = new NumberSetting("Smoothness",
|
| 256 | "Ticks the box takes to slide to a new spot.", 10, 1, 20, 1, " ticks")
|
| 257 | .under(renderMode, RenderMode.SMOOTH);
|
| 258 | private final NumberSetting gradientHeight = new NumberSetting("Gradient height",
|
| 259 | "How tall the fading box is.", 0.7, 0.1, 1, 0.05, " blocks")
|
| 260 | .under(renderMode, RenderMode.GRADIENT);
|
| 261 | private final NumberSetting fadeTime = new NumberSetting("Fade time",
|
| 262 | "Ticks the box takes to fade away.", 10, 1, 20, 1, " ticks")
|
| 263 | .under(renderMode, RenderMode.FADING);
|
| 264 | private final BoolSetting showDamage = new BoolSetting("Show damage",
|
| 265 | "Writes the expected damage over the box.", true)
|
| 266 | .under(renderMode, RenderMode.NORMAL, RenderMode.SMOOTH, RenderMode.FADING, RenderMode.GRADIENT);
|
| 267 | private final ColorSetting damageColor = new ColorSetting("Damage colour",
|
| 268 | "Colour of the damage number.", 0, 0, 1, false)
|
| 269 | .under(showDamage);
|
| 270 | private final NumberSetting damageScale = new NumberSetting("Damage scale",
|
| 271 | "Size of the damage number.", 1.25, 1, 4, 0.25, "x")
|
| 272 | .under(showDamage);
|
| 273 |
|
| 274 | private final SlotSwap slots = new SlotSwap();
|
| 275 | private final HotbarLoan loan = new HotbarLoan();
|
| 276 |
|
| 277 | private int placeTimer;
|
| 278 | private int breakTimer;
|
| 279 | private int supportTimer;
|
| 280 | private int refillTimer;
|
| 281 | private int busyTimer;
|
| 282 | private int switchTimer;
|
| 283 | private long lastHitAt;
|
| 284 | private String targetName;
|
| 285 | private String status;
|
| 286 |
|
| 287 | // True for the tick when some target is weak enough to ignore Min damage.
|
| 288 | private boolean finishing;
|
| 289 |
|
| 290 | // The targets and every other entity worth looking at this tick.
|
| 291 | private final List<LivingEntity> targets = new ArrayList<>();
|
| 292 | private final List<Entity> entities = new ArrayList<>();
|
| 293 |
|
| 294 | // Spots placed on with the ticks left before they are forgotten.
|
| 295 | private final Map<BlockPos, Integer> ownSpots = new HashMap<>();
|
| 296 |
|
| 297 | // Crystals just hit with the ticks left before they count as still there.
|
| 298 | private final Map<Integer, Integer> removed = new HashMap<>();
|
| 299 |
|
| 300 | // Hits landed on each crystal that refused to go.
|
| 301 | private final Map<Integer, Integer> attempts = new HashMap<>();
|
| 302 |
|
| 303 | // What the box is drawn on and the damage it promised.
|
| 304 | private BlockPos drawn;
|
| 305 | private float drawnDamage;
|
| 306 | private int drawnTicks;
|
| 307 | private Vec3 slideFrom;
|
| 308 | private Vec3 slideTo;
|
| 309 | private int slideTicks;
|
| 310 | private Vec3 damageAt;
|
| 311 |
|
| 312 | public CrystalAura() {
|
| 313 | super("CrystalAura", "Places end crystals near enemies and blows them up.", Category.COMBAT);
|
| 314 | addSettings(targetRange, players, mobs, ignoreNakeds,
|
| 315 | placeRange, placeWallsRange, breakRange, breakWallsRange,
|
| 316 | doPlace, placeDelay, multiPlace, oldPlacement, support, supportDelay,
|
| 317 | doBreak, breakDelay, attackFrequency, breakAttempts, ticksExisted, fastBreak,
|
| 318 | smartDelay, antiWeakness, onlyOwn,
|
| 319 | minDamage, maxSelfDamage, antiSuicide, predict,
|
| 320 | finisher, finisherHealth, finisherArmour, finisherMissing, finisherKey,
|
| 321 | autoSwitch, switchDelay, noGapSwitch, noBowSwitch,
|
| 322 | pauseOnUse, pauseOnMine, pauseOnLag, lagLimit, pauseModules, pauseHealth,
|
| 323 | rotate, yawSteps, yawStepsMode, swing,
|
| 324 | renderMode);
|
| 325 | addSettings(boxStyle.settings());
|
| 326 | addSettings(renderPlace, placeTime, renderBreak, breakTime, smoothness, gradientHeight,
|
| 327 | fadeTime, showDamage, damageColor, damageScale);
|
| 328 | searchTags("end crystal", "cpvp", "ca");
|
| 329 | }
|
| 330 |
|
| 331 | private static List<String> moduleNames() {
|
| 332 | List<String> names = new ArrayList<>();
|
| 333 | for (Module module : OfflineClient.INSTANCE.getModuleManager().getAll()) {
|
| 334 | if (module.isTogglable()) {
|
| 335 | names.add(module.getName());
|
| 336 | }
|
| 337 | }
|
| 338 | return names;
|
| 339 | }
|
| 340 |
|
| 341 | @Override
|
| 342 | public String getSuffix() {
|
| 343 | return targetName == null ? null : suffix(targetName, status);
|
| 344 | }
|
| 345 |
|
| 346 | public boolean hasTarget() {
|
| 347 | return targetName != null;
|
| 348 | }
|
| 349 |
|
| 350 | // True only for a short window after a real place or break.
|
| 351 | // Other combat modules stand aside during that window.
|
| 352 | public boolean isActing() {
|
| 353 | return busyTimer > 0;
|
| 354 | }
|
| 355 |
|
| 356 | @Override
|
| 357 | protected void onEnable() {
|
| 358 | placeTimer = 0;
|
| 359 | breakTimer = 0;
|
| 360 | supportTimer = 0;
|
| 361 | refillTimer = 0;
|
| 362 | busyTimer = 0;
|
| 363 | switchTimer = 0;
|
| 364 | lastHitAt = 0;
|
| 365 | slots.forget();
|
| 366 | clearMemory();
|
| 367 | }
|
| 368 |
|
| 369 | @Override
|
| 370 | protected void onDisable() {
|
| 371 | busyTimer = 0;
|
| 372 | slots.restore();
|
| 373 | loan.giveBack();
|
| 374 | clearMemory();
|
| 375 | }
|
| 376 |
|
| 377 | private void clearMemory() {
|
| 378 | targetName = null;
|
| 379 | targets.clear();
|
| 380 | entities.clear();
|
| 381 | ownSpots.clear();
|
| 382 | removed.clear();
|
| 383 | attempts.clear();
|
| 384 | drawn = null;
|
| 385 | drawnTicks = 0;
|
| 386 | slideFrom = null;
|
| 387 | slideTo = null;
|
| 388 | }
|
| 389 |
|
| 390 | @Subscribe
|
| 391 | private void onTick(TickEvent event) {
|
| 392 | entities.clear();
|
| 393 | targets.clear();
|
| 394 | if (!inGame() || mc.player.isSpectator()) {
|
| 395 | targetName = null;
|
| 396 | return;
|
| 397 | }
|
| 398 | tickTimers();
|
| 399 | forgetOld();
|
| 400 |
|
| 401 | collectTargets();
|
| 402 | targetName = targets.isEmpty() ? null : nameOf(targets.getFirst());
|
| 403 | status = null;
|
| 404 | if (targets.isEmpty()) {
|
| 405 | restoreSlot();
|
| 406 | return;
|
| 407 | }
|
| 408 | String pause = pauseReason();
|
| 409 | if (pause != null) {
|
| 410 | restoreSlot();
|
| 411 | status = pause;
|
| 412 | return;
|
| 413 | }
|
| 414 |
|
| 415 | collectEntities();
|
| 416 | finishing = finisherKey.isHeld() || targets.stream().anyMatch(this::finishing);
|
| 417 |
|
| 418 | boolean hitSomething = false;
|
| 419 | if (doBreak.isOn() && !paused(Pause.BREAK) && breakTimer == 0) {
|
| 420 | hitSomething = breakBest();
|
| 421 | }
|
| 422 | if (doPlace.isOn() && !paused(Pause.PLACE) && placeTimer == 0
|
| 423 | && (multiPlace.isOn() || !worthHitting())) {
|
| 424 | placeBest();
|
| 425 | } else if (!hitSomething && !worthHitting()) {
|
| 426 | status = status == null ? "(waiting)" : status;
|
| 427 | }
|
| 428 | restoreSlot();
|
| 429 | }
|
| 430 |
|
| 431 | private void tickTimers() {
|
| 432 | placeTimer = Math.max(0, placeTimer - 1);
|
| 433 | breakTimer = Math.max(0, breakTimer - 1);
|
| 434 | supportTimer = Math.max(0, supportTimer - 1);
|
| 435 | refillTimer = Math.max(0, refillTimer - 1);
|
| 436 | busyTimer = Math.max(0, busyTimer - 1);
|
| 437 | switchTimer = Math.max(0, switchTimer - 1);
|
| 438 | if (drawnTicks > 0) {
|
| 439 | drawnTicks--;
|
| 440 | }
|
| 441 | if (slideTicks > 0) {
|
| 442 | slideTicks--;
|
| 443 | }
|
| 444 | }
|
| 445 |
|
| 446 | private void forgetOld() {
|
| 447 | ownSpots.entrySet().removeIf(entry -> {
|
| 448 | entry.setValue(entry.getValue() - 1);
|
| 449 | return entry.getValue() <= 0;
|
| 450 | });
|
| 451 | removed.entrySet().removeIf(entry -> {
|
| 452 | entry.setValue(entry.getValue() - 1);
|
| 453 | return entry.getValue() <= 0;
|
| 454 | });
|
| 455 | attempts.keySet().removeIf(id -> mc.level.getEntity(id) == null);
|
| 456 | }
|
| 457 |
|
| 458 | // The silent switch goes back at the end of the tick. Normal stays on the crystals.
|
| 459 | private void restoreSlot() {
|
| 460 | if (!autoSwitch.is(Switch.NORMAL) || targets.isEmpty()) {
|
| 461 | slots.restore();
|
| 462 | }
|
| 463 | }
|
| 464 |
|
| 465 | private String pauseReason() {
|
| 466 | if (pauseOnLag.isOn() && TickRate.INSTANCE.lagging(lagLimit.getInt())) {
|
| 467 | return "(lag)";
|
| 468 | }
|
| 469 | if (pauseHealth.getValue() > 0 && EntityUtil.totalHealth(mc.player) <= pauseHealth.getFloat()) {
|
| 470 | return "(low health)";
|
| 471 | }
|
| 472 | for (String name : pauseModules.getValue()) {
|
| 473 | Module module = OfflineClient.INSTANCE.getModuleManager().get(name);
|
| 474 | if (module != null && module.isEnabled()) {
|
| 475 | return "(" + module.getName() + ")";
|
| 476 | }
|
| 477 | }
|
| 478 | if (paused(Pause.BOTH)) {
|
| 479 | return "(paused)";
|
| 480 | }
|
| 481 | return null;
|
| 482 | }
|
| 483 |
|
| 484 | // True when the given half is held off by a use or a mine.
|
| 485 | private boolean paused(Pause half) {
|
| 486 | return halts(pauseOnUse.getValue(), half, mc.player.isUsingItem())
|
| 487 | || halts(pauseOnMine.getValue(), half, mc.gameMode.isDestroying());
|
| 488 | }
|
| 489 |
|
| 490 | private static boolean halts(Pause chosen, Pause half, boolean busy) {
|
| 491 | if (!busy || chosen == Pause.NONE) {
|
| 492 | return false;
|
| 493 | }
|
| 494 | return chosen == Pause.BOTH ? half == Pause.BOTH || half != Pause.NONE
|
| 495 | : chosen == half;
|
| 496 | }
|
| 497 |
|
| 498 | private void collectTargets() {
|
| 499 | double reach = targetRange.getValue();
|
| 500 | for (Entity entity : mc.level.entitiesForRendering()) {
|
| 501 | if (!(entity instanceof LivingEntity living) || entity == mc.player
|
| 502 | || !living.isAlive() || mc.player.distanceTo(entity) > reach) {
|
| 503 | continue;
|
| 504 | }
|
| 505 | if (entity instanceof Player player) {
|
| 506 | if (!players.isOn() || !EntityUtil.isEnemy(player)
|
| 507 | || (ignoreNakeds.isOn() && naked(player))) {
|
| 508 | continue;
|
| 509 | }
|
| 510 | } else if (!mobs.contains(entity.getType())) {
|
| 511 | continue;
|
| 512 | }
|
| 513 | targets.add(living);
|
| 514 | }
|
| 515 | targets.sort((a, b) -> Double.compare(mc.player.distanceToSqr(a), mc.player.distanceToSqr(b)));
|
| 516 | }
|
| 517 |
|
| 518 | private static boolean naked(Player player) {
|
| 519 | if (!player.getMainHandItem().isEmpty() || !player.getOffhandItem().isEmpty()) {
|
| 520 | return false;
|
| 521 | }
|
| 522 | for (EquipmentSlot slot : ItemUtil.ARMOR_SLOTS) {
|
| 523 | if (!player.getItemBySlot(slot).isEmpty()) {
|
| 524 | return false;
|
| 525 | }
|
| 526 | }
|
| 527 | return true;
|
| 528 | }
|
| 529 |
|
| 530 | private static String nameOf(LivingEntity target) {
|
| 531 | return target instanceof Player player ? EntityUtil.nameOf(player) : target.getName().getString();
|
| 532 | }
|
| 533 |
|
| 534 | private void collectEntities() {
|
| 535 | for (Entity entity : mc.level.entitiesForRendering()) {
|
| 536 | if (entity.isRemoved() || entity.isSpectator()) {
|
| 537 | continue;
|
| 538 | }
|
| 539 | if (entity instanceof EndCrystal && removed.containsKey(entity.getId())) {
|
| 540 | continue;
|
| 541 | }
|
| 542 | entities.add(entity);
|
| 543 | }
|
| 544 | }
|
| 545 |
|
| 546 | // True whilst a crystal that passes the damage checks is still standing.
|
| 547 | private boolean worthHitting() {
|
| 548 | return doBreak.isOn() && bestCrystal() != null;
|
| 549 | }
|
| 550 |
|
| 551 | private boolean breakBest() {
|
| 552 | if (!attackAllowed()) {
|
| 553 | return false;
|
| 554 | }
|
| 555 | EndCrystal best = bestCrystal();
|
| 556 | if (best == null) {
|
| 557 | return false;
|
| 558 | }
|
| 559 | return hit(best);
|
| 560 | }
|
| 561 |
|
| 562 | private boolean attackAllowed() {
|
| 563 | if (switchTimer > 0) {
|
| 564 | return false;
|
| 565 | }
|
| 566 | long gap = 1000 / attackFrequency.getInt();
|
| 567 | return System.currentTimeMillis() - lastHitAt >= gap;
|
| 568 | }
|
| 569 |
|
| 570 | private EndCrystal bestCrystal() {
|
| 571 | EndCrystal best = null;
|
| 572 | float bestDamage = 0;
|
| 573 | for (Entity entity : entities) {
|
| 574 | if (!(entity instanceof EndCrystal crystal) || !hittable(crystal)) {
|
| 575 | continue;
|
| 576 | }
|
| 577 | float damage = scoreOf(crystal.position());
|
| 578 | if (damage > bestDamage) {
|
| 579 | bestDamage = damage;
|
| 580 | best = crystal;
|
| 581 | }
|
| 582 | }
|
| 583 | return best;
|
| 584 | }
|
| 585 |
|
| 586 | private boolean hittable(EndCrystal crystal) {
|
| 587 | if (crystal.tickCount < ticksExisted.getInt()) {
|
| 588 | return false;
|
| 589 | }
|
| 590 | if (attempts.getOrDefault(crystal.getId(), 0) >= breakAttempts.getInt()) {
|
| 591 | return false;
|
| 592 | }
|
| 593 | if (onlyOwn.isOn() && !ownSpots.containsKey(crystal.blockPosition())) {
|
| 594 | return false;
|
| 595 | }
|
| 596 | Vec3 centre = crystal.getBoundingBox().getCenter();
|
| 597 | double reach = BlockUtil.canSee(centre) ? breakRange.getValue() : breakWallsRange.getValue();
|
| 598 | if (EntityUtil.reachDistance(mc.player, crystal) > reach) {
|
| 599 | return false;
|
| 600 | }
|
| 601 | if (smartDelay.isOn() && immune()) {
|
| 602 | return false;
|
| 603 | }
|
| 604 | return selfSafe(crystal.position());
|
| 605 | }
|
| 606 |
|
| 607 | // Damage during immunity drops to the difference and the crystal is wasted.
|
| 608 | private boolean immune() {
|
| 609 | for (LivingEntity target : targets) {
|
| 610 | if (target.hurtTime == 0) {
|
| 611 | return false;
|
| 612 | }
|
| 613 | }
|
| 614 | return true;
|
| 615 | }
|
| 616 |
|
| 617 | private boolean hit(EndCrystal crystal) {
|
| 618 | if (rotate.isOn() && !RotationManager.look(crystal.getBoundingBox().getCenter(),
|
| 619 | RotationPriority.AURA, RotationManager.BLOCK_TOLERANCE, yawSteps.getFloat())) {
|
| 620 | status = "(turning)";
|
| 621 | return false;
|
| 622 | }
|
| 623 | if (antiWeakness.isOn() && !armWeakHand()) {
|
| 624 | status = "(weakness)";
|
| 625 | return false;
|
| 626 | }
|
| 627 | mc.player.connection.send(new ServerboundAttackPacket(crystal.getId()));
|
| 628 | swing.getValue().swing();
|
| 629 | lastHitAt = System.currentTimeMillis();
|
| 630 | breakTimer = breakDelay.getInt();
|
| 631 | busyTimer = BUSY_TICKS;
|
| 632 | removed.put(crystal.getId(), REMOVED_MEMORY);
|
| 633 | attempts.merge(crystal.getId(), 1, Integer::sum);
|
| 634 | if (renderBreak.isOn()) {
|
| 635 | show(crystal.blockPosition().below(), scoreOf(crystal.position()), breakTime.getInt());
|
| 636 | }
|
| 637 | return true;
|
| 638 | }
|
| 639 |
|
| 640 | // A crystal that spawns is hit before its first tick when the reach and damage allow.
|
| 641 | @Subscribe
|
| 642 | private void onEntityAdded(EntityAddedEvent event) {
|
| 643 | if (!fastBreak.isOn() || !doBreak.isOn() || breakTimer > 0 || !inGame()
|
| 644 | || !(event.getEntity() instanceof EndCrystal crystal) || targets.isEmpty()) {
|
| 645 | return;
|
| 646 | }
|
| 647 | if (paused(Pause.BREAK) || pauseReason() != null || !attackAllowed()) {
|
| 648 | return;
|
| 649 | }
|
| 650 | if (ticksExisted.getInt() > 0 || !hittable(crystal) || scoreOf(crystal.position()) <= 0) {
|
| 651 | return;
|
| 652 | }
|
| 653 | hit(crystal);
|
| 654 | restoreSlot();
|
| 655 | }
|
| 656 |
|
| 657 | private void placeBest() {
|
| 658 | if (supportTimer > 0) {
|
| 659 | return;
|
| 660 | }
|
| 661 | BlockPos base = bestBase();
|
| 662 | if (base == null) {
|
| 663 | if (support.is(Support.OFF)) {
|
| 664 | status = "(no safe spot)";
|
| 665 | } else {
|
| 666 | placeSupport();
|
| 667 | }
|
| 668 | return;
|
| 669 | }
|
| 670 | InteractionHand hand = crystalHand();
|
| 671 | if (hand == null) {
|
| 672 | return;
|
| 673 | }
|
| 674 | Vec3 hit = Vec3.atCenterOf(base).add(0, 0.5, 0);
|
| 675 | float step = yawStepsMode.is(YawSteps.ALL) ? yawSteps.getFloat() : RotationManager.NO_STEP;
|
| 676 | if (rotate.isOn() && !RotationManager.look(hit, RotationPriority.AURA,
|
| 677 | RotationManager.BLOCK_TOLERANCE, step)) {
|
| 678 | status = "(turning)";
|
| 679 | return;
|
| 680 | }
|
| 681 | BlockHitResult result = new BlockHitResult(hit, Direction.UP, base, false);
|
| 682 | if (mc.gameMode.useItemOn(mc.player, hand, result).consumesAction()) {
|
| 683 | swing.getValue().swing(hand);
|
| 684 | ownSpots.put(base.above().immutable(), OWN_MEMORY);
|
| 685 | placeTimer = placeDelay.getInt();
|
| 686 | busyTimer = BUSY_TICKS;
|
| 687 | if (renderPlace.isOn()) {
|
| 688 | show(base, scoreOf(Vec3.atBottomCenterOf(base.above())), placeTime.getInt());
|
| 689 | }
|
| 690 | }
|
| 691 | }
|
| 692 |
|
| 693 | private BlockPos bestBase() {
|
| 694 | BlockPos best = null;
|
| 695 | float bestDamage = 0;
|
| 696 | Vec3 eye = mc.player.getEyePosition();
|
| 697 | double furthest = Math.max(placeRange.getValue(), placeWallsRange.getValue());
|
| 698 | int r = (int) Math.ceil(furthest);
|
| 699 | BlockPos middle = mc.player.blockPosition();
|
| 700 | for (BlockPos base : BlockPos.betweenClosed(middle.offset(-r, -r, -r), middle.offset(r, r, r))) {
|
| 701 | BlockPos above = base.above();
|
| 702 | Vec3 crystalPos = Vec3.atBottomCenterOf(above);
|
| 703 | if (eye.distanceTo(crystalPos) > furthest || !BlockUtil.state(above).isAir()) {
|
| 704 | continue;
|
| 705 | }
|
| 706 | Block block = BlockUtil.state(base).getBlock();
|
| 707 | if (block != Blocks.OBSIDIAN && block != Blocks.BEDROCK) {
|
| 708 | continue;
|
| 709 | }
|
| 710 | if (oldPlacement.isOn() && !BlockUtil.state(above.above()).isAir()) {
|
| 711 | continue;
|
| 712 | }
|
| 713 | double reach = BlockUtil.canSee(crystalPos) ? placeRange.getValue() : placeWallsRange.getValue();
|
| 714 | if (eye.distanceTo(crystalPos) > reach) {
|
| 715 | continue;
|
| 716 | }
|
| 717 | // The crystal model needs its whole space free of entities.
|
| 718 | if (entityBlocks(crystalSpace(above)) || !selfSafe(crystalPos)) {
|
| 719 | continue;
|
| 720 | }
|
| 721 | float damage = scoreOf(crystalPos);
|
| 722 | if (damage > bestDamage) {
|
| 723 | bestDamage = damage;
|
| 724 | best = base.immutable();
|
| 725 | }
|
| 726 | }
|
| 727 | if (best != null && renderMode.getValue() != RenderMode.NONE) {
|
| 728 | preview(best, bestDamage);
|
| 729 | }
|
| 730 | return best;
|
| 731 | }
|
| 732 |
|
| 733 | private static AABB crystalSpace(BlockPos above) {
|
| 734 | return new AABB(above.getX(), above.getY(), above.getZ(),
|
| 735 | above.getX() + 1, above.getY() + 2, above.getZ() + 1);
|
| 736 | }
|
| 737 |
|
| 738 | // The damage a crystal here deals to every target added up. Zero when no
|
| 739 | // target on its own clears the minimum.
|
| 740 | private float scoreOf(Vec3 crystalPos) {
|
| 741 | return scoreOf(crystalPos, targets);
|
| 742 | }
|
| 743 |
|
| 744 | private float scoreOf(Vec3 crystalPos, List<LivingEntity> against) {
|
| 745 | float total = 0;
|
| 746 | boolean enough = false;
|
| 747 | for (LivingEntity target : against) {
|
| 748 | float damage = ExplosionUtil.crystalDamage(target, crystalPos, lead(target));
|
| 749 | if (damage <= 0) {
|
| 750 | continue;
|
| 751 | }
|
| 752 | enough |= finishing || damage >= minDamage.getFloat();
|
| 753 | total += damage;
|
| 754 | }
|
| 755 | return enough ? total : 0;
|
| 756 | }
|
| 757 |
|
| 758 | // How far the target travels before the blast lands.
|
| 759 | private Vec3 lead(LivingEntity target) {
|
| 760 | return predict.isOn() ? EntityUtil.velocityOf(target).scale(LEAD_TICKS) : Vec3.ZERO;
|
| 761 | }
|
| 762 |
|
| 763 | // True when the target is nearly dead or their armour is falling apart.
|
| 764 | private boolean finishing(LivingEntity target) {
|
| 765 | if (!finisher.isOn()) {
|
| 766 | return false;
|
| 767 | }
|
| 768 | if (EntityUtil.totalHealth(target) <= finisherHealth.getFloat()) {
|
| 769 | return true;
|
| 770 | }
|
| 771 | if (!(target instanceof Player)) {
|
| 772 | return false;
|
| 773 | }
|
| 774 | for (EquipmentSlot slot : ItemUtil.ARMOR_SLOTS) {
|
| 775 | ItemStack piece = target.getItemBySlot(slot);
|
| 776 | if (piece.isEmpty()) {
|
| 777 | if (finisherMissing.isOn()) {
|
| 778 | return true;
|
| 779 | }
|
| 780 | continue;
|
| 781 | }
|
| 782 | if (!piece.isDamageableItem()) {
|
| 783 | continue;
|
| 784 | }
|
| 785 | int left = piece.getMaxDamage() - piece.getDamageValue();
|
| 786 | if (left <= piece.getMaxDamage() * finisherArmour.getFloat() / 100f) {
|
| 787 | return true;
|
| 788 | }
|
| 789 | }
|
| 790 | return false;
|
| 791 | }
|
| 792 |
|
| 793 | // Puts something with attack damage in hand when weakness has zeroed it out.
|
| 794 | // The server refuses the whole attack at zero and the crystal survives.
|
| 795 | private boolean armWeakHand() {
|
| 796 | if (mc.player.getAttributeValue(Attributes.ATTACK_DAMAGE) > 0) {
|
| 797 | return true;
|
| 798 | }
|
| 799 | ItemStack held = mc.player.getInventory().getSelectedItem();
|
| 800 | double heldBonus = ItemUtil.attributeValue(held, Attributes.ATTACK_DAMAGE,
|
| 801 | EquipmentSlot.MAINHAND);
|
| 802 | double base = mc.player.getAttributeValue(Attributes.ATTACK_DAMAGE) - heldBonus;
|
| 803 |
|
| 804 | int bestSlot = -1;
|
| 805 | double bestBonus = 0;
|
| 806 | for (int i = 0; i < InventoryUtil.HOTBAR_SIZE; i++) {
|
| 807 | ItemStack stack = mc.player.getInventory().getItem(i);
|
| 808 | if (stack.isEmpty()) {
|
| 809 | continue;
|
| 810 | }
|
| 811 | double bonus = ItemUtil.attributeValue(stack, Attributes.ATTACK_DAMAGE,
|
| 812 | EquipmentSlot.MAINHAND);
|
| 813 | if (bonus > bestBonus) {
|
| 814 | bestBonus = bonus;
|
| 815 | bestSlot = i;
|
| 816 | }
|
| 817 | }
|
| 818 | if (bestSlot == -1 || base + bestBonus <= 0) {
|
| 819 | return false;
|
| 820 | }
|
| 821 | select(bestSlot);
|
| 822 | return true;
|
| 823 | }
|
| 824 |
|
| 825 | private boolean selfSafe(Vec3 source) {
|
| 826 | return ExplosionUtil.selfSafe(source, ExplosionUtil.CRYSTAL_POWER,
|
| 827 | maxSelfDamage.getFloat(), antiSuicide.isOn());
|
| 828 | }
|
| 829 |
|
| 830 | private boolean entityBlocks(AABB space) {
|
| 831 | for (Entity entity : entities) {
|
| 832 | if (entity.getBoundingBox().intersects(space)) {
|
| 833 | return true;
|
| 834 | }
|
| 835 | }
|
| 836 | return false;
|
| 837 | }
|
| 838 |
|
| 839 | // The hand holding a crystal. Switches the hotbar over when the mode allows.
|
| 840 | private InteractionHand crystalHand() {
|
| 841 | if (mc.player.getOffhandItem().is(Items.END_CRYSTAL)) {
|
| 842 | return InteractionHand.OFF_HAND;
|
| 843 | }
|
| 844 | if (mc.player.getMainHandItem().is(Items.END_CRYSTAL)) {
|
| 845 | return InteractionHand.MAIN_HAND;
|
| 846 | }
|
| 847 | if (autoSwitch.is(Switch.NONE)) {
|
| 848 | status = "(hold crystals)";
|
| 849 | return null;
|
| 850 | }
|
| 851 | if (autoSwitch.is(Switch.NORMAL) && holdingSomethingPrecious()) {
|
| 852 | status = "(keeping hand)";
|
| 853 | return null;
|
| 854 | }
|
| 855 | int slot = InventoryUtil.hotbarSlot(stack -> stack.is(Items.END_CRYSTAL));
|
| 856 | if (slot != -1) {
|
| 857 | select(slot);
|
| 858 | return InteractionHand.MAIN_HAND;
|
| 859 | }
|
| 860 | refillCrystals();
|
| 861 | status = "(no crystals)";
|
| 862 | return null;
|
| 863 | }
|
| 864 |
|
| 865 | private boolean holdingSomethingPrecious() {
|
| 866 | for (InteractionHand hand : InteractionHand.values()) {
|
| 867 | ItemStack stack = mc.player.getItemInHand(hand);
|
| 868 | if (noGapSwitch.isOn() && (stack.is(Items.GOLDEN_APPLE) || stack.is(Items.ENCHANTED_GOLDEN_APPLE))) {
|
| 869 | return true;
|
| 870 | }
|
| 871 | if (noBowSwitch.isOn() && stack.getItem() instanceof BowItem) {
|
| 872 | return true;
|
| 873 | }
|
| 874 | }
|
| 875 | return false;
|
| 876 | }
|
| 877 |
|
| 878 | // A hotbar swap the server has to hear about before a hit is believed.
|
| 879 | private void select(int slot) {
|
| 880 | if (mc.player.getInventory().getSelectedSlot() != slot) {
|
| 881 | switchTimer = switchDelay.getInt();
|
| 882 | }
|
| 883 | slots.select(slot);
|
| 884 | }
|
| 885 |
|
| 886 | private void refillCrystals() {
|
| 887 | if (refillTimer > 0 || mc.player.containerMenu != mc.player.inventoryMenu) {
|
| 888 | return;
|
| 889 | }
|
| 890 | int free = InventoryUtil.freeHotbarSlot();
|
| 891 | if (free == -1) {
|
| 892 | return;
|
| 893 | }
|
| 894 | for (int i = InventoryUtil.HOTBAR_SIZE; i < InventoryUtil.WHOLE_INVENTORY; i++) {
|
| 895 | if (!mc.player.getInventory().getItem(i).is(Items.END_CRYSTAL)) {
|
| 896 | continue;
|
| 897 | }
|
| 898 | refillTimer = REFILL_DELAY;
|
| 899 | InventoryUtil.swap(InventoryUtil.networkSlot(i), InventoryUtil.networkSlot(free));
|
| 900 | return;
|
| 901 | }
|
| 902 | }
|
| 903 |
|
| 904 | // Places an obsidian block on the best open spot for the next crystal.
|
| 905 | private void placeSupport() {
|
| 906 | int slot = InventoryUtil.findSlot(Items.OBSIDIAN, InventoryUtil.WHOLE_INVENTORY);
|
| 907 | if (slot == -1) {
|
| 908 | status = "(no obsidian)";
|
| 909 | return;
|
| 910 | }
|
| 911 | List<LivingEntity> against = support.is(Support.FAST) ? targets.subList(0, 1) : targets;
|
| 912 | BlockPos best = null;
|
| 913 | float bestDamage = 0;
|
| 914 | Vec3 eye = mc.player.getEyePosition();
|
| 915 | for (LivingEntity target : against) {
|
| 916 | BlockPos feet = target.blockPosition();
|
| 917 | BlockPos low = feet.offset(-SUPPORT_REACH, -SUPPORT_RISE, -SUPPORT_REACH);
|
| 918 | BlockPos high = feet.offset(SUPPORT_REACH, SUPPORT_RISE, SUPPORT_REACH);
|
| 919 | for (BlockPos pos : BlockPos.betweenClosed(low, high)) {
|
| 920 | if (!BlockUtil.isReplaceable(pos) || !BlockUtil.state(pos.above()).isAir()) {
|
| 921 | continue;
|
| 922 | }
|
| 923 | if (BlockUtil.intersectsPlayer(pos) || entityBlocks(new AABB(pos))) {
|
| 924 | continue;
|
| 925 | }
|
| 926 | Vec3 crystalPos = Vec3.atBottomCenterOf(pos.above());
|
| 927 | if (eye.distanceTo(crystalPos) > placeRange.getValue() || !selfSafe(crystalPos)) {
|
| 928 | continue;
|
| 929 | }
|
| 930 | float damage = scoreOf(crystalPos, against);
|
| 931 | if (damage > bestDamage) {
|
| 932 | bestDamage = damage;
|
| 933 | best = pos.immutable();
|
| 934 | }
|
| 935 | }
|
| 936 | }
|
| 937 | if (best == null) {
|
| 938 | status = "(no safe spot)";
|
| 939 | return;
|
| 940 | }
|
| 941 | if (rotate.isOn() && !RotationManager.look(Vec3.atCenterOf(best), RotationPriority.AURA,
|
| 942 | RotationManager.BLOCK_TOLERANCE)) {
|
| 943 | status = "(turning)";
|
| 944 | return;
|
| 945 | }
|
| 946 | if (slot < InventoryUtil.HOTBAR_SIZE) {
|
| 947 | select(slot);
|
| 948 | } else if (!loan.select(slot)) {
|
| 949 | status = "(no room for obsidian)";
|
| 950 | return;
|
| 951 | }
|
| 952 | boolean placed = BlockUtil.placeAny(best, false, true);
|
| 953 | // The block goes down before the borrowed stack heads home.
|
| 954 | loan.giveBack();
|
| 955 | if (placed) {
|
| 956 | status = "(placing support)";
|
| 957 | supportTimer = supportDelay.getInt();
|
| 958 | busyTimer = BUSY_TICKS;
|
| 959 | if (supportTimer == 0) {
|
| 960 | placeTimer = 0;
|
| 961 | placeBest();
|
| 962 | }
|
| 963 | }
|
| 964 | }
|
| 965 |
|
| 966 | // The spot the next crystal is heading for. Drawn until a placement replaces it.
|
| 967 | private void preview(BlockPos base, float damage) {
|
| 968 | if (drawnTicks == 0 || !base.equals(drawn)) {
|
| 969 | show(base, damage, 1);
|
| 970 | }
|
| 971 | }
|
| 972 |
|
| 973 | private void show(BlockPos base, float damage, int ticks) {
|
| 974 | if (renderMode.is(RenderMode.SMOOTH) && drawn != null && !base.equals(drawn)) {
|
| 975 | slideFrom = slideTo == null ? Vec3.atLowerCornerOf(drawn) : currentSlide();
|
| 976 | slideTo = Vec3.atLowerCornerOf(base);
|
| 977 | slideTicks = smoothness.getInt();
|
| 978 | }
|
| 979 | drawn = base;
|
| 980 | drawnDamage = damage;
|
| 981 | drawnTicks = Math.max(ticks, 1);
|
| 982 | }
|
| 983 |
|
| 984 | private Vec3 currentSlide() {
|
| 985 | if (slideFrom == null || slideTo == null || slideTicks == 0) {
|
| 986 | return slideTo == null ? Vec3.atLowerCornerOf(drawn) : slideTo;
|
| 987 | }
|
| 988 | double t = 1 - (double) slideTicks / smoothness.getInt();
|
| 989 | return slideFrom.lerp(slideTo, t);
|
| 990 | }
|
| 991 |
|
| 992 | @Subscribe
|
| 993 | private void onRender3D(Render3DEvent event) {
|
| 994 | if (renderMode.is(RenderMode.NONE) || drawn == null || drawnTicks == 0) {
|
| 995 | return;
|
| 996 | }
|
| 997 | DrawBatch batch = event.getBatch();
|
| 998 | AABB box = DrawBatch.blockBox(drawn);
|
| 999 | float alpha = 1;
|
| 1000 | switch (renderMode.getValue()) {
|
| 1001 | case SMOOTH -> {
|
| 1002 | Vec3 corner = currentSlide();
|
| 1003 | box = box.move(corner.subtract(Vec3.atLowerCornerOf(drawn)));
|
| 1004 | }
|
| 1005 | case FADING -> alpha = Math.min(1f, (float) drawnTicks / fadeTime.getInt());
|
| 1006 | case GRADIENT -> {
|
| 1007 | AABB tall = new AABB(box.minX, box.minY, box.minZ, box.maxX,
|
| 1008 | box.minY + gradientHeight.getValue(), box.maxZ);
|
| 1009 | batch.gradientBox(tall, ColorUtil.fade(boxStyle.lineColor(), 0.4f),
|
| 1010 | ColorUtil.fade(boxStyle.lineColor(), 0f), false);
|
| 1011 | batch.flatRect(box.minX, box.minZ, box.maxX, box.maxZ, box.minY,
|
| 1012 | boxStyle.lineColor(), false);
|
| 1013 | drawDamage(box);
|
| 1014 | return;
|
| 1015 | }
|
| 1016 | default -> {
|
| 1017 | }
|
| 1018 | }
|
| 1019 | boxStyle.draw(batch, box, ColorUtil.fade(boxStyle.lineColor(), alpha), false);
|
| 1020 | drawDamage(box);
|
| 1021 | }
|
| 1022 |
|
| 1023 | // The number is drawn on the screen over where the box top sits in the world.
|
| 1024 | private void drawDamage(AABB box) {
|
| 1025 | damageAt = showDamage.isOn() && drawnDamage > 0
|
| 1026 | ? new Vec3((box.minX + box.maxX) / 2, box.maxY + 0.5, (box.minZ + box.maxZ) / 2) : null;
|
| 1027 | }
|
| 1028 |
|
| 1029 | @Subscribe
|
| 1030 | private void onRender2D(Render2DEvent event) {
|
| 1031 | if (damageAt == null || drawnTicks == 0 || !WorldToScreen.update()) {
|
| 1032 | return;
|
| 1033 | }
|
| 1034 | Vec3 screen = WorldToScreen.project(damageAt);
|
| 1035 | if (screen == null) {
|
| 1036 | return;
|
| 1037 | }
|
| 1038 | String text = String.format(Locale.ROOT, "%.1f", drawnDamage);
|
| 1039 | RenderUtil.label(event.getContext(), mc.font, screen.x, screen.y, damageScale.getFloat(),
|
| 1040 | List.of(text), List.of(damageColor.getColor()));
|
| 1041 | }
|
| 1042 |
|
| 1043 | // Sent hotbar swaps restart the switch delay. The hit waits for the server.
|
| 1044 | @Subscribe
|
| 1045 | private void onPacketSend(PacketSendEvent event) {
|
| 1046 | if (event.getPacket() instanceof ServerboundSetCarriedItemPacket) {
|
| 1047 | switchTimer = switchDelay.getInt();
|
| 1048 | }
|
| 1049 | }
|
| 1050 | }
|
| 1051 |
|