Working on Spatial Stuff.

This commit is contained in:
Sebastian Hartte
2020-07-17 22:38:27 +02:00
parent 0c5c23e9ff
commit 15d4583c56
35 changed files with 860 additions and 693 deletions
@@ -0,0 +1,132 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.spatial;
import appeng.api.AEApi;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.ChunkRegion;
import net.minecraft.world.Heightmap;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.biome.source.BiomeAccess;
import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.biome.source.FixedBiomeSource;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.chunk.StructuresConfig;
import net.minecraft.world.gen.chunk.VerticalBlockSample;
import java.util.Arrays;
import java.util.Collections;
import java.util.Optional;
public class StorageChunkGenerator extends ChunkGenerator {
private final VerticalBlockSample columnSample;
public static final StorageChunkGenerator INSTANCE = new StorageChunkGenerator();
public static final Codec<StorageChunkGenerator> CODEC = RecordCodecBuilder.create((instance) ->
instance.stable(INSTANCE));
private final BlockState defaultBlockState;
private StorageChunkGenerator() {
super(createBiomeProvider(), createSettings());
this.defaultBlockState = AEApi.instance().definitions().blocks().matrixFrame().block().getDefaultState();
// Vertical sample is mostly used for Feature generation, for those purposes we're all filled with matrix blocks
BlockState[] columnSample = new BlockState[256];
Arrays.fill(columnSample, this.defaultBlockState);
this.columnSample = new VerticalBlockSample(columnSample);
}
@Override
protected Codec<? extends ChunkGenerator> method_28506() {
return CODEC;
}
private static BiomeSource createBiomeProvider() {
return new FixedBiomeSource(StorageCellBiome.INSTANCE);
}
private static StructuresConfig createSettings() {
return new StructuresConfig(Optional.empty(), Collections.emptyMap());
}
@Override
public void buildSurface(ChunkRegion region, Chunk chunk) {
this.fillChunk(chunk);
chunk.setShouldSave(false);
}
private void fillChunk(Chunk chunk) {
BlockPos.Mutable mutPos = new BlockPos.Mutable();
for (int cx = 0; cx < 16; cx++) {
mutPos.setX(cx);
for (int cz = 0; cz < 16; cz++) {
// FIXME: It's likely a bad idea to fill Y in the inner-loop given the storage
// layout of chunks
mutPos.setZ(cz);
for (int cy = 0; cy < 256; cy++) {
mutPos.setY(cy);
chunk.setBlockState(mutPos, defaultBlockState, false);
}
}
}
}
@Override
public int getSeaLevel() {
return 0;
}
@Override
public ChunkGenerator withSeed(long seed) {
return this;
}
@Override
public void populateNoise(WorldAccess world, StructureAccessor accessor, Chunk chunk) {
}
@Override
public BlockView getColumnSample(int x, int z) {
return columnSample;
}
@Override
public int getHeight(int p_222529_1_, int p_222529_2_, Heightmap.Type heightmapType) {
return 0;
}
@Override
public void generateFeatures(ChunkRegion region, StructureAccessor accessor) {
}
@Override
public void carve(long seed, BiomeAccess access, Chunk chunk, GenerationStep.Carver carver) {
}
}