Start of feature finders
This commit is contained in:
@@ -1,11 +1,15 @@
|
|||||||
package kaptainwutax.seedcracker;
|
package kaptainwutax.seedcracker;
|
||||||
|
|
||||||
|
import kaptainwutax.seedcracker.finder.BlockFinder;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
import net.minecraft.block.Blocks;
|
||||||
|
|
||||||
public class SeedCracker implements ModInitializer {
|
public class SeedCracker implements ModInitializer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
|
BlockFinder finder1 = new BlockFinder(Blocks.CHEST.getDefaultState());
|
||||||
|
BlockFinder finder2 = new BlockFinder(Blocks.CHEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package kaptainwutax.seedcracker.finder;
|
||||||
|
|
||||||
|
import kaptainwutax.seedcracker.world.ChunkWrapper;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.ChunkPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
import net.minecraft.world.chunk.ChunkSection;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class BlockFinder extends Finder {
|
||||||
|
|
||||||
|
private Set<BlockState> targetBlockStates = new HashSet<>();
|
||||||
|
|
||||||
|
public BlockFinder(Block block) {
|
||||||
|
this.targetBlockStates.addAll(block.getStateFactory().getStates());
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockFinder(BlockState blockState) {
|
||||||
|
this.targetBlockStates.add(blockState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BlockPos> findInChunk(World world, ChunkPos chunkPos) {
|
||||||
|
List<BlockPos> result = new ArrayList<>();
|
||||||
|
ChunkWrapper chunkWrapper = new ChunkWrapper(world, chunkPos);
|
||||||
|
Chunk chunk = chunkWrapper.getChunk();
|
||||||
|
|
||||||
|
for(BlockPos pos: CHUNK_POSITIONS) {
|
||||||
|
BlockState currentState = chunk.getBlockState(pos);
|
||||||
|
|
||||||
|
if(this.targetBlockStates.contains(currentState)) {
|
||||||
|
result.add(chunkPos.getCenterBlockPos().add(pos));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package kaptainwutax.seedcracker.finder;
|
||||||
|
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.block.Blocks;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.ChunkPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.biome.Biome;
|
||||||
|
import net.minecraft.world.gen.feature.Feature;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BuriedTreasureFinder extends BlockFinder {
|
||||||
|
|
||||||
|
protected static final List<BlockState> CHEST_HOLDERS = new ArrayList<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
CHEST_HOLDERS.add(Blocks.SANDSTONE.getDefaultState());
|
||||||
|
CHEST_HOLDERS.add(Blocks.STONE.getDefaultState());
|
||||||
|
CHEST_HOLDERS.add(Blocks.ANDESITE.getDefaultState());
|
||||||
|
CHEST_HOLDERS.add(Blocks.GRANITE.getDefaultState());
|
||||||
|
CHEST_HOLDERS.add(Blocks.DIORITE.getDefaultState());
|
||||||
|
}
|
||||||
|
|
||||||
|
public BuriedTreasureFinder() {
|
||||||
|
super(Blocks.CHEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BlockPos> findInChunk(World world, ChunkPos chunkPos) {
|
||||||
|
//Gets all the positions with a chest in the chunk.
|
||||||
|
List<BlockPos> result = super.findInChunk(world, chunkPos);
|
||||||
|
|
||||||
|
result.removeIf(pos -> {
|
||||||
|
//Buried treasure chests always generate at (9, 9) within a chunk.
|
||||||
|
int localX = pos.getX() & 15;
|
||||||
|
int localZ = pos.getZ() & 15;
|
||||||
|
if(localX != 9 || localZ != 9)return true;
|
||||||
|
|
||||||
|
//Only so many blocks can hold a treasure chest.
|
||||||
|
BlockState chestHolder = world.getBlockState(pos.down());
|
||||||
|
if(!CHEST_HOLDERS.contains(chestHolder))return true;
|
||||||
|
|
||||||
|
//Check if the biome contains the buried treasure feature.
|
||||||
|
Biome biome = world.getBiome(pos);
|
||||||
|
if(!biome.hasStructureFeature(Feature.BURIED_TREASURE))return true;
|
||||||
|
|
||||||
|
//Damn that chest be lucky!
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package kaptainwutax.seedcracker.finder;
|
||||||
|
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.ChunkPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class Finder {
|
||||||
|
|
||||||
|
protected static final List<BlockPos> CHUNK_POSITIONS = new ArrayList<>();
|
||||||
|
protected static final List<BlockPos> SUB_CHUNK_POSITIONS = new ArrayList<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
for(int x = 0; x < 16; x++) {
|
||||||
|
for(int z = 0; z < 16; z++) {
|
||||||
|
for(int y = 0; y < 256; y++) {
|
||||||
|
BlockPos pos = new BlockPos(x, y, z);
|
||||||
|
if(y < 16)SUB_CHUNK_POSITIONS.add(pos);
|
||||||
|
CHUNK_POSITIONS.add(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Finder() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract List<BlockPos> findInChunk(World world, ChunkPos chunkPos);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package kaptainwutax.seedcracker.world;
|
||||||
|
|
||||||
|
import net.minecraft.util.math.ChunkPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
|
public class ChunkWrapper {
|
||||||
|
|
||||||
|
private final World world;
|
||||||
|
private final ChunkPos chunkPos;
|
||||||
|
private final long chunkHash;
|
||||||
|
|
||||||
|
public ChunkWrapper(World world, ChunkPos chunkPos) {
|
||||||
|
this.world = world;
|
||||||
|
this.chunkPos = chunkPos;
|
||||||
|
this.chunkHash = chunkPos.toLong();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Chunk getChunk() {
|
||||||
|
return this.world.getChunk(this.chunkPos.getCenterBlockPos());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user