mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-25 13:30:10 +00:00
Merge submodule contents for common/addons/generation-stage-feature/master
This commit is contained in:
commit
a0816e2edc
8 files changed
+267
No files matched your search
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2020-2021 Polyhedral Development
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
dependencies {
|
||||||
|
"shadedApi"(project(":common:addons:manifest-addon-loader"))
|
||||||
|
}
|
||||||
+70
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020-2021 Polyhedral Development
|
||||||
|
*
|
||||||
|
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||||
|
* reference the LICENSE file in this module's root directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.dfsek.terra.addons.generation.feature;
|
||||||
|
|
||||||
|
import java.util.function.IntConsumer;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.block.state.BlockState;
|
||||||
|
import com.dfsek.terra.api.structure.feature.BinaryColumn;
|
||||||
|
import com.dfsek.terra.api.world.Column;
|
||||||
|
import com.dfsek.terra.api.world.World;
|
||||||
|
|
||||||
|
|
||||||
|
public class ColumnImpl implements Column {
|
||||||
|
private final int x;
|
||||||
|
private final int z;
|
||||||
|
private final World world;
|
||||||
|
|
||||||
|
public ColumnImpl(int x, int z, World world) {
|
||||||
|
this.x = x;
|
||||||
|
this.z = z;
|
||||||
|
this.world = world;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getZ() {
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getBlock(int y) {
|
||||||
|
return world.getBlockData(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public World getWorld() {
|
||||||
|
return world;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMinY() {
|
||||||
|
return world.getMinHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxY() {
|
||||||
|
return world.getMaxHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEach(IntConsumer function) {
|
||||||
|
for(int y = world.getMinHeight(); y < world.getMaxHeight(); y++) {
|
||||||
|
function.accept(y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BinaryColumn newBinaryColumn() {
|
||||||
|
return new BinaryColumn(getMinY(), getMaxY());
|
||||||
|
}
|
||||||
|
}
|
||||||
+49
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020-2021 Polyhedral Development
|
||||||
|
*
|
||||||
|
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||||
|
* reference the LICENSE file in this module's root directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.dfsek.terra.addons.generation.feature;
|
||||||
|
|
||||||
|
import com.dfsek.terra.addons.generation.feature.config.BiomeFeaturesTemplate;
|
||||||
|
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
|
||||||
|
import com.dfsek.terra.api.Platform;
|
||||||
|
import com.dfsek.terra.api.addon.BaseAddon;
|
||||||
|
import com.dfsek.terra.api.event.events.config.ConfigurationLoadEvent;
|
||||||
|
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
||||||
|
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||||
|
import com.dfsek.terra.api.inject.annotations.Inject;
|
||||||
|
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||||
|
import com.dfsek.terra.api.world.generator.GenerationStageProvider;
|
||||||
|
|
||||||
|
|
||||||
|
public class FeatureGenerationAddon implements AddonInitializer {
|
||||||
|
@Inject
|
||||||
|
private Platform platform;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private BaseAddon addon;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize() {
|
||||||
|
platform.getEventManager()
|
||||||
|
.getHandler(FunctionalEventHandler.class)
|
||||||
|
.register(addon, ConfigPackPreLoadEvent.class)
|
||||||
|
.then(event -> event.getPack()
|
||||||
|
.getOrCreateRegistry(GenerationStageProvider.class)
|
||||||
|
.register("FEATURE", pack -> new FeatureGenerationStage(platform)))
|
||||||
|
.failThrough();
|
||||||
|
|
||||||
|
platform.getEventManager()
|
||||||
|
.getHandler(FunctionalEventHandler.class)
|
||||||
|
.register(addon, ConfigurationLoadEvent.class)
|
||||||
|
.then(event -> {
|
||||||
|
if(event.is(TerraBiome.class)) {
|
||||||
|
event.getLoadedObject(TerraBiome.class).getContext().put(event.load(new BiomeFeaturesTemplate()).get());
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.failThrough();
|
||||||
|
}
|
||||||
|
}
|
||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020-2021 Polyhedral Development
|
||||||
|
*
|
||||||
|
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||||
|
* reference the LICENSE file in this module's root directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.dfsek.terra.addons.generation.feature;
|
||||||
|
|
||||||
|
import com.dfsek.terra.addons.generation.feature.config.BiomeFeatures;
|
||||||
|
import com.dfsek.terra.api.Platform;
|
||||||
|
import com.dfsek.terra.api.profiler.ProfileFrame;
|
||||||
|
import com.dfsek.terra.api.structure.rotation.Rotation;
|
||||||
|
import com.dfsek.terra.api.util.PopulationUtil;
|
||||||
|
import com.dfsek.terra.api.util.vector.Vector3;
|
||||||
|
import com.dfsek.terra.api.world.Chunk;
|
||||||
|
import com.dfsek.terra.api.world.World;
|
||||||
|
import com.dfsek.terra.api.world.generator.GenerationStage;
|
||||||
|
|
||||||
|
|
||||||
|
public class FeatureGenerationStage implements GenerationStage {
|
||||||
|
private final Platform platform;
|
||||||
|
|
||||||
|
public FeatureGenerationStage(Platform platform) {
|
||||||
|
this.platform = platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("try")
|
||||||
|
public void populate(World world, Chunk chunk) {
|
||||||
|
try(ProfileFrame ignore = platform.getProfiler().profile("feature")) {
|
||||||
|
int cx = chunk.getX() << 4;
|
||||||
|
int cz = chunk.getZ() << 4;
|
||||||
|
long seed = world.getSeed();
|
||||||
|
for(int x = 0; x < 16; x++) {
|
||||||
|
for(int z = 0; z < 16; z++) {
|
||||||
|
int tx = cx + x;
|
||||||
|
int tz = cz + z;
|
||||||
|
ColumnImpl column = new ColumnImpl(tx, tz, world);
|
||||||
|
world.getBiomeProvider().getBiome(tx, tz, seed).getContext().get(BiomeFeatures.class).getFeatures().forEach(feature -> {
|
||||||
|
if(feature.getDistributor().matches(tx, tz, seed)) {
|
||||||
|
feature.getLocator()
|
||||||
|
.getSuitableCoordinates(column)
|
||||||
|
.forEach(y ->
|
||||||
|
feature.getStructure(world, tx, y, tz)
|
||||||
|
.generate(new Vector3(tx, y, tz), world, PopulationUtil.getRandom(chunk),
|
||||||
|
Rotation.NONE)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020-2021 Polyhedral Development
|
||||||
|
*
|
||||||
|
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||||
|
* reference the LICENSE file in this module's root directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.dfsek.terra.addons.generation.feature.config;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.properties.Properties;
|
||||||
|
import com.dfsek.terra.api.structure.feature.Feature;
|
||||||
|
|
||||||
|
|
||||||
|
public class BiomeFeatures implements Properties {
|
||||||
|
private final List<Feature> features;
|
||||||
|
|
||||||
|
public BiomeFeatures(List<Feature> features) {
|
||||||
|
this.features = features;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Feature> getFeatures() {
|
||||||
|
return features;
|
||||||
|
}
|
||||||
|
}
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020-2021 Polyhedral Development
|
||||||
|
*
|
||||||
|
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||||
|
* reference the LICENSE file in this module's root directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.dfsek.terra.addons.generation.feature.config;
|
||||||
|
|
||||||
|
import com.dfsek.tectonic.annotations.Default;
|
||||||
|
import com.dfsek.tectonic.annotations.Value;
|
||||||
|
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.config.meta.Meta;
|
||||||
|
import com.dfsek.terra.api.structure.feature.Feature;
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("FieldMayBeFinal")
|
||||||
|
public class BiomeFeaturesTemplate implements ObjectTemplate<BiomeFeatures> {
|
||||||
|
@Value("features")
|
||||||
|
@Default
|
||||||
|
private @Meta List<@Meta Feature> features = Collections.emptyList();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BiomeFeatures get() {
|
||||||
|
return new BiomeFeatures(features);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
schema-version: 1
|
||||||
|
contributors:
|
||||||
|
- Terra contributors
|
||||||
|
id: generation-stage-feature
|
||||||
|
version: 0.1.0
|
||||||
|
entrypoints:
|
||||||
|
- "com.dfsek.terra.addons.generation.feature.FeatureGenerationAddon"
|
||||||
|
website:
|
||||||
|
issues: https://github.com/PolyhedralDev/Terra-generation-stage-feature/issues
|
||||||
|
source: https://github.com/PolyhedralDev/Terra-generation-stage-feature
|
||||||
|
docs: https://github.com/PolyhedralDev/Terra/wiki
|
||||||
|
license: GNU LGPL v3.0
|
||||||
Reference in new issue
Block a user