removed cause of tetris collision bugs (yaw, pitch in Pos)
This commit is contained in:
@@ -8,10 +8,7 @@ import net.minestom.server.entity.metadata.other.FallingBlockMeta;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.tag.Tag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
public class Tetromino {
|
||||
private final static EntityType ghostEntityType = EntityType.FALLING_BLOCK;
|
||||
@@ -44,21 +41,17 @@ public class Tetromino {
|
||||
}
|
||||
|
||||
public void setPosition(Pos newPosition) {
|
||||
this.position = newPosition;
|
||||
this.position = new Pos(newPosition.x(), newPosition.y(), newPosition.z());
|
||||
}
|
||||
|
||||
public boolean rotate(boolean clockwise) {
|
||||
int[][] newShapeArray = this.getTurnedShapeArray(clockwise);
|
||||
Orientation newOrientation = this.orientation.rotated(clockwise);
|
||||
|
||||
// TODO: doesn't work for I-Tetromino
|
||||
int[][] kicksArray = RotationChecker.getKicksArray(this.orientation, newOrientation, this.shape);
|
||||
System.out.println(this.shape.toString() + ": " + Arrays.deepToString(kicksArray));
|
||||
for(int[] k : kicksArray) {
|
||||
Pos candidate = new Pos(this.position.x() + k[0], this.position.y() + k[1], this.position.z());
|
||||
boolean moved = this.checkCollisionAndMove(candidate, newShapeArray);
|
||||
System.out.println("Candidate: " + Arrays.toString(k) + " " + moved);
|
||||
if(moved) {
|
||||
if(this.checkCollisionAndMove(candidate, newShapeArray)) {
|
||||
this.orientation = newOrientation;
|
||||
return true;
|
||||
}
|
||||
@@ -198,7 +191,7 @@ public class Tetromino {
|
||||
|
||||
private boolean isPartOfTetromino(Pos position) {
|
||||
return this.getBlockPositions().stream()
|
||||
.anyMatch(pos -> pos.equals(position));
|
||||
.anyMatch(pos -> pos.sameBlock(position));
|
||||
}
|
||||
|
||||
private List<Pos> getBlockPositions() {
|
||||
@@ -214,9 +207,10 @@ public class Tetromino {
|
||||
for(int x = 0; x < arrayLength; x++) {
|
||||
for(int y = 0; y < arrayLength; y++) {
|
||||
if(shapeArray[arrayLength - 1 - y][x] == 1) {
|
||||
switch(this.shape) {
|
||||
case I -> returnList.add(new Pos(position).add(x - 2, y - 2, 0));
|
||||
default -> returnList.add(new Pos(position).add(x - 1, y - 1, 0));
|
||||
if(Objects.requireNonNull(this.shape) == Shape.I) {
|
||||
returnList.add(position.add(x - 2, y - 2, 0));
|
||||
} else {
|
||||
returnList.add(position.add(x - 1, y - 1, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -225,21 +219,6 @@ public class Tetromino {
|
||||
return returnList;
|
||||
}
|
||||
|
||||
// private List<Pos> getBlockPositions(Pos position, int[][] shapeArray) {
|
||||
// List<Pos> returnList = new ArrayList<>();
|
||||
// if(position == null) return returnList;
|
||||
//
|
||||
// for(int x = 0; x < shapeArray.length; x++) {
|
||||
// for(int y = 0; y < shapeArray.length; y++) {
|
||||
// if(shapeArray[x][y] == 1) {
|
||||
// returnList.add(new Pos(position).sub(1, 1, 0).add(x, y, 0));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return returnList;
|
||||
// }
|
||||
|
||||
private boolean hasCollision(Pos newPosition, int[][] newShapeArray) {
|
||||
List<Pos> newBlockPositions = this.getBlockPositions(newPosition, newShapeArray);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user