@ReceiveEvent(components = {LocationComponent.class}) public void onStartSelectionAtEntity(SetBlockSelectionStartingPointEvent event, EntityRef entity) { LocationComponent locationComponent = entity.getComponent(LocationComponent.class); if (null == locationComponent) { // entity isn't LocationComponent, which shouldn't ever be the case return; } BlockSelectionComponent blockSelectionComponent = event.getBlockSelectionComponent(); if (null == blockSelectionComponent) { // event did not provide a BlockSelection component to modify return; } Vector3f worldPosition = locationComponent.getWorldPosition(); Vector3i startPosition = new Vector3i(worldPosition.x, worldPosition.y, worldPosition.z); blockSelectionComponent.startPosition = startPosition; Vector3i endPosition = startPosition; blockSelectionComponent.currentSelection = Region3i.createBounded(startPosition, endPosition); }
@ReceiveEvent(components = {LocationComponent.class}) public void onEndSelectionAtEntity(SetBlockSelectionEndingPointEvent event, EntityRef entity) { LocationComponent locationComponent = entity.getComponent(LocationComponent.class); if (null == locationComponent) { // entity isn't LocationComponent, which shouldn't ever be the case return; } BlockSelectionComponent blockSelectionComponent = event.getBlockSelectionComponent(); if (null == blockSelectionComponent) { // event did not provide a BlockSelection component to modify return; } Vector3f worldPosition = locationComponent.getWorldPosition(); Vector3i endPosition = new Vector3i(worldPosition.x, worldPosition.y, worldPosition.z); Vector3i startPosition = blockSelectionComponent.startPosition; if (null == startPosition) { startPosition = endPosition; } blockSelectionComponent.currentSelection = Region3i.createBounded(startPosition, endPosition); } }
@Test public void testCreateRegionWithBounds() { Region3i expectedRegion = Region3i.createFromMinMax(new Vector3i(-2, 4, -16), new Vector3i(4, 107, 0)); List<Vector3i> vec1 = Arrays.asList(new Vector3i(-2, 4, -16), new Vector3i(4, 4, -16), new Vector3i(-2, 107, -16), new Vector3i(-2, 4, 0), new Vector3i(4, 107, -16), new Vector3i(4, 4, 0), new Vector3i(-2, 107, 0), new Vector3i(4, 107, 0)); List<Vector3i> vec2 = Arrays.asList(new Vector3i(4, 107, 0), new Vector3i(-2, 107, 0), new Vector3i(4, 4, 0), new Vector3i(4, 107, -16), new Vector3i(-2, 4, 0), new Vector3i(-2, 107, -16), new Vector3i(4, 4, -16), new Vector3i(-2, 4, -16)); for (int i = 0; i < vec1.size(); ++i) { assertEquals(expectedRegion, Region3i.createBounded(vec1.get(i), vec2.get(i))); } }
@Test public void testStopSunlightVertical() { for (Vector3i pos : Region3i.createBounded(new Vector3i(0, 16, 0), new Vector3i(ChunkConstants.SIZE_X - 1, ChunkConstants.SIZE_Y - 1, ChunkConstants.SIZE_Z - 1))) { regenWorldView.setValueAt(pos, ChunkConstants.MAX_SUNLIGHT_REGEN); lightWorldView.setValueAt(pos, ChunkConstants.MAX_SUNLIGHT); } for (Vector3i pos : Region3i.createBounded(new Vector3i(0, 15, 0), new Vector3i(ChunkConstants.SIZE_X - 1, 15, ChunkConstants.SIZE_Z - 1))) { regenWorldView.setBlockAt(pos, solid); } for (Vector3i pos : Region3i.createBounded(new Vector3i(0, 0, 0), new Vector3i(ChunkConstants.SIZE_X - 1, 14, ChunkConstants.SIZE_Z - 1))) { regenWorldView.setValueAt(pos, (byte) (14 - pos.y)); } regenWorldView.setBlockAt(new Vector3i(16, 15, 16), air); propagator.process(new BlockChange(new Vector3i(16, 15, 16), solid, air)); sunlightPropagator.process(new BlockChange(new Vector3i(16, 15, 16), solid, air)); regenWorldView.setBlockAt(new Vector3i(16, 15, 16), solid); propagator.process(new BlockChange(new Vector3i(16, 15, 16), air, solid)); sunlightPropagator.process(new BlockChange(new Vector3i(16, 15, 16), air, solid)); for (Vector3i pos : Region3i.createBounded(new Vector3i(0, 0, 0), new Vector3i(ChunkConstants.SIZE_X - 1, 15, ChunkConstants.SIZE_Z - 1))) { assertEquals("Incorrect value at " + pos, Math.max(0, 14 - pos.y), regenWorldView.getValueAt(pos)); assertEquals("Incorrect value at " + pos, 0, lightWorldView.getValueAt(pos)); } }
EntityRef newDoor = entityManager.create(door.doorRegionPrefab); entity.removeComponent(MeshComponent.class); newDoor.addComponent(new BlockRegionComponent(Region3i.createBounded(bottomBlockPos, topBlockPos))); Vector3f doorCenter = bottomBlockPos.toVector3f(); doorCenter.y += 0.5f;
@Test public void testAllowSunlightVertical() { for (Vector3i pos : Region3i.createBounded(new Vector3i(0, 16, 0), new Vector3i(ChunkConstants.SIZE_X - 1, ChunkConstants.SIZE_Y - 1, ChunkConstants.SIZE_Z - 1))) { regenWorldView.setValueAt(pos, ChunkConstants.MAX_SUNLIGHT_REGEN); lightWorldView.setValueAt(pos, ChunkConstants.MAX_SUNLIGHT); } for (Vector3i pos : Region3i.createBounded(new Vector3i(0, 15, 0), new Vector3i(ChunkConstants.SIZE_X - 1, 15, ChunkConstants.SIZE_Z - 1))) { regenWorldView.setBlockAt(pos, solid); } for (Vector3i pos : Region3i.createBounded(new Vector3i(0, 0, 0), new Vector3i(ChunkConstants.SIZE_X - 1, 14, ChunkConstants.SIZE_Z - 1))) { regenWorldView.setValueAt(pos, (byte) (14 - pos.y)); } regenWorldView.setBlockAt(new Vector3i(16, 15, 16), air); propagator.process(new BlockChange(new Vector3i(16, 15, 16), solid, air)); sunlightPropagator.process(new BlockChange(new Vector3i(16, 15, 16), solid, air)); for (int y = 0; y < 16; y++) { assertEquals("Incorrect value at " + y, ChunkConstants.MAX_SUNLIGHT_REGEN, regenWorldView.getValueAt(new Vector3i(16, y, 16))); assertEquals(ChunkConstants.MAX_SUNLIGHT, lightWorldView.getValueAt(new Vector3i(16, y, 16))); } for (int y = 0; y < 15; y++) { assertEquals(ChunkConstants.MAX_SUNLIGHT - 1, lightWorldView.getValueAt(new Vector3i(15, y, 16))); } }
Region3i region = Region3i.createBounded(regionComponent.corner1, regionComponent.corner2); Vector3f min = new Vector3f(region.minX() - 0.5f, region.minY() - 0.5f, region.minZ() - 0.5f); Vector3f max = new Vector3f(region.maxX() + 0.5f, region.maxY() + 0.5f, region.maxZ() + 0.5f);