Skip to content

Commit

Permalink
Height control ( #13 )
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasDeBruijn committed Aug 23, 2021
1 parent c00062e commit d034f0e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/main/java/dev/array21/harotorch/config/ConfigManifest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ public class ConfigManifest {
@Required
public Integer torchRange;

/**
* The Y height above the Torch where it will have an effect
*/
@Required
public Integer torchAboveYRange;

/**
* The Y height below the Torch where it will have an effect
*/
@Required
public Integer torchBelowYRange;

/**
* What radius should we use to highlight Torches
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public void onCreatureSpawnEvent(CreatureSpawnEvent event) {
}

private boolean torchInRange(Location entityLocation) {
int yAboveLim = this.plugin.getConfigManifest().torchAboveYRange;
int yBelowLim = this.plugin.getConfigManifest().torchBelowYRange;

//Iterate over all Torches
for(Torch t : TorchHandler.getTorches()) {

Expand All @@ -81,19 +84,40 @@ private boolean torchInRange(Location entityLocation) {

if(this.plugin.getConfigManifest().getTorchRangeShape() == TorchRangeShape.CIRCLE) {
//Check if the distance cylindrical is less than the defined range squared
if(TorchHandler.getDistanceCylindrical(t.getLocation(), entityLocation) < HaroTorch.RANGE) {
return true;
if(TorchHandler.getDistanceCylindrical(t.getLocation(), entityLocation) > HaroTorch.RANGE) {
return false;
}
} else {
Location lTorch = t.getLocation();
double distanceX = Math.abs(lTorch.getX() - entityLocation.getX());
double distanceZ = Math.abs(lTorch.getZ() - entityLocation.getZ());

int radius = this.plugin.getConfigManifest().torchRange;
if(distanceX < radius && distanceZ < radius) {
return true;
if(!(distanceX < radius && distanceZ < radius)) {
return false;
}
}

boolean yAboveSatisfied = false;
boolean yBelowSatisfied = false;

if(yAboveLim != -1) {
if(t.getLocation().getY() + yAboveLim <= entityLocation.getY()) {
yAboveSatisfied = true;
}
} else {
yAboveSatisfied = true;
}

if(yBelowLim != -1) {
if(t.getLocation().getY() - yBelowLim >= entityLocation.getY()) {
yBelowSatisfied = true;
}
} else {
yBelowSatisfied = true;
}

return yAboveSatisfied && yBelowSatisfied;
}

return false;
Expand Down

0 comments on commit d034f0e

Please sign in to comment.