Rename collisionShape

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-04-24 07:11:22 +02:00
parent 8b61fc8a2d
commit 0173aace98
6 changed files with 34 additions and 34 deletions

View File

@ -344,9 +344,9 @@ final class BlockCollision {
// If player is at block 40 we cannot place a block at block 39 with side length 1 because the block will be in [39, 40] // If player is at block 40 we cannot place a block at block 39 with side length 1 because the block will be in [39, 40]
// For this reason we subtract a small amount from the player position // For this reason we subtract a small amount from the player position
Point playerPos = entity.getPosition().add(entity.getPosition().sub(blockPos).mul(0.0000001)); Point playerPos = entity.getPosition().add(entity.getPosition().sub(blockPos).mul(0.0000001));
intersects = b.registry().shape().intersectBox(playerPos.sub(blockPos), entity.getBoundingBox()); intersects = b.registry().collisionShape().intersectBox(playerPos.sub(blockPos), entity.getBoundingBox());
} else { } else {
intersects = b.registry().shape().intersectBox(entity.getPosition().sub(blockPos), entity.getBoundingBox()); intersects = b.registry().collisionShape().intersectBox(entity.getPosition().sub(blockPos), entity.getBoundingBox());
} }
if (intersects) return entity; if (intersects) return entity;
} }
@ -374,7 +374,7 @@ final class BlockCollision {
boolean hitBlock = false; boolean hitBlock = false;
if (checkBlock.isSolid()) { if (checkBlock.isSolid()) {
final Vec blockPos = new Vec(blockX, blockY, blockZ); final Vec blockPos = new Vec(blockX, blockY, blockZ);
hitBlock = checkBlock.registry().shape().intersectBoxSwept(entityPosition, entityVelocity, blockPos, boundingBox, finalResult); hitBlock = checkBlock.registry().collisionShape().intersectBoxSwept(entityPosition, entityVelocity, blockPos, boundingBox, finalResult);
} }
return hitBlock; return hitBlock;
} }

View File

@ -666,7 +666,7 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
// Move a small amount towards the entity. If the entity is within 0.01 blocks of the block, touch will trigger // Move a small amount towards the entity. If the entity is within 0.01 blocks of the block, touch will trigger
Vec blockPos = new Vec(x, y, z); Vec blockPos = new Vec(x, y, z);
Point blockEntityVector = (blockPos.sub(position)).normalize().mul(0.01); Point blockEntityVector = (blockPos.sub(position)).normalize().mul(0.01);
if (block.registry().shape().intersectBox(position.sub(blockPos).add(blockEntityVector), boundingBox)) { if (block.registry().collisionShape().intersectBox(position.sub(blockPos).add(blockEntityVector), boundingBox)) {
handler.onTouch(new BlockHandler.Touch(block, instance, new Vec(x, y, z), this)); handler.onTouch(new BlockHandler.Touch(block, instance, new Vec(x, y, z), this));
} }
} }

View File

@ -65,7 +65,7 @@ final class BlockLightCompute {
final int newIndex = xO | (zO << 4) | (yO << 8); final int newIndex = xO | (zO << 4) | (yO << 8);
final Block currentBlock = Objects.requireNonNullElse(blocks[x | (z << 4) | (y << 8)], Block.AIR); final Block currentBlock = Objects.requireNonNullElse(blocks[x | (z << 4) | (y << 8)], Block.AIR);
final Block propagatedBlock = Objects.requireNonNullElse(blocks[newIndex], Block.AIR); final Block propagatedBlock = Objects.requireNonNullElse(blocks[newIndex], Block.AIR);
if (currentBlock.registry().shape().isOccluded(propagatedBlock.registry().shape(), face)) if (currentBlock.registry().collisionShape().isOccluded(propagatedBlock.registry().collisionShape(), face))
continue; continue;
if (getLight(lightArray, newIndex) + 2 <= lightLevel) { if (getLight(lightArray, newIndex) + 2 <= lightLevel) {
placeLight(lightArray, newIndex, newLightLevel); placeLight(lightArray, newIndex, newLightLevel);

View File

@ -275,7 +275,7 @@ public final class Registry {
return materialSupplier.get(); return materialSupplier.get();
} }
public Shape shape() { public Shape collisionShape() {
return shape; return shape;
} }

View File

@ -79,8 +79,8 @@ public class BlockTest {
@Test @Test
public void testShape() { public void testShape() {
Point start = Block.LANTERN.registry().shape().relativeStart(); Point start = Block.LANTERN.registry().collisionShape().relativeStart();
Point end = Block.LANTERN.registry().shape().relativeEnd(); Point end = Block.LANTERN.registry().collisionShape().relativeEnd();
assertEquals(start, new Vec(0.312, 0, 0.312)); assertEquals(start, new Vec(0.312, 0, 0.312));
assertEquals(end, new Vec(0.687, 0.562, 0.687)); assertEquals(end, new Vec(0.687, 0.562, 0.687));

View File

@ -13,7 +13,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class BlockIsOccludedTest { public class BlockIsOccludedTest {
@Test @Test
public void blockAir() { public void blockAir() {
Shape airBlock = Block.AIR.registry().shape(); Shape airBlock = Block.AIR.registry().collisionShape();
for (BlockFace face : BlockFace.values()) { for (BlockFace face : BlockFace.values()) {
assertFalse(airBlock.isOccluded(airBlock, face)); assertFalse(airBlock.isOccluded(airBlock, face));
@ -22,8 +22,8 @@ public class BlockIsOccludedTest {
@Test @Test
public void blockLantern() { public void blockLantern() {
Shape shape = Block.LANTERN.registry().shape(); Shape shape = Block.LANTERN.registry().collisionShape();
Shape airBlock = Block.AIR.registry().shape(); Shape airBlock = Block.AIR.registry().collisionShape();
for (BlockFace face : BlockFace.values()) { for (BlockFace face : BlockFace.values()) {
assertFalse(shape.isOccluded(airBlock, face)); assertFalse(shape.isOccluded(airBlock, face));
@ -32,8 +32,8 @@ public class BlockIsOccludedTest {
@Test @Test
public void blockCauldron() { public void blockCauldron() {
Shape shape = Block.CAULDRON.registry().shape(); Shape shape = Block.CAULDRON.registry().collisionShape();
Shape airBlock = Block.AIR.registry().shape(); Shape airBlock = Block.AIR.registry().collisionShape();
for (BlockFace face : BlockFace.values()) { for (BlockFace face : BlockFace.values()) {
assertFalse(shape.isOccluded(airBlock, face)); assertFalse(shape.isOccluded(airBlock, face));
@ -42,8 +42,8 @@ public class BlockIsOccludedTest {
@Test @Test
public void blockSlabBottomAir() { public void blockSlabBottomAir() {
Shape shape = Block.SANDSTONE_SLAB.registry().shape(); Shape shape = Block.SANDSTONE_SLAB.registry().collisionShape();
Shape airBlock = Block.AIR.registry().shape(); Shape airBlock = Block.AIR.registry().collisionShape();
assertTrue(shape.isOccluded(airBlock, BlockFace.BOTTOM)); assertTrue(shape.isOccluded(airBlock, BlockFace.BOTTOM));
@ -56,8 +56,8 @@ public class BlockIsOccludedTest {
@Test @Test
public void blockSlabTopEnchantingTable() { public void blockSlabTopEnchantingTable() {
Shape shape1 = Block.SANDSTONE_SLAB.withProperty("type", "top").registry().shape(); Shape shape1 = Block.SANDSTONE_SLAB.withProperty("type", "top").registry().collisionShape();
Shape shape2 = Block.ENCHANTING_TABLE.registry().shape(); Shape shape2 = Block.ENCHANTING_TABLE.registry().collisionShape();
assertFalse(shape1.isOccluded(shape2, BlockFace.BOTTOM)); assertFalse(shape1.isOccluded(shape2, BlockFace.BOTTOM));
@ -73,9 +73,9 @@ public class BlockIsOccludedTest {
Shape shape = Block.SANDSTONE_STAIRS.withProperties(Map.of( Shape shape = Block.SANDSTONE_STAIRS.withProperties(Map.of(
"facing", "west", "facing", "west",
"half", "bottom", "half", "bottom",
"shape", "straight")).registry().shape(); "shape", "straight")).registry().collisionShape();
Shape airBlock = Block.AIR.registry().shape(); Shape airBlock = Block.AIR.registry().collisionShape();
assertTrue(shape.isOccluded(airBlock, BlockFace.WEST)); assertTrue(shape.isOccluded(airBlock, BlockFace.WEST));
assertTrue(shape.isOccluded(airBlock, BlockFace.BOTTOM)); assertTrue(shape.isOccluded(airBlock, BlockFace.BOTTOM));
@ -88,8 +88,8 @@ public class BlockIsOccludedTest {
@Test @Test
public void blockSlabBottomStone() { public void blockSlabBottomStone() {
Shape shape = Block.SANDSTONE_SLAB.registry().shape(); Shape shape = Block.SANDSTONE_SLAB.registry().collisionShape();
Shape stoneBlock = Block.STONE.registry().shape(); Shape stoneBlock = Block.STONE.registry().collisionShape();
assertTrue(shape.isOccluded(stoneBlock, BlockFace.BOTTOM)); assertTrue(shape.isOccluded(stoneBlock, BlockFace.BOTTOM));
assertTrue(shape.isOccluded(stoneBlock, BlockFace.NORTH)); assertTrue(shape.isOccluded(stoneBlock, BlockFace.NORTH));
@ -101,8 +101,8 @@ public class BlockIsOccludedTest {
@Test @Test
public void blockStone() { public void blockStone() {
Shape shape = Block.STONE.registry().shape(); Shape shape = Block.STONE.registry().collisionShape();
Shape airBlock = Block.AIR.registry().shape(); Shape airBlock = Block.AIR.registry().collisionShape();
for (BlockFace face : BlockFace.values()) { for (BlockFace face : BlockFace.values()) {
assertTrue(shape.isOccluded(airBlock, face)); assertTrue(shape.isOccluded(airBlock, face));
@ -111,8 +111,8 @@ public class BlockIsOccludedTest {
@Test @Test
public void blockStair() { public void blockStair() {
Shape shape = Block.SANDSTONE_STAIRS.registry().shape(); Shape shape = Block.SANDSTONE_STAIRS.registry().collisionShape();
Shape airBlock = Block.AIR.registry().shape(); Shape airBlock = Block.AIR.registry().collisionShape();
assertTrue(shape.isOccluded(airBlock, BlockFace.NORTH)); assertTrue(shape.isOccluded(airBlock, BlockFace.NORTH));
assertTrue(shape.isOccluded(airBlock, BlockFace.BOTTOM)); assertTrue(shape.isOccluded(airBlock, BlockFace.BOTTOM));
@ -125,8 +125,8 @@ public class BlockIsOccludedTest {
@Test @Test
public void blockSlab() { public void blockSlab() {
Shape shape = Block.SANDSTONE_SLAB.registry().shape(); Shape shape = Block.SANDSTONE_SLAB.registry().collisionShape();
Shape airBlock = Block.AIR.registry().shape(); Shape airBlock = Block.AIR.registry().collisionShape();
assertTrue(shape.isOccluded(airBlock, BlockFace.BOTTOM)); assertTrue(shape.isOccluded(airBlock, BlockFace.BOTTOM));
@ -139,8 +139,8 @@ public class BlockIsOccludedTest {
@Test @Test
public void blockSlabBottomAndSlabTop() { public void blockSlabBottomAndSlabTop() {
Shape shape1 = Block.SANDSTONE_SLAB.registry().shape(); Shape shape1 = Block.SANDSTONE_SLAB.registry().collisionShape();
Shape shape2 = Block.SANDSTONE_SLAB.withProperty("type", "top").registry().shape(); Shape shape2 = Block.SANDSTONE_SLAB.withProperty("type", "top").registry().collisionShape();
assertFalse(shape1.isOccluded(shape2, BlockFace.TOP)); assertFalse(shape1.isOccluded(shape2, BlockFace.TOP));
@ -153,7 +153,7 @@ public class BlockIsOccludedTest {
@Test @Test
public void blockSlabBottomAndSlabBottom() { public void blockSlabBottomAndSlabBottom() {
Shape shape = Block.SANDSTONE_SLAB.registry().shape(); Shape shape = Block.SANDSTONE_SLAB.registry().collisionShape();
assertTrue(shape.isOccluded(shape, BlockFace.BOTTOM)); assertTrue(shape.isOccluded(shape, BlockFace.BOTTOM));
assertTrue(shape.isOccluded(shape, BlockFace.TOP)); assertTrue(shape.isOccluded(shape, BlockFace.TOP));
@ -166,8 +166,8 @@ public class BlockIsOccludedTest {
@Test @Test
public void blockStairAndSlabBottom() { public void blockStairAndSlabBottom() {
Shape shape1 = Block.STONE_STAIRS.registry().shape(); Shape shape1 = Block.STONE_STAIRS.registry().collisionShape();
Shape shape2 = Block.SANDSTONE_SLAB.registry().shape(); Shape shape2 = Block.SANDSTONE_SLAB.registry().collisionShape();
assertTrue(shape1.isOccluded(shape2, BlockFace.BOTTOM)); assertTrue(shape1.isOccluded(shape2, BlockFace.BOTTOM));
assertTrue(shape1.isOccluded(shape2, BlockFace.NORTH)); assertTrue(shape1.isOccluded(shape2, BlockFace.NORTH));
@ -180,8 +180,8 @@ public class BlockIsOccludedTest {
@Test @Test
public void blockStairAndSlabTop() { public void blockStairAndSlabTop() {
Shape shape1 = Block.STONE_STAIRS.registry().shape(); Shape shape1 = Block.STONE_STAIRS.registry().collisionShape();
Shape shape2 = Block.SANDSTONE_SLAB.withProperty("type", "top").registry().shape(); Shape shape2 = Block.SANDSTONE_SLAB.withProperty("type", "top").registry().collisionShape();
assertTrue(shape1.isOccluded(shape2, BlockFace.NORTH)); assertTrue(shape1.isOccluded(shape2, BlockFace.NORTH));
assertTrue(shape1.isOccluded(shape2, BlockFace.BOTTOM)); assertTrue(shape1.isOccluded(shape2, BlockFace.BOTTOM));