Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,10 @@ public boolean isCannonBlock(Block block) {
return false;
}

if (!design.isAllowedMaterial(block.getType())) {
return false;
}

for (SimpleBlock designBlock : design.getAllCannonBlocks(getCannonDirection())) {
if (designBlock.compareMaterialAndLoc(block, getOffset())) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ public boolean isLoadingInterface(Vector loc) {
}
return false;
}

/**
* returns the location off one firing Trigger
* @return the firing trigger. (can be null if there is no trigger on the cannon)
*/
public Vector getFiringTrigger() {
//return one tigger
if (rightClickTrigger!= null && !rightClickTrigger.isEmpty())
return rightClickTrigger.get(0);
return rightClickTrigger.get(0);
if (redstoneTrigger != null && !redstoneTrigger.isEmpty())
return redstoneTrigger.get(0);
return null;
}

public Vector getRotationCenter() {
return rotationCenter;
}
Expand Down Expand Up @@ -154,5 +154,49 @@ public void setDestructibleBlocks(ArrayList<Vector> destructibleBlocks) {
public void addDestructibleBlocks(Vector add) {
this.destructibleBlocks.add(add);
}



private Vector min = null;
public Vector getMin() {
if (min != null) return min;
calculateMaxMin();
return min;
}

private Vector max = null;
public Vector getMax() {
if (max != null) return max;
calculateMaxMin();
return max;
}

private void calculateMaxMin() {
Vector minT = allCannonBlocks.get(0).toVector();
Vector maxT = minT.clone();

for (var block : allCannonBlocks) {
Vector vec = block.toVector();

minT.setX(Math.min(minT.getX(), vec.getX()));
minT.setY(Math.min(minT.getY(), vec.getY()));
minT.setZ(Math.min(minT.getZ(), vec.getZ()));

maxT.setX(Math.max(maxT.getX(), vec.getX()));
maxT.setY(Math.max(maxT.getY(), vec.getY()));
maxT.setZ(Math.max(maxT.getZ(), vec.getZ()));
}

min = minT;
max = maxT;
}

private double diagonal = -1;
public double getDiagonal() {
if (diagonal < 0) {
calculateMaxMin();
diagonal = max.distance(min);
}

return diagonal;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,14 @@ public static Cannon getCannon(String cannonName) {
* @return the cannon at this location
*/
public Cannon getCannonFromStorage(Location loc) {
Vector vector = loc.toVector();
for (Cannon cannon : cannonList.values()) {
//To make code faster on servers with a lot of cannons we check the distance squared
if (loc.toVector().distanceSquared(cannon.getOffset()) <= 1024 && cannon.isCannonBlock(loc.getBlock())) {
var design = cannon.getCannonDesign();
var cannonBlocks = design.getCannonBlockMap().get(cannon.getCannonDirection());
double diagonal = cannonBlocks.getDiagonal();
if (diagonal < 0 || vector.distance(cannon.getOffset()) >= diagonal) continue;

if (cannon.isCannonBlock(loc.getBlock())) {
return cannon;
}
}
Expand Down