Skip to content

Commit 6f9371b

Browse files
committed
Remove while true loop
1 parent 3b94db8 commit 6f9371b

File tree

1 file changed

+37
-38
lines changed

1 file changed

+37
-38
lines changed

core/src/main/java/tc/oc/pgm/projectile/ProjectileMatchModule.java

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -161,47 +161,13 @@ public boolean getAsBoolean() {
161161

162162
projectile.teleport(newLocation);
163163
if (projectileDefinition.damage != null || projectileDefinition.solidBlockCollision) {
164-
boolean finished = false;
165-
while (true) {
166-
if (currentLocation.distanceSquared(incrementingLocation) > currentLocation.distanceSquared(newLocation)) {
167-
incrementingLocation = newLocation.clone();
168-
finished = true;
164+
while (currentLocation.distanceSquared(incrementingLocation) < currentLocation.distanceSquared(newLocation)) {
165+
if (blockDisplayCollision(projectileDefinition, player, incrementingLocation)) {
166+
return true;
169167
}
170-
if (projectileDefinition.damage != null) {
171-
Collection<Entity> nearbyEntities = incrementingLocation.getNearbyEntities(0.5 * projectileDefinition.scale, 0.5 * projectileDefinition.scale, 0.5 * projectileDefinition.scale);
172-
if (!nearbyEntities.isEmpty()) {
173-
Party playerParty = PGM.get().getMatchManager().getPlayer(player).getParty();
174-
for (Entity entity : nearbyEntities) {
175-
if (entity instanceof Player) {
176-
if (playerParty != PGM.get().getMatchManager().getPlayer(((Player) entity)).getParty()) {
177-
((Player) entity).damage(projectileDefinition.damage, player);
178-
return true;
179-
}
180-
}
181-
}
182-
}
183-
}
184-
if (projectileDefinition.solidBlockCollision) {
185-
double posScale = 0.5 * projectileDefinition.scale;
186-
double negScale = -0.5 * projectileDefinition.scale;
187-
188-
Block b1 = incrementingLocation.clone().add(negScale, negScale, negScale).getBlock();
189-
Block b2 = incrementingLocation.clone().add(posScale, negScale, negScale).getBlock();
190-
Block b3 = incrementingLocation.clone().add(negScale, posScale, negScale).getBlock();
191-
Block b4 = incrementingLocation.clone().add(posScale, posScale, negScale).getBlock();
192-
Block b5 = incrementingLocation.clone().add(negScale, negScale, posScale).getBlock();
193-
Block b6 = incrementingLocation.clone().add(posScale, negScale, posScale).getBlock();
194-
Block b7 = incrementingLocation.clone().add(negScale, posScale, posScale).getBlock();
195-
Block b8 = incrementingLocation.clone().add(posScale, posScale, posScale).getBlock();
196-
197-
if (b1.getType().isSolid() || b2.getType().isSolid() || b3.getType().isSolid() || b4.getType().isSolid() || b5.getType().isSolid() || b6.getType().isSolid() || b7.getType().isSolid() || b8.getType().isSolid()) {
198-
return true;
199-
}
200-
}
201-
202-
if (finished) break;
203168
incrementingLocation.add(normalizedDirection.clone().multiply(projectileDefinition.scale));
204169
}
170+
return blockDisplayCollision(projectileDefinition, player, incrementingLocation);
205171
}
206172
return false;
207173
}
@@ -237,6 +203,39 @@ public boolean getAsBoolean() {
237203
}
238204
}
239205

206+
private boolean blockDisplayCollision(ProjectileDefinition projectileDefinition, Player player, Location location) {
207+
if (projectileDefinition.damage != null) {
208+
Collection<Entity> nearbyEntities = location.getNearbyEntities(0.5 * projectileDefinition.scale, 0.5 * projectileDefinition.scale, 0.5 * projectileDefinition.scale);
209+
if (!nearbyEntities.isEmpty()) {
210+
Party playerParty = PGM.get().getMatchManager().getPlayer(player).getParty();
211+
for (Entity entity : nearbyEntities) {
212+
if (entity instanceof Player) {
213+
if (playerParty != PGM.get().getMatchManager().getPlayer(((Player) entity)).getParty()) {
214+
((Player) entity).damage(projectileDefinition.damage, player);
215+
return true;
216+
}
217+
}
218+
}
219+
}
220+
}
221+
if (projectileDefinition.solidBlockCollision) {
222+
double posScale = 0.5 * projectileDefinition.scale;
223+
double negScale = -0.5 * projectileDefinition.scale;
224+
225+
Block b1 = location.clone().add(negScale, negScale, negScale).getBlock();
226+
Block b2 = location.clone().add(posScale, negScale, negScale).getBlock();
227+
Block b3 = location.clone().add(negScale, posScale, negScale).getBlock();
228+
Block b4 = location.clone().add(posScale, posScale, negScale).getBlock();
229+
Block b5 = location.clone().add(negScale, negScale, posScale).getBlock();
230+
Block b6 = location.clone().add(posScale, negScale, posScale).getBlock();
231+
Block b7 = location.clone().add(negScale, posScale, posScale).getBlock();
232+
Block b8 = location.clone().add(posScale, posScale, posScale).getBlock();
233+
234+
return b1.getType().isSolid() || b2.getType().isSolid() || b3.getType().isSolid() || b4.getType().isSolid() || b5.getType().isSolid() || b6.getType().isSolid() || b7.getType().isSolid() || b8.getType().isSolid();
235+
}
236+
return false;
237+
}
238+
240239
// For entities which need their velocity simulated
241240
private Location calculateTo(
242241
final Location entityLocation,

0 commit comments

Comments
 (0)