More memory optimizations.

This commit is contained in:
wolf
2025-06-24 21:16:22 -04:00
parent ef1790b3fc
commit d9967516b6
2 changed files with 167 additions and 220 deletions

View File

@@ -24,9 +24,15 @@ public class TrimManager implements Main, Data {
} }
public void tickPlayer(Player player) { public void tickPlayer(Player player) {
if (shouldHide(player)) return;
UUID uuid = player.getUniqueId(); UUID uuid = player.getUniqueId();
if (shouldHide(player)) {
if (activePlayers.containsKey(uuid)) {
animations.get(activePlayers.get(uuid).material).onRemove(player);
activePlayers.remove(uuid);
}
return;
}
ValidMaterial currentMaterial = getActiveMaterial(player); ValidMaterial currentMaterial = getActiveMaterial(player);
ActiveTrim active = activePlayers.get(uuid); ActiveTrim active = activePlayers.get(uuid);
Location currentLocation = player.getLocation(); Location currentLocation = player.getLocation();

View File

@@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Stack; import java.util.Stack;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class OrbitalTrollWand extends AbstractWand implements TrollFeature { public class OrbitalTrollWand extends AbstractWand implements TrollFeature {
private static final ItemStack ORBITAL_WAND = ItemBuilder.of(Material.TRIPWIRE_HOOK) private static final ItemStack ORBITAL_WAND = ItemBuilder.of(Material.TRIPWIRE_HOOK)
@@ -67,14 +68,26 @@ public class OrbitalTrollWand extends AbstractWand implements TrollFeature {
@Override @Override
public void stop(CommandSender sender, Player target) {} public void stop(CommandSender sender, Player target) {}
private final Map<UUID, OrbitalIonCannon> cannonMap = new HashMap<>(); private final Map<UUID, OrbitalIonCannon> cannonMap = new ConcurrentHashMap<>();
private final Map<UUID, Stack<ExplosionResult>> playerHistory = new HashMap<>(); private final Map<UUID, Stack<ExplosionResult>> playerHistory = new ConcurrentHashMap<>();
private final Component SUCCESS_RESTORE = Component.text("Restored previous explosion.");
private final Component ERROR_EMPTY_STACK = Component.text("Undo stack is empty!");
private final Component ERROR_EXCEPTION = Component.text("An exception was thrown when undoing the explosion! Check console for details.");
private final Component ERROR_ALREADY_CHARGING = Component.text("You are already charging the Ion Cannon!");
private final Component SUCCESS_CHARGING = Component.text("Charging Ion Cannon...");
private final Component SUCCESS_AIM = Component.text("You can now aim the Ion Cannon.");
private final Component ERROR_NOT_CONTROLLING = Component.text("You are not controlling the Ion Cannon.");
private final Component SUCCESS_DEACTIVATED = Component.text("Deactivated Ion Cannon Safely.");
private boolean undoHistory(Player player) { private boolean undoHistory(Player player) {
Stack<ExplosionResult> history = playerHistory.getOrDefault(player.getUniqueId(),new Stack<>()); Stack<ExplosionResult> history = playerHistory.get(player.getUniqueId());
if (history == null || history.isEmpty()) return false; if (history == null || history.isEmpty()) return false;
try (ExplosionResult result = history.pop()) { try (ExplosionResult result = history.pop()) {
result.restore(); result.restore();
if (history.isEmpty()) {
playerHistory.remove(player.getUniqueId());
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;
@@ -86,91 +99,97 @@ public class OrbitalTrollWand extends AbstractWand implements TrollFeature {
protected void onSwapHand(Player player) { protected void onSwapHand(Player player) {
try { try {
if (undoHistory(player)) { if (undoHistory(player)) {
Text.message(Text.Pallet.SUCCESS,false,player, Component.text("Restored previous explosion.")); Text.message(Text.Pallet.SUCCESS, false, player, SUCCESS_RESTORE);
SoundPlayer.play(player, Sound.ENTITY_ILLUSIONER_PREPARE_BLINDNESS, 10, 1);
} else { } else {
Text.message(Text.Pallet.ERROR,false,player,Component.text("Undo stack is empty!")); Text.message(Text.Pallet.ERROR, false, player, ERROR_EMPTY_STACK);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
Text.message(Text.Pallet.ERROR,false,player,Component.text("An exception was thrown when undoing the explosion! Check console for details.")); Text.message(Text.Pallet.ERROR, false, player, ERROR_EXCEPTION);
} }
} }
@Override @Override
protected void onRightClick(Player player) { protected void onRightClick(Player player) {
if (cannonMap.containsKey(player.getUniqueId())) { UUID playerId = player.getUniqueId();
OrbitalIonCannon playerCannon = cannonMap.get(player.getUniqueId()); OrbitalIonCannon playerCannon = cannonMap.get(playerId);
if (playerCannon != null) {
if (playerCannon.getFireTask() != null || playerCannon.getChargeTask() != null) { if (playerCannon.getFireTask() != null || playerCannon.getChargeTask() != null) {
Text.message(Text.Pallet.ERROR,false,player,Component.text("You are already charging the Ion Cannon!")); Text.message(Text.Pallet.ERROR, false, player, ERROR_ALREADY_CHARGING);
cannonMap.remove(player.getUniqueId()); cannonMap.remove(playerId);
return; return;
} }
playerCannon.charge(); playerCannon.charge();
cannonMap.remove(player.getUniqueId()); cannonMap.remove(playerId);
Text.message(Text.Pallet.SUCCESS,false,player, Component.text("Charging Ion Cannon...")); Text.message(Text.Pallet.SUCCESS, false, player, SUCCESS_CHARGING);
return; return;
} }
OrbitalIonCannon cannon = new OrbitalIonCannon(player, traceTargets(player)); OrbitalIonCannon cannon = new OrbitalIonCannon(player, traceTargets(player));
cannonMap.put(player.getUniqueId(),cannon); cannonMap.put(playerId, cannon);
Text.message(Text.Pallet.SUCCESS,false,player, Component.text("You can now aim the Ion Cannon.")); Text.message(Text.Pallet.SUCCESS, false, player, SUCCESS_AIM);
} }
@Override @Override
protected void onLeftClick(Player player) { protected void onLeftClick(Player player) {
if (!cannonMap.containsKey(player.getUniqueId())) { UUID playerId = player.getUniqueId();
Text.message(Text.Pallet.ERROR,false,player,Component.text("You are not controlling the Ion Cannon.")); OrbitalIonCannon playerCannon = cannonMap.get(playerId);
if (playerCannon == null) {
Text.message(Text.Pallet.ERROR, false, player, ERROR_NOT_CONTROLLING);
return; return;
} }
OrbitalIonCannon playerCannon = cannonMap.get(player.getUniqueId());
playerCannon.destroy();
cannonMap.remove(player.getUniqueId());
Text.message(Text.Pallet.SUCCESS,false,player, Component.text("Deactivated Ion Cannon Safely."));
playerCannon.destroy();
cannonMap.remove(playerId);
Text.message(Text.Pallet.SUCCESS, false, player, SUCCESS_DEACTIVATED);
SoundPlayer.play(player, Sound.BLOCK_BEACON_DEACTIVATE, 1, 0.5F);
} }
@Override @Override
protected void onScrollDown(Player player) { protected void onScrollDown(Player player) {
if (!cannonMap.containsKey(player.getUniqueId())) { OrbitalIonCannon cannon = cannonMap.get(player.getUniqueId());
Text.message(Text.Pallet.ERROR,false,player,Component.text("You are not controlling the Ion Cannon.")); if (cannon == null) {
Text.message(Text.Pallet.ERROR, false, player, ERROR_NOT_CONTROLLING);
return; return;
} }
OrbitalIonCannon cannon = cannonMap.get(player.getUniqueId());
if (cannon.getPower() <= 1) { if (cannon.getPower() <= 1) {
SoundPlayer.play(player,Sound.BLOCK_NOTE_BLOCK_HAT, 1, 1.3F); SoundPlayer.play(player, Sound.BLOCK_NOTE_BLOCK_HAT, 1, 1.3F);
cannon.setPower(2); cannon.setPower(2);
return; return;
} }
cannon.setPower(Math.max(1,cannon.getPower() - 5)); cannon.setPower(Math.max(1, cannon.getPower() - 5));
SoundPlayer.play(player,Sound.BLOCK_NOTE_BLOCK_HAT, 1, 1.7F); SoundPlayer.play(player, Sound.BLOCK_NOTE_BLOCK_HAT, 1, 1.7F);
player.sendActionBar(Text.format(Text.Pallet.INFO,"Set ion cannon power to {0}.",cannon.getPower())); player.sendActionBar(Text.format(Text.Pallet.INFO, "Set ion cannon power to {0}.", cannon.getPower()));
} }
@Override @Override
protected void onScrollUp(Player player) { protected void onScrollUp(Player player) {
if (!cannonMap.containsKey(player.getUniqueId())) { OrbitalIonCannon cannon = cannonMap.get(player.getUniqueId());
Text.message(Text.Pallet.ERROR,false,player,Component.text("You are not controlling the Ion Cannon.")); if (cannon == null) {
Text.message(Text.Pallet.ERROR, false, player, ERROR_NOT_CONTROLLING);
return; return;
} }
OrbitalIonCannon cannon = cannonMap.get(player.getUniqueId());
if (cannon.getPower() >= 50) { if (cannon.getPower() >= 50) {
SoundPlayer.play(player,Sound.BLOCK_NOTE_BLOCK_HAT, 1, 1.3F); SoundPlayer.play(player, Sound.BLOCK_NOTE_BLOCK_HAT, 1, 1.3F);
cannon.setPower(49); cannon.setPower(49);
return; return;
} }
cannon.setPower(Math.min(50,cannon.getPower() + 5)); cannon.setPower(Math.min(50, cannon.getPower() + 5));
SoundPlayer.play(player,Sound.BLOCK_NOTE_BLOCK_HAT, 1, 0.8F); SoundPlayer.play(player, Sound.BLOCK_NOTE_BLOCK_HAT, 1, 0.8F);
player.sendActionBar(Text.format(Text.Pallet.INFO,"Set ion cannon power to {0}.",cannon.getPower())); player.sendActionBar(Text.format(Text.Pallet.INFO, "Set ion cannon power to {0}.", cannon.getPower()));
} }
public class OrbitalIonCannon { public class OrbitalIonCannon {
private final Player owner; private final Player owner;
private final UUID ownerId;
private final OrbitalConfiguration simulatedOrbit; private final OrbitalConfiguration simulatedOrbit;
private Location skyRenderLocation; private Location skyRenderLocation;
private Location skyTraceLocation; private Location skyTraceLocation;
@@ -181,19 +200,24 @@ public class OrbitalTrollWand extends AbstractWand implements TrollFeature {
private BukkitTask fireTask; private BukkitTask fireTask;
private int power; private int power;
private ExplosionResult explosionResult; private ExplosionResult explosionResult;
private final BukkitTask tickTask = new BukkitRunnable() { private final BukkitTask tickTask = new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
if (owner == null || !owner.isOnline()) {
destroy();
return;
}
updateOrbitLocation(); updateOrbitLocation();
setSkyRenderLocation(getSimulatedOrbit().getRenderLocation(getTargetLocation())); setSkyRenderLocation(getSimulatedOrbit().getRenderLocation(getTargetLocation()));
setSkyTraceLocation(CustomDisplayRaytracer.blocksInFrontOf(getTargetLocation(),getSimulatedOrbit().getNormalToSatellite(getTargetLocation().toVector()),20,false).getLoc()); setSkyTraceLocation(CustomDisplayRaytracer.blocksInFrontOf(getTargetLocation(), getSimulatedOrbit().getNormalToSatellite(getTargetLocation().toVector()), 20, false).getLoc());
if (!getAimTask().isCancelled()) {
if (aimTask != null && !aimTask.isCancelled()) {
setTargetLocation(traceTargets(getOwner())); setTargetLocation(traceTargets(getOwner()));
setGroundTraced(CustomDisplayRaytracer.trace(getSkyTraceLocation(),getTargetLocation(),5,(point)-> { setGroundTraced(CustomDisplayRaytracer.trace(getSkyTraceLocation(), getTargetLocation(), 5, (point) -> {
Material type = point.getLoc().getBlock().getType(); Material type = point.getLoc().getBlock().getType();
boolean collidable = type.isCollidable(); return type.isCollidable();
Verbose.send("Block at {0} collision: {1}, {2}",point.getLoc(),type,collidable);
return collidable;
}).getLoc()); }).getLoc());
} }
} }
@@ -201,10 +225,10 @@ public class OrbitalTrollWand extends AbstractWand implements TrollFeature {
private OrbitalIonCannon(Player owner, Location target) { private OrbitalIonCannon(Player owner, Location target) {
this.owner = owner; this.owner = owner;
this.ownerId = owner.getUniqueId();
this.targetLocation = target; this.targetLocation = target;
this.power = 20; this.power = 20;
this.simulatedOrbit = new OrbitalConfiguration(target.toVector()); this.simulatedOrbit = new OrbitalConfiguration(target.toVector());
this.setAimTask(aimRunnable.runTaskTimer(main.getPlugin(), 0, 1)); this.setAimTask(aimRunnable.runTaskTimer(main.getPlugin(), 0, 1));
} }
@@ -214,18 +238,18 @@ public class OrbitalTrollWand extends AbstractWand implements TrollFeature {
@Override @Override
public void run() { public void run() {
if (ticksElapsed >= 120) { if (ticksElapsed >= 120) {
if (getExplosionResult() != null) { if (getExplosionResult() != null && getExplosionResult().getTaskManager() != null && !getExplosionResult().getTaskManager().isClosed()) {
getExplosionResult().close(); getExplosionResult().getTaskManager().close();
} }
destroy(); destroy();
return; return;
} }
if (ticksElapsed <= 40) { if (ticksElapsed <= 40) {
BlockDisplay inner = BlockDisplayRaytracer.trace(Material.WHITE_CONCRETE_POWDER,getGroundTraced(),getSkyRenderLocation(),1,2); BlockDisplay inner = BlockDisplayRaytracer.trace(Material.WHITE_CONCRETE_POWDER, getGroundTraced(), getSkyRenderLocation(), 1, 2);
inner.setGlowing(true); inner.setGlowing(true);
inner.setGlowColorOverride(Color.fromRGB(0xFFDDDD)); inner.setGlowColorOverride(Color.fromRGB(0xFFDDDD));
BlockDisplayRaytracer.trace(Material.WHITE_STAINED_GLASS,getGroundTraced(),getSkyRenderLocation(),1.5 + main.random().nextDouble(),2); BlockDisplayRaytracer.trace(Material.WHITE_STAINED_GLASS, getGroundTraced(), getSkyRenderLocation(), 1.5 + main.random().nextDouble(), 2);
} }
if (ticksElapsed == 0) { if (ticksElapsed == 0) {
@@ -237,13 +261,9 @@ public class OrbitalTrollWand extends AbstractWand implements TrollFeature {
.setBurnDelay(0) .setBurnDelay(0)
.setDestructionDelay(1); .setDestructionDelay(1);
Stack<ExplosionResult> history = playerHistory.getOrDefault(getOwner().getUniqueId(),new Stack<>()); Stack<ExplosionResult> history = playerHistory.computeIfAbsent(ownerId, k -> new Stack<>());
setExplosionResult(ExplosionUtils.createExplosion(getGroundTraced(), options));
setExplosionResult(ExplosionUtils.createExplosion(getGroundTraced(),options));
history.push(getExplosionResult()); history.push(getExplosionResult());
playerHistory.put(getOwner().getUniqueId(),history);
} }
ticksElapsed++; ticksElapsed++;
@@ -252,26 +272,31 @@ public class OrbitalTrollWand extends AbstractWand implements TrollFeature {
private final BukkitRunnable chargeRunnable = new BukkitRunnable() { private final BukkitRunnable chargeRunnable = new BukkitRunnable() {
int ticksElapsed = 0; int ticksElapsed = 0;
@Override @Override
public void run() { public void run() {
if (ticksElapsed >= 20) { final int delay = 40;
setFireTask(fireRunnable.runTaskTimer(main.getPlugin(),0,1)); if (ticksElapsed >= delay) {
setFireTask(fireRunnable.runTaskTimer(main.getPlugin(), 0, 1));
this.cancel(); this.cancel();
return; return;
} }
if (ticksElapsed == 1) { if (ticksElapsed == 0) {
new SoundPlayer(Sound.ENTITY_WARDEN_SONIC_CHARGE,30,0.5F).playAt(getTargetLocation(),40); int volume = getPower() * 20;
new SoundPlayer(Sound.BLOCK_CONDUIT_AMBIENT,30,0.5F).playAt(getGroundTraced(),40); int radius = getPower() * 10;
new SoundPlayer(Sound.ENTITY_WARDEN_LISTENING, volume, 0.6F).playAt(getGroundTraced(), radius);
new SoundPlayer(Sound.ENTITY_WARDEN_SONIC_CHARGE, volume, 0.7F).playAt(getGroundTraced(), radius);
new SoundPlayer(Sound.BLOCK_CONDUIT_AMBIENT, volume, 0.5F).playAt(getGroundTraced(), radius);
} }
double thickness = (double) ticksElapsed / 20; double thickness = (double) ticksElapsed / delay;
int otherValues = ((ticksElapsed / 20 * 100) + 100); int otherValues = ((ticksElapsed / delay * 100) + 100);
BlockDisplay inner = BlockDisplayRaytracer.trace(Material.RED_CONCRETE, getGroundTraced(),getSkyRenderLocation(),thickness,2); BlockDisplay inner = BlockDisplayRaytracer.trace(Material.RED_CONCRETE, getGroundTraced(), getSkyRenderLocation(), thickness, 2);
inner.setGlowing(true); inner.setGlowing(true);
inner.setGlowColorOverride(Color.fromRGB(255,otherValues,otherValues)); inner.setGlowColorOverride(Color.fromRGB(255, otherValues, otherValues));
BlockDisplayRaytracer.trace(Material.ORANGE_STAINED_GLASS, getGroundTraced(),getSkyRenderLocation(),thickness + 0.1 ,2); BlockDisplayRaytracer.trace(Material.ORANGE_STAINED_GLASS, getGroundTraced(), getSkyRenderLocation(), thickness + 0.1, 2);
ticksElapsed++; ticksElapsed++;
} }
@@ -279,6 +304,7 @@ public class OrbitalTrollWand extends AbstractWand implements TrollFeature {
private final BukkitRunnable aimRunnable = new BukkitRunnable() { private final BukkitRunnable aimRunnable = new BukkitRunnable() {
int ticksElapsed = 0; int ticksElapsed = 0;
@Override @Override
public void run() { public void run() {
if (getChargeTask() != null) { if (getChargeTask() != null) {
@@ -287,13 +313,13 @@ public class OrbitalTrollWand extends AbstractWand implements TrollFeature {
} }
if (ticksElapsed == 0) { if (ticksElapsed == 0) {
new SoundPlayer(Sound.BLOCK_RESPAWN_ANCHOR_CHARGE,1,0.5F).playAt(groundTraced,40); new SoundPlayer(Sound.BLOCK_RESPAWN_ANCHOR_CHARGE, getPower() * 20, 0.5F).playAt(groundTraced, getPower() * 10);
} }
BlockDisplay inner = BlockDisplayRaytracer.trace(Material.RED_CONCRETE_POWDER,getGroundTraced(),getSkyRenderLocation(),0.1,2); BlockDisplay inner = BlockDisplayRaytracer.trace(Material.RED_CONCRETE_POWDER, getGroundTraced(), getSkyRenderLocation(), 0.1, 2);
inner.setGlowing(true); inner.setGlowing(true);
inner.setGlowColorOverride(Color.fromRGB(0xFF0000)); inner.setGlowColorOverride(Color.fromRGB(0xFF0000));
BlockDisplayRaytracer.trace(Material.RED_STAINED_GLASS,getGroundTraced(),getSkyRenderLocation(),0.2,2); BlockDisplayRaytracer.trace(Material.RED_STAINED_GLASS, getGroundTraced(), getSkyRenderLocation(), 0.2, 2);
ticksElapsed++; ticksElapsed++;
} }
@@ -304,122 +330,83 @@ public class OrbitalTrollWand extends AbstractWand implements TrollFeature {
destroy(); destroy();
return; return;
} }
getSimulatedOrbit().tick(); getSimulatedOrbit().tick();
} }
private void destroy() { private void destroy() {
if (getTickTask() != null) this.getTickTask().cancel(); if (tickTask != null && !tickTask.isCancelled()) tickTask.cancel();
if (getFireTask() != null) this.getFireTask().cancel(); if (fireTask != null && !fireTask.isCancelled()) fireTask.cancel();
if (getChargeTask() != null) this.getChargeTask().cancel(); if (chargeTask != null && !chargeTask.isCancelled()) chargeTask.cancel();
if (getAimTask() != null) this.getAimTask().cancel(); if (aimTask != null && !aimTask.isCancelled()) aimTask.cancel();
cannonMap.remove(ownerId);
} }
private void charge() { private void charge() {
this.getAimTask().cancel(); if (this.aimTask != null && !this.aimTask.isCancelled()) {
this.setChargeTask(this.chargeRunnable.runTaskTimer(main.getPlugin(),0,1)); this.aimTask.cancel();
}
this.setChargeTask(this.chargeRunnable.runTaskTimer(main.getPlugin(), 0, 1));
} }
public Player getOwner() { public Player getOwner() { return owner; }
return owner; public Location getTargetLocation() { return targetLocation; }
} public void setTargetLocation(Location targetLocation) { this.targetLocation = targetLocation; }
public BukkitTask getAimTask() { return aimTask; }
public Location getTargetLocation() { public void setAimTask(BukkitTask aimTask) { this.aimTask = aimTask; }
return targetLocation; public BukkitTask getChargeTask() { return chargeTask; }
} public void setChargeTask(BukkitTask chargeTask) { this.chargeTask = chargeTask; }
public BukkitTask getFireTask() { return fireTask; }
public void setTargetLocation(Location targetLocation) { public void setFireTask(BukkitTask fireTask) { this.fireTask = fireTask; }
this.targetLocation = targetLocation; public BukkitTask getTickTask() { return tickTask; }
} public ExplosionResult getExplosionResult() { return explosionResult; }
public void setExplosionResult(ExplosionResult explosionResult) { this.explosionResult = explosionResult; }
public BukkitTask getAimTask() { public OrbitalConfiguration getSimulatedOrbit() { return simulatedOrbit; }
return aimTask; public Location getSkyRenderLocation() { return skyRenderLocation; }
} public void setSkyRenderLocation(Location skyRenderLocation) { this.skyRenderLocation = skyRenderLocation; }
public Location getGroundTraced() { return groundTraced; }
public void setAimTask(BukkitTask aimTask) { public void setGroundTraced(Location groundTraced) { this.groundTraced = groundTraced; }
this.aimTask = aimTask; public int getPower() { return power; }
} public void setPower(int power) { this.power = power; }
public Location getSkyTraceLocation() { return skyTraceLocation; }
public BukkitTask getChargeTask() { public void setSkyTraceLocation(Location skyTraceLocation) { this.skyTraceLocation = skyTraceLocation; }
return chargeTask;
}
public void setChargeTask(BukkitTask chargeTask) {
this.chargeTask = chargeTask;
}
public BukkitTask getFireTask() {
return fireTask;
}
public void setFireTask(BukkitTask fireTask) {
this.fireTask = fireTask;
}
public BukkitTask getTickTask() {
return tickTask;
}
public ExplosionResult getExplosionResult() {
return explosionResult;
}
public void setExplosionResult(ExplosionResult explosionResult) {
this.explosionResult = explosionResult;
}
public OrbitalConfiguration getSimulatedOrbit() {
return simulatedOrbit;
}
public Location getSkyRenderLocation() {
return skyRenderLocation;
}
public void setSkyRenderLocation(Location skyRenderLocation) {
this.skyRenderLocation = skyRenderLocation;
}
public Location getGroundTraced() {
return groundTraced;
}
public void setGroundTraced(Location groundTraced) {
this.groundTraced = groundTraced;
}
public int getPower() {
return power;
}
public void setPower(int power) {
this.power = power;
}
public Location getSkyTraceLocation() {
return skyTraceLocation;
}
public void setSkyTraceLocation(Location skyTraceLocation) {
this.skyTraceLocation = skyTraceLocation;
}
} }
public class OrbitalConfiguration { public static class OrbitalConfiguration {
private Vector baseSatellite; private Vector baseSatellite;
private final Vector[] satelliteOffsets = {
new Vector(0, 0, 0), // base
new Vector(60_000_000, 0, 0), // posX
new Vector(0, 0, 60_000_000), // posZ
new Vector(60_000_000, 0, 60_000_000), // posXZ
new Vector(-60_000_000, 0, 0), // negX
new Vector(0, 0, -60_000_000), // negZ
new Vector(-60_000_000, 0, -60_000_000), // negXZ
new Vector(60_000_000, 0, -60_000_000), // posXNegZ
new Vector(-60_000_000, 0, 60_000_000) // negXPosZ
};
private final Vector tempVector1 = new Vector();
private final Vector tempVector2 = new Vector();
private final Vector[] satellites = new Vector[9];
public OrbitalConfiguration(Vector center) { public OrbitalConfiguration(Vector center) {
this.baseSatellite = center.clone().setY(11_368_121); this.baseSatellite = center.clone().setY(11_368_121);
for (int i = 0; i < satellites.length; i++) {
satellites[i] = new Vector();
}
} }
public void tick() { public void tick() {
Vector orbitalLocation = getBaseSatellite(); Vector orbitalLocation = getBaseSatellite();
if (orbitalLocation.getX() > 30_000_000 || orbitalLocation.getZ() > 30_000_000) { if (orbitalLocation.getX() > 30_000_000 || orbitalLocation.getZ() > 30_000_000) {
setBaseSatellite(new Vector(-orbitalLocation.getX(),orbitalLocation.getY(),-orbitalLocation.getZ())); setBaseSatellite(tempVector1.setX(-orbitalLocation.getX()).setY(orbitalLocation.getY()).setZ(-orbitalLocation.getZ()));
return; return;
} }
setBaseSatellite(orbitalLocation.clone().add(new Vector(2_500,0,762))); tempVector1.setX(2_500).setY(0).setZ(762);
setBaseSatellite(orbitalLocation.clone().add(tempVector1));
} }
public Location getRenderLocation(Location center) { public Location getRenderLocation(Location center) {
@@ -429,27 +416,19 @@ public class OrbitalTrollWand extends AbstractWand implements TrollFeature {
} }
public Vector getNormalToSatellite(Vector target) { public Vector getNormalToSatellite(Vector target) {
Vector closestSatellite = getClosestSatellite(target).clone(); Vector closestSatellite = getClosestSatellite(target);
return closestSatellite.clone().subtract(target).normalize(); return tempVector2.copy(closestSatellite).subtract(target).normalize();
} }
public Vector getNormalToTarget(Vector target) { public Vector getNormalToTarget(Vector target) {
Vector closestSatellite = getClosestSatellite(target).clone(); Vector closestSatellite = getClosestSatellite(target);
return target.clone().subtract(closestSatellite).normalize(); return tempVector2.copy(target).subtract(closestSatellite).normalize();
} }
public Vector getClosestSatellite(Vector location) { public Vector getClosestSatellite(Vector location) {
Vector[] satellites = new Vector[] { for (int i = 0; i < satellites.length; i++) {
getBaseSatellite(), satellites[i].copy(baseSatellite).add(satelliteOffsets[i]);
getPosXSat(), }
getPosZSat(),
getPosXZSat(),
getNegXSat(),
getNegZSat(),
getNegXZSat(),
getPosXNegZSat(),
getNegXPosZSat()
};
Vector closest = satellites[0]; Vector closest = satellites[0];
double minDistance = location.distanceSquared(closest); double minDistance = location.distanceSquared(closest);
@@ -465,50 +444,12 @@ public class OrbitalTrollWand extends AbstractWand implements TrollFeature {
return closest; return closest;
} }
public Vector getPosXSat() { public Vector getBaseSatellite() { return baseSatellite; }
return baseSatellite.clone().add(new Vector(60_000_000,0,0)); public void setBaseSatellite(Vector baseSatellite) { this.baseSatellite = baseSatellite; }
}
public Vector getPosZSat() {
return baseSatellite.clone().add(new Vector(0,0,60_000_000));
}
public Vector getPosXZSat() {
return baseSatellite.clone().add(new Vector(60_000_000,0,60_000_000));
}
public Vector getNegXSat() {
return baseSatellite.clone().add(new Vector(-60_000_000,0,0));
}
public Vector getNegZSat() {
return baseSatellite.clone().add(new Vector(0,0,-60_000_000));
}
public Vector getNegXZSat() {
return baseSatellite.clone().add(new Vector(-60_000_000,0,60_000_000));
}
public Vector getPosXNegZSat() {
return baseSatellite.clone().add(new Vector(60_000_000,0,-60_000_000));
}
public Vector getNegXPosZSat() {
return baseSatellite.clone().add(new Vector(-60_000_000,0,60_000_000));
}
public Vector getBaseSatellite() {
return baseSatellite;
}
public void setBaseSatellite(Vector baseSatellite) {
this.baseSatellite = baseSatellite;
}
} }
private static Location traceTargets(Player player) { private static Location traceTargets(Player player) {
Point hit = CustomDisplayRaytracer.trace(player.getEyeLocation(),player.getEyeLocation().getDirection(),128,CustomDisplayRaytracer.HIT_BLOCK); Point hit = CustomDisplayRaytracer.trace(player.getEyeLocation(), player.getEyeLocation().getDirection(), 128, CustomDisplayRaytracer.HIT_BLOCK);
return hit.getLoc(); return hit.getLoc();
} }
} }