use of org.terasology.engine.world.WorldProvider in project Terasology by MovingBlocks.
the class StorageManagerTest method setup.
@BeforeEach
public void setup(@TempDir Path tempHome) throws Exception {
super.setup();
PathManager.getInstance().useOverrideHomePath(tempHome);
savePath = PathManager.getInstance().getSavePath("testSave");
assert !Files.isRegularFile(tempHome.resolve("global.dat"));
entityManager = context.get(EngineEntityManager.class);
moduleEnvironment = mock(ModuleEnvironment.class);
blockManager = context.get(BlockManager.class);
extraDataManager = context.get(ExtraBlockDataManager.class);
ModuleManager moduleManager = mock(ModuleManager.class);
when(moduleManager.getEnvironment()).thenReturn(moduleEnvironment);
RecordedEventStore recordedEventStore = new RecordedEventStore();
recordAndReplayUtils = new RecordAndReplayUtils();
CharacterStateEventPositionMap characterStateEventPositionMap = new CharacterStateEventPositionMap();
DirectionAndOriginPosRecorderList directionAndOriginPosRecorderList = new DirectionAndOriginPosRecorderList();
recordAndReplaySerializer = new RecordAndReplaySerializer(entityManager, recordedEventStore, recordAndReplayUtils, characterStateEventPositionMap, directionAndOriginPosRecorderList, moduleManager, mock(TypeRegistry.class));
recordAndReplayCurrentStatus = context.get(RecordAndReplayCurrentStatus.class);
esm = new ReadWriteStorageManager(savePath, moduleEnvironment, entityManager, blockManager, extraDataManager, false, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
context.put(StorageManager.class, esm);
this.character = entityManager.create();
Client client = createClientMock(PLAYER_ID, character);
NetworkSystem networkSystem = mock(NetworkSystem.class);
when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
when(networkSystem.getPlayers()).thenReturn(Arrays.asList(client));
context.put(NetworkSystem.class, networkSystem);
AssetManager assetManager = context.get(AssetManager.class);
BlockFamilyDefinitionData data = new BlockFamilyDefinitionData();
data.setBlockFamily(SymmetricFamily.class);
assetManager.loadAsset(new ResourceUrn("test:testblock"), data, BlockFamilyDefinition.class);
assetManager.loadAsset(new ResourceUrn("test:testblock2"), data, BlockFamilyDefinition.class);
testBlock = context.get(BlockManager.class).getBlock("test:testblock");
testBlock2 = context.get(BlockManager.class).getBlock("test:testblock2");
context.put(ChunkProvider.class, mock(ChunkProvider.class));
WorldProvider worldProvider = mock(WorldProvider.class);
when(worldProvider.getWorldInfo()).thenReturn(new WorldInfo());
context.put(WorldProvider.class, worldProvider);
}
use of org.terasology.engine.world.WorldProvider in project Terasology by MovingBlocks.
the class NetworkSystemImpl method getServerInfoMessage.
private NetData.ServerInfoMessage getServerInfoMessage(String errorMessage) {
NetData.ServerInfoMessage.Builder serverInfoMessageBuilder = NetData.ServerInfoMessage.newBuilder();
serverInfoMessageBuilder.setTime(time.getGameTimeInMs());
if (config.getServerMOTD() != null) {
serverInfoMessageBuilder.setMOTD(config.getServerMOTD());
}
serverInfoMessageBuilder.setOnlinePlayersAmount(clientList.size());
WorldProvider worldProvider = context.get(WorldProvider.class);
if (worldProvider != null) {
NetData.WorldInfo.Builder worldInfoBuilder = NetData.WorldInfo.newBuilder();
worldInfoBuilder.setTime(worldProvider.getTime().getMilliseconds());
worldInfoBuilder.setTitle(worldProvider.getTitle());
serverInfoMessageBuilder.addWorldInfo(worldInfoBuilder);
}
WorldGenerator worldGen = context.get(WorldGenerator.class);
if (worldGen != null) {
serverInfoMessageBuilder.setReflectionHeight(worldGen.getWorld().getSeaLevel() + 0.5f);
}
for (Module module : CoreRegistry.get(ModuleManager.class).getEnvironment()) {
if (!StandardModuleExtension.isServerSideOnly(module)) {
serverInfoMessageBuilder.addModule(NetData.ModuleInfo.newBuilder().setModuleId(module.getId().toString()).setModuleVersion(module.getVersion().toString()).build());
}
}
for (Map.Entry<String, Short> blockMapping : blockManager.getBlockIdMap().entrySet()) {
serverInfoMessageBuilder.addBlockId(blockMapping.getValue());
serverInfoMessageBuilder.addBlockName(blockMapping.getKey());
}
for (BlockFamily registeredBlockFamily : blockManager.listRegisteredBlockFamilies()) {
serverInfoMessageBuilder.addRegisterBlockFamily(registeredBlockFamily.getURI().toString());
}
if (errorMessage != null && !errorMessage.isEmpty()) {
serverInfoMessageBuilder.setErrorMessage(errorMessage);
}
serializeComponentInfo(serverInfoMessageBuilder);
serializeEventInfo(serverInfoMessageBuilder);
return serverInfoMessageBuilder.build();
}
use of org.terasology.engine.world.WorldProvider in project Terasology by MovingBlocks.
the class InitialiseRemoteWorld method step.
@Override
public boolean step() {
// TODO: These shouldn't be done here, nor so strongly tied to the world renderer
LocalPlayer localPlayer = new LocalPlayer();
localPlayer.setRecordAndReplayClasses(context.get(DirectionAndOriginPosRecorderList.class), context.get(RecordAndReplayCurrentStatus.class));
context.put(LocalPlayer.class, localPlayer);
BlockManager blockManager = context.get(BlockManager.class);
ExtraBlockDataManager extraDataManager = context.get(ExtraBlockDataManager.class);
RemoteChunkProvider chunkProvider = new RemoteChunkProvider(blockManager, localPlayer);
WorldProviderCoreImpl worldProviderCore = new WorldProviderCoreImpl(gameManifest.getWorldInfo(TerasologyConstants.MAIN_WORLD), chunkProvider, blockManager.getBlock(BlockManager.UNLOADED_ID), context);
EntityAwareWorldProvider entityWorldProvider = new EntityAwareWorldProvider(worldProviderCore, context);
WorldProvider worldProvider = new WorldProviderWrapper(entityWorldProvider, extraDataManager);
context.put(WorldProvider.class, worldProvider);
context.put(BlockEntityRegistry.class, entityWorldProvider);
context.get(ComponentSystemManager.class).register(entityWorldProvider, "engine:BlockEntityRegistry");
DefaultCelestialSystem celestialSystem = new DefaultCelestialSystem(new BasicCelestialModel(), context);
context.put(CelestialSystem.class, celestialSystem);
context.get(ComponentSystemManager.class).register(celestialSystem);
// Init. a new world
context.put(BackdropProvider.class, new Skysphere(context));
RenderingSubsystemFactory engineSubsystemFactory = context.get(RenderingSubsystemFactory.class);
WorldRenderer worldRenderer = engineSubsystemFactory.createWorldRenderer(context);
float reflectionHeight = context.get(NetworkSystem.class).getServer().getInfo().getReflectionHeight();
worldRenderer.getActiveCamera().setReflectionHeight(reflectionHeight);
context.put(WorldRenderer.class, worldRenderer);
// TODO: These shouldn't be done here, nor so strongly tied to the world renderer
context.put(Camera.class, worldRenderer.getActiveCamera());
context.get(NetworkSystem.class).setRemoteWorldProvider(chunkProvider);
return true;
}
use of org.terasology.engine.world.WorldProvider in project Terasology by MovingBlocks.
the class ServerImpl method processBlockChanges.
/**
* Apply the block changes from the message to the local world.
*/
private void processBlockChanges(NetData.NetMessage message) {
for (NetData.BlockChangeMessage blockChange : message.getBlockChangeList()) {
Block newBlock = blockManager.getBlock((short) blockChange.getNewBlock());
logger.debug("Received block change to {}", newBlock);
// TODO: Store changes to blocks that aren't ready to be modified (the surrounding chunks aren't available)
WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);
Vector3i pos = NetMessageUtil.convert(blockChange.getPos());
if (worldProvider.isBlockRelevant(pos)) {
worldProvider.setBlock(pos, newBlock);
} else {
awaitingChunkReadyBlockUpdates.put(Chunks.toChunkPos(pos), blockChange);
}
}
}
use of org.terasology.engine.world.WorldProvider in project Terasology by MovingBlocks.
the class HeadlessEnvironment method setupWorldProvider.
@Override
protected void setupWorldProvider() {
WorldProvider worldProvider = mock(WorldProvider.class);
when(worldProvider.getWorldInfo()).thenReturn(new WorldInfo());
when(worldProvider.getTime()).thenReturn(WORLD_TIME);
context.put(WorldProvider.class, worldProvider);
}
Aggregations