From 5515db111efe5dcdaa7d9c4ff15d57c507988e5c Mon Sep 17 00:00:00 2001 From: Zak <34372536+ZakShearman@users.noreply.github.com> Date: Mon, 30 Sep 2024 20:17:49 +0100 Subject: [PATCH] fix: account for rotation on tower destroy --- .../model/tower/placed/PlacedTower.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/PlacedTower.java b/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/PlacedTower.java index 35a5335..3b8a7e3 100644 --- a/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/PlacedTower.java +++ b/src/main/java/pink/zak/minestom/towerdefence/model/tower/placed/PlacedTower.java @@ -39,6 +39,7 @@ public abstract class PlacedTower { protected final int id; protected final @NotNull Point basePoint; protected final @NotNull Direction facing; + protected final @NotNull Rotation rotation; protected final @NotNull GameUser owner; protected @NotNull T level; @@ -51,6 +52,7 @@ protected PlacedTower(@NotNull GameHandler gameHandler, Tower configuration, int this.id = id; this.basePoint = basePoint; this.facing = facing; + this.rotation = Rotation.values()[DirectionUtil.fromDirection(facing).getTurns()]; this.owner = owner; this.level = (T) configuration.getLevel(level); @@ -106,10 +108,7 @@ public void upgrade(int level, @Nullable GameUser user) { // todo re-investigate using a batch to apply in the future // it was buggy last time it was tried private void placeLevel() { - int turns = DirectionUtil.fromDirection(this.facing).getTurns(); - Rotation rotation = Rotation.values()[turns]; - - this.level.getSchematic().apply(rotation, (relativePoint, block) -> { + this.level.getSchematic().apply(this.rotation, (relativePoint, block) -> { // Add the ID_TAG with the tower's ID to each block block = block.withTag(ID_TAG, this.id); @@ -130,11 +129,8 @@ private void placeBase() { } private void removeNonUpdatedBlocks(TowerLevel oldLevel, TowerLevel newLevel) { - int turns = DirectionUtil.fromDirection(this.facing).getTurns(); - Rotation rotation = Rotation.values()[turns]; - - Set oldRelativePoints = SchemUtils.getRelativeBlockPoints(rotation, oldLevel.getSchematic()); - Set newRelativePoints = SchemUtils.getRelativeBlockPoints(rotation, newLevel.getSchematic()); + Set oldRelativePoints = SchemUtils.getRelativeBlockPoints(this.rotation, oldLevel.getSchematic()); + Set newRelativePoints = SchemUtils.getRelativeBlockPoints(this.rotation, newLevel.getSchematic()); TowerDefenceInstance instance = this.gameHandler.getInstance(); for (Point relativePoint : oldRelativePoints) { @@ -148,7 +144,7 @@ public void destroy() { Set relativePositions = this.getConfiguration().getLevels().stream() .filter(level -> level.asInteger() <= this.level.asInteger()) .map(TowerLevel::getSchematic) - .map(schem -> SchemUtils.getRelativeBlockPoints(Rotation.NONE, schem)) + .map(schem -> SchemUtils.getRelativeBlockPoints(this.rotation, schem)) .flatMap(Set::stream) .collect(Collectors.toSet());