Improve changeling hive generation. Fixes #398

This commit is contained in:
Sollace 2024-09-24 14:48:34 +01:00
parent 5b443f118d
commit f8018cb6fc
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
25 changed files with 305 additions and 50 deletions

View file

@ -6,7 +6,9 @@ import java.util.function.Consumer;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.block.ShellsBlock;
import com.minelittlepony.unicopia.block.UBlocks;
import com.minelittlepony.unicopia.server.world.gen.CaveCarvingStructureProcessor;
import com.minelittlepony.unicopia.server.world.gen.OverworldBiomeSelectionCallback;
import com.minelittlepony.unicopia.server.world.gen.SurfaceGrowthStructureProcessor;
import com.minelittlepony.unicopia.util.registry.DynamicRegistry;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
@ -23,6 +25,7 @@ import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.BiomeTags;
import net.minecraft.sound.BiomeMoodSound;
import net.minecraft.sound.SoundEvents;
import net.minecraft.structure.processor.StructureProcessorType;
import net.minecraft.util.collection.DataPool;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3i;
@ -120,6 +123,9 @@ public interface UWorldGen {
.build();
});
StructureProcessorType<SurfaceGrowthStructureProcessor> SURFACE_GROWTH_STRUCTURE_PROCESSOR = Registry.register(Registries.STRUCTURE_PROCESSOR, Unicopia.id("surface_growth"), () -> SurfaceGrowthStructureProcessor.CODEC);
StructureProcessorType<CaveCarvingStructureProcessor> CAVE_CARVING_STRUCTURE_PROCESSOR = Registry.register(Registries.STRUCTURE_PROCESSOR, Unicopia.id("cave_carving"), () -> CaveCarvingStructureProcessor.CODEC);
@SafeVarargs
static <T> T applyAll(T t, Consumer<T> ...consumers) {
for (Consumer<T> consumer : consumers) {

View file

@ -0,0 +1,36 @@
package com.minelittlepony.unicopia.server.world.gen;
import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.server.world.UWorldGen;
import com.mojang.serialization.Codec;
import net.minecraft.structure.StructurePlacementData;
import net.minecraft.structure.StructureTemplate;
import net.minecraft.structure.processor.StructureProcessor;
import net.minecraft.structure.processor.StructureProcessorType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Heightmap;
import net.minecraft.world.WorldView;
public class CaveCarvingStructureProcessor extends StructureProcessor {
public static final Codec<CaveCarvingStructureProcessor> CODEC = Codec.unit(new CaveCarvingStructureProcessor());
@Override
protected StructureProcessorType<?> getType() {
return UWorldGen.SURFACE_GROWTH_STRUCTURE_PROCESSOR;
}
@Nullable
@Override
public StructureTemplate.StructureBlockInfo process(
WorldView world,
BlockPos pos,
BlockPos pivot,
StructureTemplate.StructureBlockInfo originalBlockInfo,
StructureTemplate.StructureBlockInfo currentBlockInfo,
StructurePlacementData data
) {
int topY = world.getTopY(Heightmap.Type.WORLD_SURFACE_WG, currentBlockInfo.pos().getX(), currentBlockInfo.pos().getZ());
return currentBlockInfo.pos().getY() > topY && world.isAir(currentBlockInfo.pos()) ? null : currentBlockInfo;
}
}

View file

@ -0,0 +1,67 @@
package com.minelittlepony.unicopia.server.world.gen;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.minelittlepony.unicopia.server.world.UWorldGen;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.block.BlockState;
import net.minecraft.structure.StructurePlacementData;
import net.minecraft.structure.StructureTemplate;
import net.minecraft.structure.processor.StructureProcessor;
import net.minecraft.structure.processor.StructureProcessorType;
import net.minecraft.structure.rule.RuleTest;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.ServerWorldAccess;
public class SurfaceGrowthStructureProcessor extends StructureProcessor {
public static final Codec<SurfaceGrowthStructureProcessor> CODEC = RecordCodecBuilder.create(instance -> instance.group(
RuleTest.TYPE_CODEC.fieldOf("input_predicate").forGetter(rule -> rule.inputPredicate),
BlockState.CODEC.fieldOf("output_state").forGetter(rule -> rule.outputState)
).apply(instance, SurfaceGrowthStructureProcessor::new));
private final RuleTest inputPredicate;
private final BlockState outputState;
public SurfaceGrowthStructureProcessor(RuleTest inputPredicate, BlockState outputState) {
this.inputPredicate = inputPredicate;
this.outputState = outputState;
}
@Override
protected StructureProcessorType<?> getType() {
return UWorldGen.SURFACE_GROWTH_STRUCTURE_PROCESSOR;
}
@SuppressWarnings("deprecation")
@Override
public List<StructureTemplate.StructureBlockInfo> reprocess(
ServerWorldAccess world,
BlockPos pos,
BlockPos pivot,
List<StructureTemplate.StructureBlockInfo> originalBlockInfos,
List<StructureTemplate.StructureBlockInfo> currentBlockInfos,
StructurePlacementData data
) {
Map<BlockPos, StructureTemplate.StructureBlockInfo> positionalInfos = currentBlockInfos.stream().collect(Collectors.toMap(
StructureTemplate.StructureBlockInfo::pos,
Function.identity()
));
return currentBlockInfos.stream().map(currentBlockInfo -> {
StructureTemplate.StructureBlockInfo aboveBlockInfo = positionalInfos.get(currentBlockInfo.pos().up());
BlockState currentState = aboveBlockInfo == null ? world.getBlockState(currentBlockInfo.pos().up()) : aboveBlockInfo.state();
if ((currentState.isAir() || currentState.isReplaceable())
&& inputPredicate.test(currentBlockInfo.state(), Random.create(MathHelper.hashCode(currentBlockInfo.pos())))) {
return new StructureTemplate.StructureBlockInfo(currentBlockInfo.pos(), outputState, currentBlockInfo.nbt());
}
return currentBlockInfo;
}).collect(Collectors.toList());
}
}

View file

@ -13,10 +13,23 @@
},
"output_state": {
"name": "unicopia:hive",
"Name": "unicopia:hive",
"properties": []
"Name": "unicopia:hive"
}
}
]
},
{
"processor_type": "unicopia:cave_carving"
},
{
"processor_type": "unicopia:surface_growth",
"input_predicate": {
"predicate_type": "block_match",
"block": "unicopia:chitin"
},
"output_state": {
"name": "unicopia:surface_chitin",
"Name": "unicopia:surface_chitin"
}
}
]

View file

@ -0,0 +1,32 @@
[
{
"processor_type": "minecraft:rule",
"rules": [
{
"location_predicate": {
"predicate_type": "always_true"
},
"input_predicate": {
"predicate_type": "random_block_match",
"block": "unicopia:chitin",
"probability": 0.2
},
"output_state": {
"name": "unicopia:hive",
"Name": "unicopia:hive"
}
}
]
},
{
"processor_type": "unicopia:surface_growth",
"input_predicate": {
"predicate_type": "block_match",
"block": "unicopia:chitin"
},
"output_state": {
"name": "unicopia:surface_chitin",
"Name": "unicopia:surface_chitin"
}
}
]

View file

@ -0,0 +1,13 @@
[
{
"processor_type": "unicopia:surface_growth",
"input_predicate": {
"predicate_type": "block_match",
"block": "unicopia:chitin"
},
"output_state": {
"name": "unicopia:surface_chitin",
"Name": "unicopia:surface_chitin"
}
}
]

View file

@ -18,7 +18,7 @@
}
},
"start_height": {
"absolute": -7
"absolute": -6
},
"start_pool": "unicopia:changeling_hive/start",
"step": "underground_structures",

View file

@ -4,9 +4,7 @@
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/chamber_decoration/nothing",
"processors": {
"processors": []
},
"processors": "unicopia:changeling_hive_surfacing",
"projection": "rigid"
},
"weight": 7
@ -24,9 +22,7 @@
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/chamber_decoration/spiders",
"processors": {
"processors": []
},
"processors": "unicopia:changeling_hive_surfacing",
"projection": "rigid"
},
"weight": 4
@ -35,9 +31,7 @@
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/chamber_decoration/spiked",
"processors": {
"processors": []
},
"processors": "unicopia:changeling_hive_surfacing",
"projection": "rigid"
},
"weight": 2
@ -46,9 +40,7 @@
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/chamber_decoration/slime",
"processors": {
"processors": []
},
"processors": "unicopia:changeling_hive_surfacing",
"projection": "rigid"
},
"weight": 2

View file

@ -0,0 +1,50 @@
{
"elements": [
{
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/floor_decoration/empty",
"processors": [],
"projection": "rigid"
},
"weight": 6
},
{
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/floor_decoration/slime_1",
"processors": [],
"projection": "rigid"
},
"weight": 1
},
{
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/floor_decoration/slime_2",
"processors": [],
"projection": "rigid"
},
"weight": 1
},
{
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/floor_decoration/slime_3",
"processors": [],
"projection": "rigid"
},
"weight": 1
},
{
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/floor_decoration/spikes",
"processors": [],
"projection": "rigid"
},
"weight": 3
}
],
"fallback": "unicopia:changeling_hive/floor_additions_termination"
}

View file

@ -0,0 +1,14 @@
{
"elements": [
{
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/floor_decoration/empty",
"processors": [],
"projection": "rigid"
},
"weight": 1
}
],
"fallback": "minecraft:empty"
}

View file

@ -0,0 +1,14 @@
{
"elements": [
{
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/entrance_large_lower",
"processors": [],
"projection": "rigid"
},
"weight": 6
}
],
"fallback": "minecraft:empty"
}

View file

@ -4,9 +4,7 @@
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/pit_decoration/eggs",
"processors": {
"processors": []
},
"processors": "unicopia:changeling_hive_surfacing",
"projection": "rigid"
},
"weight": 1
@ -15,9 +13,7 @@
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/pit_decoration/lava",
"processors": {
"processors": []
},
"processors": "unicopia:changeling_hive_surfacing",
"projection": "rigid"
},
"weight": 1
@ -35,9 +31,7 @@
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/pit_decoration/spiders",
"processors": {
"processors": []
},
"processors": "unicopia:changeling_hive_surfacing",
"projection": "rigid"
},
"weight": 1
@ -46,9 +40,7 @@
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/pit_decoration/spikes",
"processors": {
"processors": []
},
"processors": "unicopia:changeling_hive_surfacing",
"projection": "rigid"
},
"weight": 1
@ -57,9 +49,7 @@
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/pit_decoration/bulb",
"processors": {
"processors": []
},
"processors": "unicopia:changeling_hive_surfacing",
"projection": "rigid"
},
"weight": 1

View file

@ -0,0 +1,32 @@
{
"elements": [
{
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/roof_decoration/empty",
"processors": [],
"projection": "rigid"
},
"weight": 6
},
{
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/roof_decoration/slime",
"processors": [],
"projection": "rigid"
},
"weight": 1
},
{
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/roof_decoration/spikes",
"processors": [],
"projection": "rigid"
},
"weight": 3
}
],
"fallback": "unicopia:changeling_hive/roof_additions_termination"
}

View file

@ -0,0 +1,14 @@
{
"elements": [
{
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/roof_decoration/empty",
"processors": [],
"projection": "rigid"
},
"weight": 1
}
],
"fallback": "minecraft:empty"
}

View file

@ -3,26 +3,8 @@
{
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/entrance",
"processors": "unicopia:changeling_hive_decay",
"projection": "rigid"
},
"weight": 3
},
{
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/spiked/entrance",
"processors": "unicopia:changeling_hive_decay",
"projection": "rigid"
},
"weight": 3
},
{
"element": {
"element_type": "minecraft:single_pool_element",
"location": "unicopia:changeling_hive/slimey/entrance",
"processors": "unicopia:changeling_hive_decay",
"location": "unicopia:changeling_hive/entrance_large_upper",
"processors": "unicopia:changeling_hive_entrance_decay",
"projection": "rigid"
},
"weight": 1