Skip to content

Commit

Permalink
- more refactors
Browse files Browse the repository at this point in the history
- tweak how biome container is generated
- block carvers from acting on chunks containing surface structures
- added spawn type option
  • Loading branch information
dags- committed Jun 5, 2020
1 parent 8810eb5 commit 5e99228
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
38 changes: 38 additions & 0 deletions src/main/java/com/terraforged/fm/template/StructureUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.terraforged.fm.template;

import com.google.common.collect.ImmutableList;
import it.unimi.dsi.fastutil.longs.LongSet;
import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.gen.feature.structure.Structure;

import java.util.List;
import java.util.Map;

public class StructureUtils {

public static final List<Structure<?>> SURFACE_STRUCTURES = ImmutableList.of(
Structure.VILLAGE,
Structure.JUNGLE_TEMPLE,
Structure.PILLAGER_OUTPOST,
Structure.SWAMP_HUT,
Structure.IGLOO,
Structure.DESERT_PYRAMID,
Structure.WOODLAND_MANSION
);

public static boolean hasOvergroundStructure(IChunk chunk) {
Map<String, LongSet> references = chunk.getStructureReferences();
for (Structure<?> structure : SURFACE_STRUCTURES) {
LongSet refs = references.get(structure.getStructureName());
if (refs != null && refs.size() > 0) {
return true;
}
}
return false;
}

public static boolean hasStructure(IChunk chunk, Structure<?> structure) {
LongSet refs = chunk.getStructureReferences().get(structure.getStructureName());
return refs != null && refs.size() > 0;
}
}
13 changes: 5 additions & 8 deletions src/main/java/com/terraforged/fm/template/Template.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.gen.feature.Feature;
import net.minecraftforge.common.util.Constants;

import java.io.IOException;
Expand All @@ -34,13 +33,11 @@ public Template(List<BlockInfo> blocks) {
public boolean paste(IWorld world, BlockPos origin, Mirror mirror, Rotation rotation, PasteConfig config) {
if (config.checkBounds) {
IChunk chunk = world.getChunk(origin);
if (chunk == null || chunk.getStructureReferences(Feature.VILLAGE.getStructureName()).isEmpty()) {
return pasteNormal(world, origin, mirror, rotation, config);
if (StructureUtils.hasOvergroundStructure(chunk)) {
return pasteWithBoundsCheck(world, origin, mirror, rotation, config);
}
return pasteWithBoundsCheck(world, origin, mirror, rotation, config);
} else {
return pasteNormal(world, origin, mirror, rotation, config);
}
return pasteNormal(world, origin, mirror, rotation, config);
}

public boolean pasteNormal(IWorld world, BlockPos origin, Mirror mirror, Rotation rotation, PasteConfig config) {
Expand All @@ -61,8 +58,8 @@ public boolean pasteNormal(IWorld world, BlockPos origin, Mirror mirror, Rotatio
placeBase(world, pos, block.state, config.baseDepth);
}

world.setBlockState(pos, state, 2);
placed = true;
world.setBlockState(pos, block.state, 2);
}
return placed;
}
Expand Down Expand Up @@ -185,7 +182,7 @@ private static List<Template.BlockInfo> relativize(Template.BlockInfo[] blocks)
if (origin == null) {
origin = block.pos;
lowestSolid = block.pos.getY();
}else if (block.pos.getY() < lowestSolid) {
} else if (block.pos.getY() < lowestSolid) {
origin = block.pos;
lowestSolid = block.pos.getY();
} else if (block.pos.getY() == lowestSolid) {
Expand Down

0 comments on commit 5e99228

Please sign in to comment.