Renamed Scatter to Feature and added a generation feature interface
- Renamed SurfaceScatterGenerator to SurfaceFeatureGenerator - Renamed PlanetScatterGenerator to PlanetFeatureGenerator - Added a very basic interface for adding generation features - Removed debug leftovers from PlayerManager and VisionManager
This commit is contained in:
parent
7ecdfdfb4d
commit
2d3d250f92
@ -45,7 +45,6 @@ public class PlayerManager {
|
|||||||
|
|
||||||
public void addPlayer(Player player) {
|
public void addPlayer(Player player) {
|
||||||
this.players.add(player);
|
this.players.add(player);
|
||||||
System.out.println("PlayerManager.addPlayer()");
|
|
||||||
getServer().postEvent(new PlayerJoinedEvent.Immutable(getServer(), player));
|
getServer().postEvent(new PlayerJoinedEvent.Immutable(getServer(), player));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,13 +45,11 @@ public class VisionManager {
|
|||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
private void onPlayerJoined(PlayerJoinedEvent event) {
|
private void onPlayerJoined(PlayerJoinedEvent event) {
|
||||||
System.out.println("VisionManager.onPlayerJoined()");
|
|
||||||
getVision(event.getPlayer(), true);
|
getVision(event.getPlayer(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
private void onPlayerLeft(PlayerLeftEvent event) {
|
private void onPlayerLeft(PlayerLeftEvent event) {
|
||||||
System.out.println("VisionManager.onPlayerLeft()");
|
|
||||||
visions.remove(event.getPlayer());
|
visions.remove(event.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package ru.windcorp.progressia.test.gen.planet;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import glm.vec._3.i.Vec3i;
|
||||||
|
import ru.windcorp.progressia.common.util.VectorUtil;
|
||||||
|
import ru.windcorp.progressia.common.world.ChunkData;
|
||||||
|
import ru.windcorp.progressia.common.world.block.BlockDataRegistry;
|
||||||
|
import ru.windcorp.progressia.test.gen.surface.SurfaceFeature;
|
||||||
|
import ru.windcorp.progressia.test.gen.surface.SurfaceFeatureGenerator;
|
||||||
|
|
||||||
|
public class PlanetFeatureGenerator {
|
||||||
|
|
||||||
|
private final TestPlanetGenerator parent;
|
||||||
|
private final SurfaceFeatureGenerator surfaceGenerator;
|
||||||
|
|
||||||
|
public PlanetFeatureGenerator(TestPlanetGenerator generator) {
|
||||||
|
this.parent = generator;
|
||||||
|
|
||||||
|
Collection<SurfaceFeature> features = new ArrayList<>();
|
||||||
|
features.add(new SurfaceFeature("Test:GlassFeature") {
|
||||||
|
@Override
|
||||||
|
public void process(ChunkData chunk, Random random) {
|
||||||
|
|
||||||
|
chunk.setBlockRel(new Vec3i(8, 8, 8), BlockDataRegistry.getInstance().get("Test:Glass"), true);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.surfaceGenerator = new SurfaceFeatureGenerator(features);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TestPlanetGenerator getGenerator() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void generateFeatures(ChunkData chunk) {
|
||||||
|
if (isOrdinaryChunk(chunk.getPosition())) {
|
||||||
|
generateOrdinaryFeatures(chunk);
|
||||||
|
} else {
|
||||||
|
generateBorderFeatures(chunk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isOrdinaryChunk(Vec3i chunkPos) {
|
||||||
|
Vec3i sorted = VectorUtil.sortAfterAbs(chunkPos, null);
|
||||||
|
return sorted.x != sorted.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generateOrdinaryFeatures(ChunkData chunk) {
|
||||||
|
surfaceGenerator.generateFeatures(chunk);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generateBorderFeatures(ChunkData chunk) {
|
||||||
|
// Do nothing
|
||||||
|
chunk.setGenerationHint(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -38,7 +38,7 @@ public class TestPlanetGenerator extends AbstractWorldGenerator<Boolean> {
|
|||||||
private final Planet planet;
|
private final Planet planet;
|
||||||
|
|
||||||
private final PlanetTerrainGenerator terrainGenerator;
|
private final PlanetTerrainGenerator terrainGenerator;
|
||||||
private final PlanetScatterGenerator scatterGenerator;
|
private final PlanetFeatureGenerator featureGenerator;
|
||||||
|
|
||||||
public TestPlanetGenerator(String id, Planet planet, WorldLogic world) {
|
public TestPlanetGenerator(String id, Planet planet, WorldLogic world) {
|
||||||
super(id, Boolean.class, "Test:PlanetGravityModel");
|
super(id, Boolean.class, "Test:PlanetGravityModel");
|
||||||
@ -50,7 +50,7 @@ public class TestPlanetGenerator extends AbstractWorldGenerator<Boolean> {
|
|||||||
model.configure(planet.getGravityModelSettings());
|
model.configure(planet.getGravityModelSettings());
|
||||||
|
|
||||||
this.terrainGenerator = new PlanetTerrainGenerator(this);
|
this.terrainGenerator = new PlanetTerrainGenerator(this);
|
||||||
this.scatterGenerator = new PlanetScatterGenerator(this);
|
this.featureGenerator = new PlanetFeatureGenerator(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,7 +86,7 @@ public class TestPlanetGenerator extends AbstractWorldGenerator<Boolean> {
|
|||||||
ChunkData chunk = world.getChunk(chunkPos);
|
ChunkData chunk = world.getChunk(chunkPos);
|
||||||
|
|
||||||
if (!isChunkReady(chunk.getGenerationHint())) {
|
if (!isChunkReady(chunk.getGenerationHint())) {
|
||||||
scatterGenerator.generateScatter(chunk);
|
featureGenerator.generateFeatures(chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
return chunk;
|
return chunk;
|
||||||
|
@ -17,12 +17,17 @@
|
|||||||
*/
|
*/
|
||||||
package ru.windcorp.progressia.test.gen.surface;
|
package ru.windcorp.progressia.test.gen.surface;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
||||||
import ru.windcorp.progressia.common.world.ChunkData;
|
import ru.windcorp.progressia.common.world.ChunkData;
|
||||||
|
|
||||||
public class SurfaceScatterGenerator {
|
public abstract class SurfaceFeature extends Namespaced {
|
||||||
|
|
||||||
public void generateScatter(ChunkData chunk) {
|
public SurfaceFeature(String id) {
|
||||||
chunk.setGenerationHint(true);
|
super(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract void process(ChunkData chunk, Random random);
|
||||||
|
|
||||||
}
|
}
|
@ -15,30 +15,31 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package ru.windcorp.progressia.test.gen.planet;
|
package ru.windcorp.progressia.test.gen.surface;
|
||||||
|
|
||||||
import glm.vec._3.i.Vec3i;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import ru.windcorp.progressia.common.util.CoordinatePacker;
|
||||||
import ru.windcorp.progressia.common.world.ChunkData;
|
import ru.windcorp.progressia.common.world.ChunkData;
|
||||||
import ru.windcorp.progressia.common.world.block.BlockDataRegistry;
|
|
||||||
import ru.windcorp.progressia.test.gen.surface.SurfaceScatterGenerator;
|
|
||||||
|
|
||||||
public class PlanetScatterGenerator {
|
public class SurfaceFeatureGenerator {
|
||||||
|
|
||||||
private final TestPlanetGenerator parent;
|
private final Collection<SurfaceFeature> features; // TODO make ordered
|
||||||
private final SurfaceScatterGenerator surfaceGenerator;
|
|
||||||
|
public SurfaceFeatureGenerator(Collection<SurfaceFeature> features) {
|
||||||
public PlanetScatterGenerator(TestPlanetGenerator generator) {
|
this.features = new ArrayList<>(features);
|
||||||
this.parent = generator;
|
|
||||||
this.surfaceGenerator = new SurfaceScatterGenerator();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestPlanetGenerator getGenerator() {
|
public void generateFeatures(ChunkData chunk) {
|
||||||
return parent;
|
Random random = new Random(CoordinatePacker.pack3IntsIntoLong(chunk.getPosition()) /* ^ seed*/);
|
||||||
}
|
|
||||||
|
for (SurfaceFeature feature : features) {
|
||||||
public void generateScatter(ChunkData chunk) {
|
feature.process(chunk, random);
|
||||||
chunk.setBlock(new Vec3i(8, 8, 8), BlockDataRegistry.getInstance().get("Test:Log"), false);
|
}
|
||||||
surfaceGenerator.generateScatter(chunk);
|
|
||||||
|
chunk.setGenerationHint(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user