use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class BlockItemSystem method onPlaceBlock.
@ReceiveEvent(components = { BlockItemComponent.class, ItemComponent.class })
public void onPlaceBlock(ActivateEvent event, EntityRef item) {
if (!event.getTarget().exists()) {
event.consume();
return;
}
BlockItemComponent blockItem = item.getComponent(BlockItemComponent.class);
BlockFamily blockFamily = blockItem.blockFamily;
Side surfaceSide = Side.inDirection(event.getHitNormal());
BlockComponent blockComponent = event.getTarget().getComponent(BlockComponent.class);
if (blockComponent == null) {
// If there is no block there (i.e. it's a BlockGroup, we don't allow placing block, try somewhere else)
event.consume();
return;
}
Vector3i targetBlock = new Vector3i(blockComponent.getPosition());
Vector3i placementPos = new Vector3i(targetBlock);
placementPos.add(surfaceSide.direction());
Vector2f relativeAttachmentPosition = getRelativeAttachmentPosition(event);
Block block = blockFamily.getBlockForPlacement(new BlockPlacementData(placementPos, surfaceSide, event.getDirection(), relativeAttachmentPosition));
if (canPlaceBlock(block, targetBlock, placementPos)) {
// TODO: Fix this for changes.
if (networkSystem.getMode().isAuthority()) {
PlaceBlocks placeBlocks = new PlaceBlocks(placementPos, block, event.getInstigator());
worldProvider.getWorldEntity().send(placeBlocks);
if (!placeBlocks.isConsumed()) {
item.send(new OnBlockItemPlaced(placementPos, blockEntityRegistry.getBlockEntityAt(placementPos), event.getInstigator()));
} else {
event.consume();
}
}
recordBlockPlaced(event, blockFamily);
event.getInstigator().send(new PlaySoundEvent(Assets.getSound("engine:PlaceBlock").get(), 0.5f));
} else {
event.consume();
}
}
use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class BlockRegion method iterator.
// -- ITERABLE ---------------------------------------------------------------------------------------------------//
@Override
public Iterator<Vector3ic> iterator() {
if (!isValid()) {
return Collections.emptyIterator();
}
return new Iterator<Vector3ic>() {
private Vector3i current = null;
private final Vector3i next = getMin(new Vector3i());
public boolean findNext() {
next.z++;
if (next.z > maxZ) {
next.z = minZ;
next.y++;
if (next.y > maxY) {
next.y = minY;
next.x++;
}
}
return next.x <= maxX;
}
@Override
public boolean hasNext() {
if (current == null) {
return true;
}
if (current.equals(next.x(), next.y(), next.z())) {
return findNext();
}
return next.x <= maxX;
}
@Override
public Vector3ic next() {
if (current == null) {
current = new Vector3i(next);
return next;
}
if (current.equals(next.x(), next.y(), next.z())) {
if (findNext()) {
return next;
}
return null;
}
current.set(next);
return next;
}
};
}
use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class SparseFieldFacetTest method testGetRelativeMap.
@Test
public void testGetRelativeMap() {
facet.set(0, 1, 2, 4f);
facet.set(0, 1, 3, 3);
facet.set(9, 3, 1, Math.PI);
facet.setWorld(13, 28, 34, 2);
facet.setWorld(10, 21, 35, 1);
Map<Vector3i, Number> expected = ImmutableMap.<Vector3i, Number>of(new Vector3i(0, 1, 2), 4.0f, new Vector3i(0, 1, 3), 3.0f, new Vector3i(3, 8, 4), 2.0f, new Vector3i(0, 1, 5), 1.0f, new Vector3i(9, 3, 1), Math.PI);
assertEquals(expected, facet.getRelativeEntries());
}
use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class InternalLightGeneratorTest method testLightPropagation.
@Test
public void testLightPropagation() {
Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, extraDataManager);
chunk.setBlock(16, 32, 16, fullLight);
InternalLightProcessor.generateInternalLighting(chunk);
assertEquals(fullLight.getLuminance(), chunk.getLight(16, 32, 16));
assertEquals(fullLight.getLuminance() - 1, chunk.getLight(16, 33, 16));
for (int i = 1; i < fullLight.getLuminance(); ++i) {
for (Vector3ic pos : Diamond3iIterable.shell(new Vector3i(16, 32, 16), i).build()) {
assertEquals(fullLight.getLuminance() - i, chunk.getLight(pos));
}
}
}
use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class InternalLightGeneratorTest method testHorizontalSunlightPropagation.
@Test
public void testHorizontalSunlightPropagation() {
Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, extraDataManager);
for (Vector3ic pos : new BlockRegion(0, 4, 0).setSize(Chunks.SIZE_X, 1, Chunks.SIZE_Z)) {
chunk.setBlock(pos, solidBlock);
}
chunk.setBlock(new Vector3i(16, 4, 16), airBlock);
InternalLightProcessor.generateInternalLighting(chunk);
assertEquals(12, chunk.getSunlight(16, 3, 16));
assertEquals(11, chunk.getSunlight(15, 3, 16));
assertEquals(11, chunk.getSunlight(17, 3, 16));
assertEquals(11, chunk.getSunlight(16, 3, 15));
assertEquals(11, chunk.getSunlight(16, 3, 17));
assertEquals(12, chunk.getSunlight(15, 2, 16));
assertEquals(12, chunk.getSunlight(17, 2, 16));
assertEquals(12, chunk.getSunlight(16, 2, 15));
assertEquals(12, chunk.getSunlight(16, 2, 17));
}
Aggregations