use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class EntityAwareWorldProviderTest method testEntityExtraComponentsRemovedBeforeCleanUp.
@Test
public void testEntityExtraComponentsRemovedBeforeCleanUp() {
EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i());
entity.addComponent(new StringComponent("test"));
LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), StringComponent.class);
worldProvider.update(1.0f);
assertEquals(Lists.newArrayList(new EventInfo(BeforeDeactivateComponent.newInstance(), entity), new EventInfo(BeforeRemoveComponent.newInstance(), entity)), checker.receivedEvents);
}
use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class EntityAwareWorldProviderTest method testGetTemporaryBlockSendsNoEvent.
@Test
public void testGetTemporaryBlockSendsNoEvent() {
BlockEventChecker checker = new BlockEventChecker();
entityManager.getEventSystem().registerEventHandler(checker);
EntityRef blockEntity = worldProvider.getBlockEntityAt(new Vector3i());
assertTrue(blockEntity.exists());
assertFalse(checker.addedReceived);
assertFalse(checker.activateReceived);
assertFalse(checker.deactivateReceived);
assertFalse(checker.removedReceived);
}
use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class EntityAwareWorldProviderTest method testNetworkComponentRemovedWhenTemporaryCleanedUp.
@Test
public void testNetworkComponentRemovedWhenTemporaryCleanedUp() {
EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i());
entity.addComponent(new RetainedOnBlockChangeComponent(2));
LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), NetworkComponent.class);
entity.removeComponent(RetainedOnBlockChangeComponent.class);
worldProvider.update(1.0f);
assertEquals(Lists.newArrayList(new EventInfo(BeforeDeactivateComponent.newInstance(), entity), new EventInfo(BeforeRemoveComponent.newInstance(), entity)), checker.receivedEvents);
}
use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class EntityAwareWorldProviderTest method testComponentsAddedAndActivatedWhenBlockChanged.
@Disabled("Failing due to #2625. TODO: fix to match new behaviour")
@Test
public void testComponentsAddedAndActivatedWhenBlockChanged() {
LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), StringComponent.class);
worldProvider.setBlock(new Vector3i(), blockWithString);
EntityRef blockEntity = worldProvider.getBlockEntityAt(new Vector3i());
assertTrue(blockEntity.exists());
assertEquals(Lists.newArrayList(new EventInfo(OnAddedComponent.newInstance(), blockEntity), new EventInfo(OnActivatedComponent.newInstance(), blockEntity)), checker.receivedEvents);
}
use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class KinematicCharacterMover method findClimbable.
private Vector3i findClimbable(CharacterMovementComponent movementComp, Vector3f worldPos, boolean swimming, boolean diving) {
Vector3i finalDir = null;
Vector3f[] sides = { new Vector3f(worldPos), new Vector3f(worldPos), new Vector3f(worldPos), new Vector3f(worldPos), new Vector3f(worldPos) };
float factor = 1.0f;
sides[0].x += factor * movementComp.radius;
sides[1].x -= factor * movementComp.radius;
sides[2].z += factor * movementComp.radius;
sides[3].z -= factor * movementComp.radius;
sides[4].y -= movementComp.height;
float distance = 100f;
for (Vector3f side : sides) {
Block block = worldProvider.getBlock(side);
if (block.isClimbable()) {
// If any of our sides are near a climbable block, check if we are near to the side
Vector3i myPos = new Vector3i(worldPos, org.joml.RoundingMode.HALF_UP);
Vector3i climbBlockPos = new Vector3i(side, org.joml.RoundingMode.HALF_UP);
Vector3i dir = new Vector3i(block.getDirection().direction());
float currentDistance = 10f;
if (dir.x != 0 && Math.abs(worldPos.x - climbBlockPos.x + dir.x * .5f) < movementComp.radius + 0.1f) {
if (myPos.x < climbBlockPos.x) {
dir.x = -dir.x;
}
currentDistance = Math.abs(climbBlockPos.z - worldPos.z);
} else if (dir.z != 0 && Math.abs(worldPos.z - climbBlockPos.z + dir.z * .5f) < movementComp.radius + 0.1f) {
if (myPos.z < climbBlockPos.z) {
dir.z = -dir.z;
}
currentDistance = Math.abs(climbBlockPos.z - worldPos.z);
}
// adjacent ledges around a corner.
if (currentDistance < distance) {
distance = currentDistance;
finalDir = dir;
}
}
}
return finalDir;
}
Aggregations