8 Commits

Author SHA1 Message Date
Unknown f9d2e3d01b bump to 0.0.2 2019-12-15 14:27:53 -05:00
Unknown f9f3c88cfd updated decorator data to use rand instead of seed 2019-12-15 09:54:03 -05:00
Unknown 235fff9426 fixed render OFF disabling hand rendering 2019-12-15 09:53:41 -05:00
Unknown 7a49baa19c removed redundant super 2019-12-14 16:45:28 -05:00
Unknown 10bb559a1e updated mansion finder 2019-12-14 16:45:19 -05:00
Unknown b86892c10a removed water-logging check for shipwrecks 2019-12-14 16:45:03 -05:00
Unknown 525d67f0f1 added shipwreck finder 2019-12-14 14:45:43 -05:00
Unknown 118e056c06 optimized search range of emerald ore 2019-12-14 14:45:26 -05:00
14 changed files with 261 additions and 79 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.7.2+build.174
# Mod Properties
mod_version = 1.0.0
mod_version = 0.0.2-alpha
maven_group = kaptainwutax
archives_base_name = seedcracker
@@ -2,19 +2,9 @@ package kaptainwutax.seedcracker.cracker.population;
import kaptainwutax.seedcracker.cracker.DecoratorCache;
import kaptainwutax.seedcracker.util.Rand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.ChunkRandom;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.decorator.ConfiguredDecorator;
import net.minecraft.world.gen.decorator.Decorator;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.DecoratedFeatureConfig;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public abstract class DecoratorData {
@@ -39,7 +29,7 @@ public abstract class DecoratorData {
decoratorSeed += salt;
decoratorSeed ^= Rand.JAVA_LCG.multiplier;
decoratorSeed &= Rand.JAVA_LCG.modulo - 1;
return this.testDecorator(decoratorSeed);
return this.testDecorator(new Rand(decoratorSeed, false));
}
public long getPopulationSeed(long structureSeed, int x, int z) {
@@ -49,7 +39,7 @@ public abstract class DecoratorData {
return (long)x * a + (long)z * b ^ structureSeed;
}
public abstract boolean testDecorator(long decoratorSeed);
public abstract boolean testDecorator(Rand rand);
@Override
public boolean equals(Object obj) {
@@ -63,42 +53,4 @@ public abstract class DecoratorData {
return false;
}
public abstract static class Feature {
private Map<Biome, Long> CACHE = new HashMap<>();
private GenerationStep.Feature genStep;
private Decorator decorator;
public Feature(GenerationStep.Feature genStep, Decorator decorator) {
this.genStep = genStep;
this.decorator = decorator;
}
public ChunkRandom buildRand(long worldSeed, Biome biome, ChunkPos chunkPos) {
if(CACHE.containsKey(biome)) {
return new ChunkRandom(CACHE.get(biome));
}
List<ConfiguredFeature<?, ?>> features = biome.getFeaturesForStep(this.genStep);
for(int i = 0; i < features.size(); i++) {
ConfiguredFeature<?, ?> feature = features.get(i);
if(!(feature.config instanceof DecoratedFeatureConfig))continue;
ConfiguredDecorator<?> currentDecorator = ((DecoratedFeatureConfig)feature.config).decorator;
if(currentDecorator.decorator == this.decorator) {
BlockPos pos = new BlockPos(chunkPos.getStartX(), 0, chunkPos.getStartZ());
ChunkRandom chunkRandom = new ChunkRandom();
long populationSeed = chunkRandom.setSeed(worldSeed, pos.getX(), pos.getZ());
long seed = chunkRandom.setFeatureSeed(populationSeed, i, this.genStep.ordinal());
CACHE.put(biome, seed ^ Rand.JAVA_LCG.multiplier);
return chunkRandom;
}
}
return null;
}
}
}
@@ -28,9 +28,8 @@ public class DungeonData extends DecoratorData {
}
@Override
public boolean testDecorator(long decoratorSeed) {
public boolean testDecorator(Rand rand) {
if(this.starts.isEmpty())return true;
Rand rand = new Rand(decoratorSeed, false);
//TODO: This currently only supports 1 dungeon per chunk.
BlockPos start = this.starts.get(0);
@@ -30,13 +30,12 @@ public class EmeraldOreData extends DecoratorData {
}
@Override
public boolean testDecorator(long decoratorSeed) {
public boolean testDecorator(Rand rand) {
if(this.starts.isEmpty())return true;
//TODO: This currently only supports 1 emerald per chunk.
BlockPos start = this.starts.get(0);
Rand rand = new Rand(decoratorSeed, false);
int b = rand.nextInt(6);
for(int i = 0; i < b + 3; i++) {
@@ -20,9 +20,7 @@ public class EndGatewayData extends DecoratorData {
}
@Override
public boolean testDecorator(long decoratorSeed) {
Rand rand = new Rand(decoratorSeed, false);
public boolean testDecorator(Rand rand) {
if(rand.nextInt(700) != 0)return false;
if(rand.nextInt(16) != this.xOffset)return false;
if(rand.nextInt(16) != this.zOffset)return false;
@@ -3,7 +3,6 @@ package kaptainwutax.seedcracker.finder;
public class DefaultFinderConfig extends FinderConfig {
public DefaultFinderConfig() {
super();
this.typeStates.put(Type.DIAMOND_ORE, false);
this.typeStates.put(Type.INFESTED_STONE_ORE, false);
this.typeStates.put(Type.IGLOO, false);
@@ -75,6 +75,7 @@ public class FinderConfig {
MONUMENT(OceanMonumentFinder::create, Category.STRUCTURES),
SWAMP_HUT(SwampHutFinder::create, Category.STRUCTURES),
MANSION(MansionFinder::create, Category.STRUCTURES),
SHIPWRECK(ShipwreckFinder::create, Category.STRUCTURES),
END_PILLARS(EndPillarsFinder::create, Category.OTHERS),
END_GATEWAY(EndGatewayFinder::create, Category.OTHERS),
@@ -43,12 +43,11 @@ public class FinderQueue {
}
public void renderFinders(MatrixStack matrixStack) {
if(this.renderType == RenderType.OFF)return;
RenderSystem.pushMatrix();
RenderSystem.multMatrix(matrixStack.peek().getModel());
//System.out.println("rendering");
if(this.renderType == RenderType.OFF)return;
GlStateManager.disableTexture();
//Makes it render through blocks.
@@ -21,6 +21,8 @@ import java.util.List;
public class EmeraldOreFinder extends BlockFinder {
protected static List<BlockPos> SEARCH_POSITIONS = Finder.buildSearchPositions(Finder.CHUNK_POSITIONS, pos -> {
if(pos.getY() < 4)return true;
if(pos.getY() > 28 + 4)return true;
return false;
});
@@ -13,7 +13,9 @@ import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.feature.Feature;
import java.util.ArrayList;
import java.util.HashMap;
@@ -23,7 +25,6 @@ import java.util.Map;
public class MansionFinder extends Finder {
protected static List<BlockPos> SEARCH_POSITIONS = buildSearchPositions(CHUNK_POSITIONS, pos -> {
if(pos.getY() != 64)return true;
if((pos.getX() & 15) != 0)return true;
if((pos.getZ() & 15) != 0)return true;
return false;
@@ -35,27 +36,28 @@ public class MansionFinder extends Finder {
public MansionFinder(World world, ChunkPos chunkPos) {
super(world, chunkPos);
Direction.Type.HORIZONTAL.forEach(direction -> {
PieceFinder finder = new PieceFinder(world, chunkPos, direction, size);
for(Direction direction: Direction.values()) {
PieceFinder finder = new PieceFinder(world, chunkPos, direction, this.size);
finder.searchPositions = SEARCH_POSITIONS;
buildStructure(finder);
this.finders.add(finder);
});
}
}
@Override
public List<BlockPos> findInChunk() {
Biome biome = this.world.getBiome(this.chunkPos.getCenterBlockPos().add(9, 0, 9));
if(!biome.hasStructureFeature(Feature.WOODLAND_MANSION)) {
return new ArrayList<>();
}
Map<PieceFinder, List<BlockPos>> result = this.findInChunkPieces();
List<BlockPos> combinedResult = new ArrayList<>();
result.forEach((pieceFinder, positions) -> {
positions.removeIf(pos -> {
//Figure this out, it's not a trivial task.
return false;
});
combinedResult.addAll(positions);
positions.forEach(pos -> {
@@ -80,12 +82,26 @@ public class MansionFinder extends Finder {
}
public void buildStructure(PieceFinder finder) {
BlockState air = Blocks.AIR.getDefaultState();
BlockState cobblestone = Blocks.COBBLESTONE.getDefaultState();
BlockState birchPlanks = Blocks.BIRCH_PLANKS.getDefaultState();
BlockState redCarpet = Blocks.RED_CARPET.getDefaultState();
BlockState whiteCarpet = Blocks.WHITE_CARPET.getDefaultState();
//TODO: Finish this.
finder.fillWithOutline(0, 0, 0, 15, 0, 15, birchPlanks, birchPlanks, false);
finder.fillWithOutline(0, 0, 8, 6, 0, 12, null, null, false);
finder.fillWithOutline(0, 0, 12, 9, 0, 15, null, null, false);
finder.fillWithOutline(15, 0, 0, 15, 0, 15, cobblestone, cobblestone, false);
finder.addBlock(Blocks.DARK_OAK_LOG.getDefaultState(), 15, 0, 15);
finder.addBlock(Blocks.DARK_OAK_LOG.getDefaultState(), 15, 0, 7);
finder.addBlock(Blocks.DARK_OAK_LOG.getDefaultState(), 14, 0, 7);
finder.fillWithOutline(9, 1, 0, 9, 1, 8, whiteCarpet, whiteCarpet, false);
finder.addBlock(whiteCarpet, 8,1, 8);
finder.fillWithOutline(13, 1, 0, 13, 1, 8, whiteCarpet, whiteCarpet, false);
finder.addBlock(whiteCarpet, 14,1, 8);
finder.fillWithOutline(10, 1, 0, 12, 1, 15, redCarpet, redCarpet, false);
}
@Override
@@ -71,7 +71,7 @@ public class PieceFinder extends Finder {
//FOR DEBUGGING PIECES.
if(this.debug) {
MinecraftClient.getInstance().execute(() -> {
int y = this.rotation.ordinal() * 10 + this.mirror.ordinal() * 20 + 100;
int y = this.rotation.ordinal() * 10 + this.mirror.ordinal() * 20 + 120;
if (this.chunkPos.x % 2 == 0 && this.chunkPos.z % 2 == 0) {
this.structure.forEach((pos, state) -> {
@@ -89,7 +89,7 @@ public class PieceFinder extends Finder {
BlockState state = this.world.getBlockState(pos);
//Blockstate may change when it gets placed in the world, that's why it's using the block here.
if(!state.getBlock().equals(entry.getValue().getBlock())) {
if(entry.getValue() != null && !state.getBlock().equals(entry.getValue().getBlock())) {
found = false;
break;
}
@@ -200,10 +200,6 @@ public class PieceFinder extends Finder {
}
protected void addBlock(BlockState state, int x, int y, int z) {
if(state == null) {
return;
}
BlockPos pos = new BlockPos(
this.applyXTransform(x, z),
this.applyYTransform(y),
@@ -211,6 +207,11 @@ public class PieceFinder extends Finder {
);
if(this.boundingBox.contains(pos)) {
if(state == null) {
this.structure.remove(pos);
return;
}
if (this.mirror != BlockMirror.NONE) {
state = state.mirror(this.mirror);
}
@@ -219,6 +220,7 @@ public class PieceFinder extends Finder {
state = state.rotate(this.rotation);
}
this.structure.put(pos, state);
}
}
@@ -0,0 +1,210 @@
package kaptainwutax.seedcracker.finder.structure;
import kaptainwutax.seedcracker.SeedCracker;
import kaptainwutax.seedcracker.cracker.StructureData;
import kaptainwutax.seedcracker.finder.BlockFinder;
import kaptainwutax.seedcracker.finder.Finder;
import kaptainwutax.seedcracker.render.Cube;
import kaptainwutax.seedcracker.render.Cuboid;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.ChestBlockEntity;
import net.minecraft.block.enums.ChestType;
import net.minecraft.client.util.math.Vector4f;
import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.feature.Feature;
import java.util.ArrayList;
import java.util.List;
public class ShipwreckFinder extends BlockFinder {
protected static List<BlockPos> SEARCH_POSITIONS = Finder.buildSearchPositions(Finder.CHUNK_POSITIONS, pos -> {
return false;
});
public ShipwreckFinder(World world, ChunkPos chunkPos) {
super(world, chunkPos, Blocks.CHEST);
this.searchPositions = SEARCH_POSITIONS;
}
@Override
public List<BlockPos> findInChunk() {
Biome biome = this.world.getBiome(this.chunkPos.getCenterBlockPos().add(9, 0, 9));
if(!biome.hasStructureFeature(Feature.SHIPWRECK)) {
return new ArrayList<>();
}
List<BlockPos> result = super.findInChunk();
result.removeIf(pos -> {
BlockState state = this.world.getBlockState(pos);
if(state.get(ChestBlock.CHEST_TYPE) != ChestType.SINGLE)return true;
BlockEntity blockEntity = this.world.getBlockEntity(pos);
if(!(blockEntity instanceof ChestBlockEntity))return true;
return !this.onChestFound(pos);
});
return result;
}
/**
* Source: https://github.com/skyrising/casual-mod/blob/master/src/main/java/de/skyrising/casual/ShipwreckFinder.java
* */
private boolean onChestFound(BlockPos pos) {
BlockPos.Mutable mutablePos = new BlockPos.Mutable(pos);
Direction chestFacing = world.getBlockState(pos).get(ChestBlock.FACING);
int[] stairs = new int[4];
int totalStairs = 0;
int[] trapdoors = new int[4];
int totalTrapdoors = 0;
for(int y = -1; y <= 2; y++) {
for(int x = -1; x <= 1; x++) {
for(int z = -1; z <= 1; z++) {
if (x == 0 && y == 0 && z == 0)continue;
mutablePos.set(pos.getX() + x, pos.getY() + y, pos.getZ() + z);
BlockState neighborState = world.getBlockState(mutablePos);
Block neighborBlock = neighborState.getBlock();
if(neighborBlock == Blocks.VOID_AIR)return false;
if(neighborBlock instanceof StairsBlock) {
stairs[y + 1]++;
totalStairs++;
} else if(neighborBlock instanceof TrapdoorBlock) {
trapdoors[y + 1]++;
totalTrapdoors++;
}
}
}
}
//System.out.printf("%s: chest facing %s\n", pos, chestFacing);
int chestX = 4;
int chestY = 2;
int chestZ = 0;
int length = 16;
int height = 9;
Direction direction = chestFacing;
if(trapdoors[3] > 4) { // with_mast[_degraded]
chestZ = 9;
height = 21;
length = 28;
} else if(totalTrapdoors == 0 && stairs[3] == 3) { // upsidedown_backhalf[_degraded]
if(stairs[0] == 0) {
chestX = 2;
chestZ = 12;
direction = chestFacing.getOpposite();
} else { // redundant
chestX = 3;
chestY = 5;
chestZ = 5;
direction = chestFacing.rotateYClockwise();
}
} else if(totalTrapdoors == 0) { // rightsideup that have backhalf
if(stairs[0] == 4) {
if(totalStairs > 4) {
chestX = 6;
chestY = 4;
chestZ = 12;
direction = chestFacing.getOpposite();
} else { // sideways backhalf
chestX = 6;
chestY = 3;
chestZ = 8;
length = 17;
direction = chestFacing.getOpposite();
}
} else if(stairs[0] == 3 && totalStairs > 5) {
chestX = 5;
chestZ = 6;
direction = chestFacing.rotateYCounterclockwise();
}
mutablePos.set(pos);
mutablePos.setOffset(0, -chestY, 0);
mutablePos.setOffset(direction.rotateYClockwise(), chestX - 4);
mutablePos.setOffset(direction, -chestZ - 1);
if(this.world.getBlockState(mutablePos).getMaterial() == Material.WOOD) {
if(length == 17) { // sideways
chestZ += 11;
length += 11;
} else {
chestZ += 12;
length += 12;
}
mutablePos.setOffset(0, 10, 0);
if(this.world.getBlockState(mutablePos).getBlock() instanceof LogBlock) {
height = 21;
}
}
} else if(totalTrapdoors == 2 && trapdoors[3] == 2 && stairs[3] == 3) { // rightsideup_fronthalf[_degraded]
chestZ = 8;
length = 24;
}
if(chestZ != 0) {
mutablePos.set(pos);
mutablePos.setOffset(direction, 15 - chestZ);
mutablePos.setOffset(direction.rotateYClockwise(), chestX - 4);
BlockPos.Mutable pos2 = new BlockPos.Mutable(mutablePos);
pos2.setOffset(0, -chestY, 0);
pos2.setOffset(direction, -15);
pos2.setOffset(direction.rotateYClockwise(), 4);
BlockPos.Mutable pos3 = new BlockPos.Mutable(pos2);
pos3.setOffset(direction, length - 1);
pos3.setOffset(direction.rotateYClockwise(), -8);
pos3.setOffset(0, height - 1, 0);
BlockBox box = new BlockBox(
Math.min(pos2.getX(), pos3.getX()), pos2.getY(), Math.min(pos2.getZ(), pos3.getZ()),
Math.max(pos2.getX(), pos3.getX()), pos3.getY(), Math.max(pos2.getZ(), pos3.getZ()));
mutablePos.setOffset(-4, -chestY, -15);
if((mutablePos.getX() & 0xf) == 0 && (mutablePos.getZ() & 0xf) == 0) {
if(SeedCracker.get().onStructureData(new StructureData(new ChunkPos(mutablePos), StructureData.SHIPWRECK))) {
this.renderers.add(new Cuboid(box, new Vector4f(1.0f, 0.0f, 1.0f, 1.0f)));
this.renderers.add(new Cube(new ChunkPos(mutablePos).getCenterBlockPos().offset(Direction.UP, mutablePos.getY()), new Vector4f(1.0f, 0.0f, 1.0f, 1.0f)));
return true;
}
}
}
return false;
}
@Override
public boolean isValidDimension(DimensionType dimension) {
return dimension == DimensionType.OVERWORLD;
}
public static List<Finder> create(World world, ChunkPos chunkPos) {
List<Finder> finders = new ArrayList<>();
finders.add(new ShipwreckFinder(world, chunkPos));
finders.add(new ShipwreckFinder(world, new ChunkPos(chunkPos.x - 1, chunkPos.z)));
finders.add(new ShipwreckFinder(world, new ChunkPos(chunkPos.x, chunkPos.z - 1)));
finders.add(new ShipwreckFinder(world, new ChunkPos(chunkPos.x - 1, chunkPos.z - 1)));
finders.add(new ShipwreckFinder(world, new ChunkPos(chunkPos.x + 1, chunkPos.z)));
finders.add(new ShipwreckFinder(world, new ChunkPos(chunkPos.x, chunkPos.z + 1)));
finders.add(new ShipwreckFinder(world, new ChunkPos(chunkPos.x + 1, chunkPos.z + 1)));
finders.add(new ShipwreckFinder(world, new ChunkPos(chunkPos.x - 1, chunkPos.z - 1)));
finders.add(new ShipwreckFinder(world, new ChunkPos(chunkPos.x - 1, chunkPos.z + 1)));
return finders;
}
}
@@ -1,6 +1,7 @@
package kaptainwutax.seedcracker.render;
import net.minecraft.client.util.math.Vector4f;
import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
@@ -24,6 +25,10 @@ public class Cuboid extends Renderer {
this(start, new Vec3i(end.getX() - start.getX(), end.getY() - start.getY(), end.getZ() - start.getZ()), color);
}
public Cuboid(BlockBox box, Vector4f color) {
this(new BlockPos(box.minX, box.minY, box.minZ), new BlockPos(box.maxX, box.maxY, box.maxZ), color);
}
public Cuboid(BlockPos start, Vec3i size, Vector4f color) {
this.start = start;
this.size = size;
+1 -1
View File
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "seedcracker",
"version": "0.0.1",
"version": "0.0.2",
"name": "Seed Cracker",
"description": "This is an example description! Tell everyone what your mod is about!",