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