Skip to content

Commit

Permalink
A few fixes and balancing
Browse files Browse the repository at this point in the history
  • Loading branch information
frqnny committed Apr 1, 2023
1 parent 1440b07 commit dbf2cfe
Show file tree
Hide file tree
Showing 36 changed files with 198 additions and 194 deletions.
29 changes: 10 additions & 19 deletions src/main/java/io/github/frqnny/mostructures/init/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,23 @@

import io.github.frqnny.mostructures.MoStructures;
import io.github.frqnny.mostructures.config.StructureConfigEntry;
import io.github.frqnny.mostructures.mixin.RandomSpreadStructurePlacementAccessor;
import io.github.frqnny.mostructures.mixin.StructureSetAccessor;
import io.github.frqnny.mostructures.structure.ModStructurePlacement;
import net.fabricmc.fabric.api.event.registry.DynamicRegistrySetupCallback;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.world.gen.chunk.placement.RandomSpreadStructurePlacement;

import java.util.List;

public class Events {

public static void init() {
DynamicRegistrySetupCallback.EVENT.register(view -> {
view.registerEntryAdded(RegistryKeys.STRUCTURE_SET, (rawId, id, structureSet) -> {
StructureConfigEntry entry = MoStructures.CONFIG.get(id);
DynamicRegistrySetupCallback.EVENT.register(view -> view.registerEntryAdded(RegistryKeys.STRUCTURE_SET, (rawId, id, structureSet) -> {
StructureConfigEntry entry = MoStructures.CONFIG.get(id);

if (entry != null) { // id matches some structure in the config
if (structureSet.placement() instanceof RandomSpreadStructurePlacement) {
((RandomSpreadStructurePlacementAccessor) structureSet.placement()).setSpacing(entry.spacing);
((RandomSpreadStructurePlacementAccessor) structureSet.placement()).setSeparation(entry.separation);
if (!entry.activated) {
((StructureSetAccessor) (Object) structureSet).setStructures(List.of());
}
}
if (entry != null) { // id matches some structure in the config
if (structureSet.placement() instanceof ModStructurePlacement p) {
p.setSpacing(entry.spacing);
p.setSeparation(entry.separation);
p.setActivated(entry.activated);
}
});

});
}
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

import io.github.frqnny.mostructures.MoStructures;
import io.github.frqnny.mostructures.structure.ModStructure;
import io.github.frqnny.mostructures.structure.ModStructurePlacement;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.structure.StructurePieceType;
import net.minecraft.world.gen.chunk.placement.StructurePlacementType;
import net.minecraft.world.gen.structure.Structure;
import net.minecraft.world.gen.structure.StructureType;

public class Structures {
public static final StructureType<ModStructure> GENERIC = () -> ModStructure.CODEC;
public static final TagKey<Structure> NO_LAKES = TagKey.of(RegistryKeys.STRUCTURE, MoStructures.id("no_lakes"));
public static StructurePieceType VOLCANIC_VENT_TYPE;
public static final StructurePlacementType<ModStructurePlacement> TYPE = () -> ModStructurePlacement.CODEC;

public static void init() {
Registry.register(Registries.STRUCTURE_TYPE, MoStructures.id("generic"), GENERIC);


Registry.register(Registries.STRUCTURE_PLACEMENT, MoStructures.id("type"), TYPE);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.frqnny.mostructures.init.Structures;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.structure.pool.StructurePool;
import net.minecraft.structure.pool.StructurePoolBasedGenerator;
Expand Down Expand Up @@ -43,6 +44,7 @@ public class ModStructure extends Structure {
private final int maxDistanceFromCenter;



public ModStructure(Structure.Config config, RegistryEntry<StructurePool> startPool, Optional<Identifier> startJigsawName, int size, HeightProvider startHeight, boolean useExpansionHack, Optional<Heightmap.Type> projectStartToHeightmap, int maxDistanceFromCenter, int heightRange) {
super(config);
this.startPool = startPool;
Expand All @@ -55,8 +57,9 @@ public ModStructure(Structure.Config config, RegistryEntry<StructurePool> startP
this.heightRange = heightRange;
}

@Override
public Optional<Structure.StructurePosition> getStructurePosition(Structure.Context context) {
if (canGenerate(context.chunkGenerator(), context.seed(), context.chunkPos(), context.world(), context.noiseConfig())) {
if (canGenerate(context.chunkGenerator(), context.chunkPos(), context.world(), context.noiseConfig())) {
ChunkPos chunkPos = context.chunkPos();
int y = this.startHeight.get(context.random(), new HeightContext(context.chunkGenerator(), context.world()));
BlockPos blockPos = new BlockPos(chunkPos.getStartX(), y, chunkPos.getStartZ());
Expand All @@ -66,8 +69,7 @@ public Optional<Structure.StructurePosition> getStructurePosition(Structure.Cont
}
}

public boolean canGenerate(ChunkGenerator chunkGenerator, long worldSeed, ChunkPos pos, HeightLimitView world, NoiseConfig noiseConfig) {

public boolean canGenerate(ChunkGenerator chunkGenerator, ChunkPos pos, HeightLimitView world, NoiseConfig noiseConfig) {
int heightRange = this.heightRange;
if (heightRange != -1) {
int maxTerrainHeight = Integer.MIN_VALUE;
Expand All @@ -88,7 +90,7 @@ public boolean canGenerate(ChunkGenerator chunkGenerator, long worldSeed, ChunkP

@Override
public StructureType<?> getType() {
return null;//todo
return Structures.GENERIC;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.frqnny.mostructures.init.Structures;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryElementCodec;
import net.minecraft.registry.entry.RegistryEntry;
Expand All @@ -11,50 +12,60 @@
import net.minecraft.util.math.Vec3i;
import net.minecraft.util.math.random.CheckedRandom;
import net.minecraft.util.math.random.ChunkRandom;
import net.minecraft.world.gen.chunk.placement.SpreadType;
import net.minecraft.world.gen.chunk.placement.StructurePlacement;
import net.minecraft.world.gen.chunk.placement.StructurePlacementCalculator;
import net.minecraft.world.gen.chunk.placement.StructurePlacementType;
import net.minecraft.world.gen.chunk.placement.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class ModStructurePlacement extends StructurePlacement {
public class ModStructurePlacement extends RandomSpreadStructurePlacement {
public static final Codec<ModStructurePlacement> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Vec3i.createOffsetCodec(16).optionalFieldOf("locate_offset", Vec3i.ZERO).forGetter(ModStructurePlacement::getLocateOffset),
FrequencyReductionMethod.CODEC.optionalFieldOf("frequency_reduction_method", FrequencyReductionMethod.DEFAULT).forGetter(ModStructurePlacement::getFrequencyReductionMethod),
Codec.floatRange(0.0f, 1.0f).optionalFieldOf("frequency", 1.0f).forGetter(ModStructurePlacement::getFrequency),
Codecs.NONNEGATIVE_INT.fieldOf("salt").forGetter(ModStructurePlacement::getSalt),
ModExclusionZone.CODEC.listOf().optionalFieldOf("exclusion_zone").forGetter(placement -> placement.exclusionZones),
RegistryElementCodec.of(RegistryKeys.STRUCTURE_SET, StructureSet.CODEC, false).listOf().fieldOf("structure_set_to_avoid").orElse(new ArrayList<>(20)).forGetter(config -> config.structureSetToAvoid),
Codec.intRange(0, 4096).fieldOf("spacing").forGetter(ModStructurePlacement::getSpacing),
Codec.intRange(0, 4096).fieldOf("separation").forGetter(ModStructurePlacement::getSeparation),
SpreadType.CODEC.optionalFieldOf("spread_type", SpreadType.LINEAR).forGetter(ModStructurePlacement::getSpreadType))
.apply(instance, ModStructurePlacement::new));
private final Optional<List<ModExclusionZone>> exclusionZones;
private final int spacing;
private final int separation;
public final List<RegistryEntry<StructureSet>> structureSetToAvoid;
private int spacing;
private int separation;
private final SpreadType spreadType;
private boolean activated;

public ModStructurePlacement(Vec3i locateOffset, StructurePlacement.FrequencyReductionMethod frequencyReductionMethod, float frequency, int salt, Optional<List<ModExclusionZone>> exclusionZones, int spacing, int separation, SpreadType spreadType) {
super(locateOffset, frequencyReductionMethod, frequency, salt, Optional.empty());
public ModStructurePlacement(Vec3i locateOffset, StructurePlacement.FrequencyReductionMethod frequencyReductionMethod, float frequency, int salt, List<RegistryEntry<StructureSet>> structureSetToAvoid, int spacing, int separation, SpreadType spreadType) {
super(locateOffset, frequencyReductionMethod, frequency, salt, Optional.empty(), spacing, separation, spreadType);
this.spacing = spacing;
this.separation = separation;
this.spreadType = spreadType;
this.exclusionZones = exclusionZones;
this.structureSetToAvoid = structureSetToAvoid;
}

public ModStructurePlacement(int spacing, int separation, SpreadType spreadType, int salt) {
this(Vec3i.ZERO, StructurePlacement.FrequencyReductionMethod.DEFAULT, 1.0f, salt, Optional.empty(), spacing, separation, spreadType);
public void setActivated(boolean activated) {
this.activated = activated;
}

@Override
public int getSpacing() {
return this.spacing;
}

@Override
public int getSeparation() {
return this.separation;
}

public void setSeparation(int separation) {
this.separation = separation;
}

public void setSpacing(int spacing) {
this.spacing = spacing;
}

@Override
public SpreadType getSpreadType() {
return this.spreadType;
}
Expand All @@ -78,39 +89,53 @@ protected boolean isStartChunk(StructurePlacementCalculator calculator, int chun

@Override
public boolean shouldGenerate(StructurePlacementCalculator calculator, int chunkX, int chunkZ) {
if (!activated) {
return false;
}

if (!this.isStartChunk(calculator, chunkX, chunkZ)) {
return false;
}
if (this.getFrequency() < 1.0f && !this.getFrequencyReductionMethod().shouldGenerate(calculator.getStructureSeed(), this.getSalt(), chunkX, chunkZ, this.getFrequency())) {
return false;
}

if (exclusionZones.isPresent()) {
var list = exclusionZones.get();
for (ModExclusionZone zone : list) {
if (zone.shouldExclude(calculator, chunkX, chunkZ)) {
if (!structureSetToAvoid.isEmpty()) {
for (RegistryEntry<StructureSet> entry : structureSetToAvoid) {
if (shouldExclude(calculator, entry, chunkX, chunkZ, 3)) {
return false;
}
}
}

return true;
}

@Override
public StructurePlacementType<?> getType() {
return StructurePlacementType.RANDOM_SPREAD;
public boolean shouldGenerateNoExclusionCheck(StructurePlacementCalculator calculator, int chunkX, int chunkZ) {
if (!activated) {
return false;
}
if (!this.isStartChunk(calculator, chunkX, chunkZ)) {
return false;
}
return !(this.getFrequency() < 1.0f) || this.getFrequencyReductionMethod().shouldGenerate(calculator.getStructureSeed(), this.getSalt(), chunkX, chunkZ, this.getFrequency());
}

public static boolean shouldExclude(StructurePlacementCalculator calculator, RegistryEntry<StructureSet> structureSetEntry, int centerChunkX, int centerChunkZ, int chunkCount) {
if (structureSetEntry.value().placement() instanceof ModStructurePlacement structurePlacement) {
for (int i = centerChunkX - chunkCount; i <= centerChunkX + chunkCount; ++i) {
for (int j = centerChunkZ - chunkCount; j <= centerChunkZ + chunkCount; ++j) {
if (!structurePlacement.shouldGenerateNoExclusionCheck(calculator, i, j)) continue;
return true;
}
}
}

public record ModExclusionZone(RegistryEntry<StructureSet> otherSet, int chunkCount) {
public static final Codec<ModExclusionZone> CODEC = RecordCodecBuilder.create(instance -> instance.group(
RegistryElementCodec.of(RegistryKeys.STRUCTURE_SET, StructureSet.CODEC, false).fieldOf("other_set").forGetter(ModExclusionZone::otherSet),
Codec.intRange(1, 16).fieldOf("chunk_count").forGetter(ModExclusionZone::chunkCount))
.apply(instance, ModExclusionZone::new)
);
return false;
}

boolean shouldExclude(StructurePlacementCalculator calculator, int centerChunkX, int centerChunkZ) {
return calculator.canGenerate(this.otherSet, centerChunkX, centerChunkZ, this.chunkCount);
}
@Override
public StructurePlacementType<?> getType() {
return Structures.TYPE;
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
{
"type": "mostructures:generic",
"start_pool": "mostructures:air/balloons",
"structure_set_to_avoid": [
"mostructures:the_castle_in_the_sky"
],
"size": 7,
"max_distance_from_center": 80,
"step": "surface_structures",
"project_start_to_heightmap": "WORLD_SURFACE_WG",
"start_height": {
"type": "uniform",
"min_inclusive": {
"above_bottom": 45
"above_bottom": 105
},
"max_inclusive": {
"above_bottom": 100
"above_bottom": 150
}
},
"use_expansion_hack": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
{
"type": "mostructures:generic",
"start_pool": "mostructures:barn_house/base_plates",
"structure_set_to_avoid": [
"mostructures:abandoned_church",
"mostructures:killer_bunny_castle",
"mostructures:lighthouse",
"mostructures:moai",
"mostructures:tavern",
"mostructures:villager_market"
],

"size": 7,
"heightRange": 40,
"biomes": "#mostructures:has_structure/barn_house",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"type": "mostructures:generic",
"start_pool": "mostructures:pyramid/base",
"structure_set_to_avoid": [
"mostructures:abandoned_church"
],
"size": 7,
"heightRange": 40,
"biomes": "#mostructures:has_structure/big_pyramid",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"type": "mostructures:generic",
"start_pool": "mostructures:abandoned/village/plates_desert",
"structure_set_to_avoid": [
"mostructures:big_pyramid",
"mostructures:lighthouse",
"mostructures:moai",
"mostructures:villager_tower"
],
"size": 7,
"heightRange": 40,
"biomes": "#mostructures:has_structure/desert_abandoned_church",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"type": "mostructures:generic",
"start_pool": "mostructures:ice_tower/base",
"structure_set_to_avoid": [
"mostructures:abandoned_church",
"mostructures:lighthouse",
"mostructures:moai",
"mostructures:villager_tower"
],
"size": 7,
"heightRange": 40,
"biomes": "#mostructures:has_structure/ice_tower",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"type": "mostructures:generic",
"start_pool": "mostructures:jungle_pyramid/base",
"structure_set_to_avoid": [],
"size": 7,
"heightRange": 40,
"biomes": "#mostructures:has_structure/jungle_pyramid",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
{
"type": "mostructures:generic",
"start_pool": "mostructures:bunny/base",
"structure_set_to_avoid": [
"mostructures:abandoned_church",
"mostructures:big_pyramid",
"mostructures:ice_tower",
"mostructures:jungle_pyramid",
"mostructures:lighthouse",
"mostructures:moai",
"mostructures:pillager_factory",
"mostructures:villager_tower"
],
"size": 7,
"heightRange": 40,
"heightRange": 20,
"biomes": "#mostructures:has_structure/killer_bunny_castle",
"use_expansion_hack": true,
"terrain_adaptation": "beard_thin",
Expand Down
Loading

0 comments on commit dbf2cfe

Please sign in to comment.