добавлены тесты для SimpleWorld
This commit is contained in:
@@ -5,8 +5,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class EntityLocationTest {
|
||||
private static final ThreadLocalRandom rnd = ThreadLocalRandom.current();
|
||||
@@ -42,6 +41,7 @@ class EntityLocationTest {
|
||||
EntityLocation locOrig = new EntityLocation(x, y, z, yaw, pitch);
|
||||
EntityLocation locClone = locOrig.clone();
|
||||
assertEquals(locOrig, locClone);
|
||||
assertNotSame(locOrig, locClone);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.List;
|
||||
public class FlatChunkProvider implements ChunkProvider {
|
||||
private ChunkSection chunkSection;
|
||||
|
||||
public void setLayersBlock(List<String> listOfLayers) {
|
||||
public void setLayersBlockAsString(List<String> listOfLayers) {
|
||||
List<BlockType> layoutsBlock = new ArrayList<>();
|
||||
|
||||
for (String value : listOfLayers) {
|
||||
@@ -29,6 +29,10 @@ public class FlatChunkProvider implements ChunkProvider {
|
||||
}
|
||||
}
|
||||
|
||||
setLayersBlock(layoutsBlock);
|
||||
}
|
||||
|
||||
public void setLayersBlock(List<BlockType> layoutsBlock) {
|
||||
this.chunkSection = new SimpleChunkSection(layoutsBlock);
|
||||
}
|
||||
|
||||
@@ -41,11 +45,11 @@ public class FlatChunkProvider implements ChunkProvider {
|
||||
|
||||
@Override
|
||||
public void saveChunk(Chunk chunk) {
|
||||
//TODO ignore
|
||||
//FIXME nope...
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveChunk(Chunk... chunks) {
|
||||
//TODO ignore
|
||||
//FIXME nope...
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-04-28
|
||||
*/
|
||||
package mc.world.simple;
|
||||
|
||||
import mc.core.world.Biome;
|
||||
@@ -65,6 +61,13 @@ public class SimpleChunkSection implements ChunkSection {
|
||||
|
||||
@Override
|
||||
public Block getBlock(int x, int y, int z) {
|
||||
if (x < 0) x = 0;
|
||||
else if (x > 15) x = 15;
|
||||
if (y < 0) y = 0;
|
||||
else if (y > 15) y = 15;
|
||||
if (z < 0) z = 0;
|
||||
else if (z > 15) z = 15;
|
||||
|
||||
if (y >= layersBlock.size()) {
|
||||
return blockFactory.create(BlockType.AIR, x, y, z);
|
||||
}
|
||||
|
||||
@@ -9,11 +9,12 @@ import mc.core.world.WorldType;
|
||||
import mc.core.world.chunk.Chunk;
|
||||
import mc.core.world.chunk.ChunkProvider;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class SimpleWorld implements World, BeanNameAware {
|
||||
@Getter
|
||||
private String name;
|
||||
@@ -48,17 +49,6 @@ public class SimpleWorld implements World, BeanNameAware {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setLayersBlock(List<String> listOfLayers) {
|
||||
if (chunkProvider == null) {
|
||||
FlatChunkProvider chunkProvider = new FlatChunkProvider();
|
||||
chunkProvider.setLayersBlock(listOfLayers);
|
||||
this.chunkProvider = chunkProvider;
|
||||
} else if (this.chunkProvider instanceof FlatChunkProvider) {
|
||||
((FlatChunkProvider)chunkProvider).setLayersBlock(listOfLayers);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanName(@Nonnull String name) {
|
||||
this.name = name;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package mc.world.simple;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import mc.core.world.block.Block;
|
||||
import mc.core.world.block.BlockType;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class SimpleChunkSectionTest {
|
||||
private SimpleChunkSection chunkSection;
|
||||
private List<BlockType> layersBlock;
|
||||
|
||||
@BeforeEach
|
||||
void before() {
|
||||
layersBlock = Lists.newArrayList(
|
||||
BlockType.BEDROCK,
|
||||
BlockType.DIRT,
|
||||
BlockType.DIRT,
|
||||
BlockType.GRASS
|
||||
);
|
||||
|
||||
chunkSection = new SimpleChunkSection(layersBlock);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getBlock() {
|
||||
for (int y = 15; y >= 0; y--) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
Block block = chunkSection.getBlock(x, y, z);
|
||||
if (y > layersBlock.size()-1) {
|
||||
assertEquals(block.getBlockType(), BlockType.AIR);
|
||||
} else {
|
||||
assertEquals(block.getBlockType(), layersBlock.get(y));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package mc.world.simple;
|
||||
|
||||
import mc.core.EntityLocation;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = {TestSpringConfig.class})
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
class SimpleWorldTest {
|
||||
@Autowired
|
||||
private SimpleWorld world;
|
||||
|
||||
@Test
|
||||
void spawn() {
|
||||
final EntityLocation location = new EntityLocation(1d, 2d, 3d,4f, 5f);
|
||||
|
||||
world.setSpawn(location);
|
||||
assertEquals(location, world.getSpawn());
|
||||
assertSame(location, world.getSpawn());
|
||||
|
||||
world.setSpawn(1d, 2d, 3d, 4f, 5f);
|
||||
assertEquals(location, world.getSpawn());
|
||||
assertNotSame(location, world.getSpawn());
|
||||
|
||||
location.setYawPitch(0, 0);
|
||||
world.setSpawn(1d, 2d, 3d);
|
||||
assertEquals(location, world.getSpawn());
|
||||
assertNotSame(location, world.getSpawn());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package mc.world.simple;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import mc.core.world.block.BlockType;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan("mc.world.simple")
|
||||
public class TestSpringConfig {
|
||||
@Bean
|
||||
public List<BlockType> layersBlock() {
|
||||
return Lists.newArrayList(
|
||||
BlockType.BEDROCK,
|
||||
BlockType.DIRT,
|
||||
BlockType.DIRT,
|
||||
BlockType.GRASS
|
||||
);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SimpleChunkSection chunkSection(List<BlockType> layersBlock) {
|
||||
return new SimpleChunkSection(layersBlock);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SimpleWorld simpleWorld(List<BlockType> layersBlock) {
|
||||
FlatChunkProvider chunkProvider = new FlatChunkProvider();
|
||||
chunkProvider.setLayersBlock(layersBlock);
|
||||
|
||||
SimpleWorld world = new SimpleWorld();
|
||||
world.setChunkProvider(chunkProvider);
|
||||
return world;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user