Skip to content

Commit

Permalink
Move the "boundingBoxExpanded" to ElevatorMovement & rename it so "te…
Browse files Browse the repository at this point in the history
…leportingBoundingBox" & new shiftY method.
  • Loading branch information
andrew121410 committed Sep 9, 2024
1 parent 187821d commit 176188e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
29 changes: 9 additions & 20 deletions src/main/java/com/andrew121410/mc/world16elevators/Elevator.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ public class Elevator {
private ElevatorMovement elevatorMovement;
private ElevatorSettings elevatorSettings;

private BoundingBox boundingBoxExpanded;

private Map<Integer, ElevatorFloor> floorsMap;

//TEMP DON'T SAVE
Expand Down Expand Up @@ -79,9 +77,6 @@ public Elevator(World16Elevators plugin, String name, String world, ElevatorMove
this.elevatorMovement = elevatorMovement;
this.elevatorSettings = elevatorSettings;

// Expand the bounding box by -1 on the Y axis for minY and +1 on the Y axis for maxY
this.boundingBoxExpanded = this.elevatorMovement.getBoundingBox().clone().expand(0, 1, 0);

this.isGoing = false;
this.isIdling = false;
this.isFloorQueueGoing = false;
Expand All @@ -104,10 +99,12 @@ public Elevator(World16Elevators plugin, String name, String world, ElevatorMove
}
}

// This should be used for like teleporting entities up and down.
public Collection<Entity> getEntities() {
return getBukkitWorld().getNearbyEntities(boundingBoxExpanded);
return getBukkitWorld().getNearbyEntities(this.getElevatorMovement().getTeleportingBoundingBox());
}

// This should be used for like teleporting entities up and down.
public Collection<Player> getPlayers() {
return getEntities().stream().filter(entity -> entity instanceof Player).map(entity -> (Player) entity).collect(Collectors.toList());
}
Expand Down Expand Up @@ -242,15 +239,7 @@ private void moveWithWorldEdit(int howManyY, boolean goUP) {
return;
}

if (goUP) {
this.elevatorMovement.getAtDoor().add(0, howManyY, 0);
this.elevatorMovement.getBoundingBox().shift(0, howManyY, 0);
this.boundingBoxExpanded.shift(0, howManyY, 0);
} else {
this.elevatorMovement.getAtDoor().subtract(0, howManyY, 0);
this.elevatorMovement.getBoundingBox().shift(0, -howManyY, 0);
this.boundingBoxExpanded.shift(0, -howManyY, 0);
}
this.elevatorMovement.shiftY(goUP ? howManyY : -howManyY);
}

// Ran when it actually reaches a floor.
Expand Down Expand Up @@ -381,13 +370,13 @@ public Map<Location, Material> showLocationOfElevator(Map<Location, Material> ma
}

if (atDoor == null) {
atDoor = elevatorMovement.getAtDoor().clone();
atDoor = this.elevatorMovement.getAtDoor().clone();
}
if (boundingBox == null) {
boundingBox = elevatorMovement.getBoundingBox().clone();
boundingBox = this.elevatorMovement.getBoundingBox().clone();
}
if (boundingBoxExpanded == null) {
boundingBoxExpanded = this.boundingBoxExpanded.clone();
boundingBoxExpanded = this.elevatorMovement.getTeleportingBoundingBox().clone();
}

Map<Location, Material> blockMap = new HashMap<>();
Expand Down Expand Up @@ -477,7 +466,7 @@ public Map<Location, Material> fixUnalignedElevator(Player player, boolean confi
if (confirmChange) {
// Shift the elevator bounding box to where the function thinks the elevator is at
this.elevatorMovement.getBoundingBox().shift(0, shiftAmount, 0);
this.boundingBoxExpanded.shift(0, shiftAmount, 0);
this.elevatorMovement.getTeleportingBoundingBox().shift(0, shiftAmount, 0);

// Update the Y position of the door
this.elevatorMovement.getAtDoor().setY(y);
Expand All @@ -494,7 +483,7 @@ public Map<Location, Material> fixUnalignedElevator(Player player, boolean confi
break;
} else { // Show where the elevator is at.
BoundingBox clonedBoundingBox = this.elevatorMovement.getBoundingBox().clone().shift(0, shiftAmount, 0);
BoundingBox clonedExpandedBoundingBox = this.boundingBoxExpanded.clone().shift(0, shiftAmount, 0);
BoundingBox clonedExpandedBoundingBox = this.elevatorMovement.getTeleportingBoundingBox().clone().shift(0, shiftAmount, 0);
Location clonedAtDoor = this.elevatorMovement.getAtDoor().clone();
clonedAtDoor.setY(y);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,30 @@ public class ElevatorMovement {
private Integer floor;

private Location atDoor;
private BoundingBox boundingBox;
private BoundingBox boundingBox; // This is the bounding box of the blocks we have to move, up and down.
private BoundingBox teleportingBoundingBox; // This bounding box is used for teleporting the player up and down.

public ElevatorMovement(Integer floor, Location atDoor, BoundingBox boundingBox, BoundingBox teleportingBoundingBox) {
this.floor = floor;
this.atDoor = ElevatorFloor.ifIronDoorThenGetBlockUnderTheDoorIfNotThanReturn(atDoor).getLocation();
this.boundingBox = boundingBox;
this.teleportingBoundingBox = teleportingBoundingBox;
}

public ElevatorMovement(Integer floor, Location atDoor, BoundingBox boundingBox) {
this.floor = floor;
this.atDoor = ElevatorFloor.ifIronDoorThenGetBlockUnderTheDoorIfNotThanReturn(atDoor).getLocation();
this.boundingBox = boundingBox;
}

/**
* Shift the bounding box and the atDoor location by the amount.
*
* @param amount The amount to shift by. Positive values will shift up, negative values will shift down.
*/
public void shiftY(int amount) {
this.atDoor.add(0, amount, 0);
this.boundingBox.shift(0, amount, 0);
this.teleportingBoundingBox.shift(0, amount, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ public void run() {

// Copy the stuff
BoundingBox copyBoundingBox = elevator.getElevatorMovement().getBoundingBox().clone();
BoundingBox copyExpandedBoundingBox = elevator.getBoundingBoxExpanded().clone();
BoundingBox copyExpandedBoundingBox = elevator.getElevatorMovement().getTeleportingBoundingBox().clone();
Location copyAtDoor = elevator.getElevatorMovement().getAtDoor().clone();

// Shift the stuff
Expand All @@ -950,7 +950,7 @@ public void run() {

// Set the new values.
elevator.getElevatorMovement().setBoundingBox(copyBoundingBox);
elevator.setBoundingBoxExpanded(copyExpandedBoundingBox);
elevator.getElevatorMovement().setTeleportingBoundingBox(copyExpandedBoundingBox);
elevator.getElevatorMovement().setAtDoor(copyAtDoor);

p1.sendMessage(Translate.miniMessage("<green>The changes have been confirmed."));
Expand Down

0 comments on commit 176188e

Please sign in to comment.