First Working Worldgen of Meteorites

This commit is contained in:
Sebastian Hartte
2020-07-07 18:55:56 +02:00
parent f8ee4bb1f2
commit 2944873431
10 changed files with 81 additions and 51 deletions
@@ -20,6 +20,9 @@ package appeng.block.storage;
import javax.annotation.Nullable;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.container.implementations.SkyChestContainer;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
@@ -76,8 +79,7 @@ public class SkyChestBlock extends AEBaseTileBlock<SkyChestBlockEntity> {
return ActionResult.PASS;
}
throw new IllegalStateException();
// FIXME FABRIC ContainerOpener.openContainer(SkyChestContainer.TYPE, player, ContainerLocator.forTileEntity(tile));
ContainerOpener.openContainer(SkyChestContainer.TYPE, player, ContainerLocator.forTileEntity(tile));
}
return ActionResult.SUCCESS;
+24 -3
View File
@@ -35,6 +35,8 @@ import appeng.mixins.CriteriaRegisterMixin;
import appeng.recipes.handlers.*;
import appeng.worldgen.ChargedQuartzOreConfig;
import appeng.worldgen.ChargedQuartzOreFeature;
import appeng.worldgen.meteorite.MeteoriteStructure;
import net.earthcomputer.libstructure.LibStructure;
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.BlockState;
@@ -50,11 +52,11 @@ import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.chunk.StructureConfig;
import net.minecraft.world.gen.decorator.Decorator;
import net.minecraft.world.gen.decorator.NopeDecoratorConfig;
import net.minecraft.world.gen.decorator.RangeDecoratorConfig;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraft.world.gen.feature.*;
import java.util.function.Consumer;
@@ -295,14 +297,33 @@ public abstract class AppEngBase implements AppEng {
}
private void registerWorldGen() {
LibStructure.registerStructure(
MeteoriteStructure.ID,
MeteoriteStructure.INSTANCE,
GenerationStep.Feature.TOP_LAYER_MODIFICATION,
new StructureConfig(32, 8, 124895654),
new MeteoriteStructure(DefaultFeatureConfig.CODEC).configure(DefaultFeatureConfig.INSTANCE)
);
Registry.register(Registry.FEATURE, AppEng.makeId("charged_quartz_ore"), new ChargedQuartzOreFeature(ChargedQuartzOreConfig.CODEC));
Biome.BIOMES.forEach(b -> {
// FIXME FABRIC addMeteoriteWorldGen(b);
addMeteoriteWorldGen(b);
addQuartzWorldGen(b);
});
}
private static void addMeteoriteWorldGen(Biome b) {
if (!AEConfig.instance().isFeatureEnabled(AEFeature.METEORITE_WORLD_GEN)) {
return;
}
if (b.getCategory() == Biome.Category.THEEND || b.getCategory() == Biome.Category.NETHER) {
return;
}
b.addStructureFeature(MeteoriteStructure.INSTANCE.configure(FeatureConfig.DEFAULT));
}
private static void addQuartzWorldGen(Biome b) {
if (!AEConfig.instance().isFeatureEnabled(AEFeature.CERTUS_QUARTZ_WORLD_GEN)) {
return;
@@ -60,8 +60,7 @@ public class SkyStoneBlock extends AEBaseBlock {
BlockPos currentPos, BlockPos facingPos) {
if (worldIn instanceof ServerWorld) {
ServerWorld serverWorld = (ServerWorld) worldIn;
WorldData.instance().compassData().service().updateArea(serverWorld, new ChunkPos(currentPos),
currentPos.getY());
WorldData.instance().compassData().service().notifyBlockChange(serverWorld, currentPos);
}
return super.getStateForNeighborUpdate(stateIn, facing, facingState, worldIn, currentPos, facingPos);
@@ -79,7 +78,7 @@ public class SkyStoneBlock extends AEBaseBlock {
if (w instanceof ServerWorld) {
ServerWorld serverWorld = (ServerWorld) w;
WorldData.instance().compassData().service().updateArea(serverWorld, new ChunkPos(pos), pos.getY());
WorldData.instance().compassData().service().notifyBlockChange(serverWorld, pos);
}
}
@@ -31,6 +31,7 @@ import net.minecraft.block.Block;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.chunk.Chunk;
@@ -90,38 +91,52 @@ public final class CompassService {
public void tryUpdateArea(final WorldAccess w, ChunkPos chunkPos) {
// If this seems weird: during worldgen, WorldAccess is a specific region, but getWorld is
// still the server world
// still the server world. We do need to use the world access to get the chunk in question
// though, since during worldgen, it's not comitted to the actual world yet.
World world = w.getWorld();
if (!(world instanceof ServerWorld)) {
return;
}
updateArea((ServerWorld) world, chunkPos);
Chunk chunk = w.getChunk(chunkPos.x, chunkPos.z);
updateArea((ServerWorld) world, chunk);
}
public void updateArea(final ServerWorld w, ChunkPos chunkPos) {
this.updateArea(w, chunkPos, CHUNK_SIZE);
this.updateArea(w, chunkPos, CHUNK_SIZE + 32);
this.updateArea(w, chunkPos, CHUNK_SIZE + 64);
this.updateArea(w, chunkPos, CHUNK_SIZE + 96);
this.updateArea(w, chunkPos, CHUNK_SIZE + 128);
this.updateArea(w, chunkPos, CHUNK_SIZE + 160);
this.updateArea(w, chunkPos, CHUNK_SIZE + 192);
this.updateArea(w, chunkPos, CHUNK_SIZE + 224);
Chunk chunk = w.getChunk(chunkPos.x, chunkPos.z);
updateArea(w, chunk);
}
public Future<?> updateArea(final ServerWorld w, ChunkPos chunkPos, int y) {
public void updateArea(final ServerWorld w, Chunk chunk) {
this.updateArea(w, chunk, CHUNK_SIZE);
this.updateArea(w, chunk, CHUNK_SIZE + 32);
this.updateArea(w, chunk, CHUNK_SIZE + 64);
this.updateArea(w, chunk, CHUNK_SIZE + 96);
this.updateArea(w, chunk, CHUNK_SIZE + 128);
this.updateArea(w, chunk, CHUNK_SIZE + 160);
this.updateArea(w, chunk, CHUNK_SIZE + 192);
this.updateArea(w, chunk, CHUNK_SIZE + 224);
}
/**
* Notifies the compass service that a skystone block has either been placed or replaced
* at the give position.
*/
public void notifyBlockChange(final ServerWorld w, BlockPos pos) {
Chunk chunk = w.getChunk(pos);
updateArea(w, chunk, pos.getY());
}
private Future<?> updateArea(final ServerWorld w, Chunk c, int y) {
this.jobSize++;
final int cx = chunkPos.x;
final int cdy = y >> 5;
final int cz = chunkPos.z;
final int low_y = cdy << 5;
final int hi_y = low_y + 32;
// lower level...
final Chunk c = w.getChunk(cx, cz);
int cx = c.getPos().x;
int cz = c.getPos().z;
Block skyStoneBlock = AEApi.instance().definitions().blocks().skyStoneBlock().block();
BlockPos.Mutable pos = new BlockPos.Mutable();
@@ -39,7 +39,6 @@ import net.minecraft.util.math.Direction;
*/
public abstract class InventoryAdaptor implements Iterable<ItemSlot> {
public static InventoryAdaptor getAdaptor(final BlockEntity te, final Direction d) {
FixedItemInv inv = ItemAttributes.FIXED_INV.get(te.getWorld(), te.getPos().offset(d), SearchOptions.inDirection(d.getOpposite()));
if (inv == ItemAttributes.FIXED_INV.defaultValue) {
@@ -21,6 +21,12 @@ package appeng.worldgen.meteorite;
import java.util.ArrayList;
import java.util.List;
import alexiil.mc.lib.attributes.AttributeList;
import alexiil.mc.lib.attributes.AttributeProvider;
import alexiil.mc.lib.attributes.AttributeUtil;
import alexiil.mc.lib.attributes.item.ItemAttributes;
import appeng.tile.storage.SkyChestBlockEntity;
import appeng.util.inv.AdaptorFixedInv;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
@@ -203,8 +209,12 @@ public final class MeteoritePlacer {
if (AEConfig.instance().isFeatureEnabled(AEFeature.SPAWN_PRESSES_IN_METEORITES)) {
this.putter.put(world, pos, this.skyChestDefinition.block().getDefaultState());
final BlockEntity te = world.getBlockEntity(pos); // FIXME: this is also probably a band-aid for another issue
final InventoryAdaptor ap = InventoryAdaptor.getAdaptor(te, Direction.UP);
final SkyChestBlockEntity te = (SkyChestBlockEntity) world.getBlockEntity(pos);
InventoryAdaptor ap = null;
if (te != null) {
ap = new AdaptorFixedInv(te.getInternalInventory());
}
if (ap != null && !ap.containsItems()) // FIXME: band-aid for meteorites being generated multiple times
{
// TODO: loot tables would be better
@@ -23,18 +23,9 @@ public class MeteoriteStructure extends StructureFeature<DefaultFeatureConfig> {
@Override
public boolean shouldStartAt(ChunkGenerator generator, BiomeSource biomeSource, long seed, ChunkRandom randIn, int chunkX, int chunkZ, Biome biome, ChunkPos chunkPos2, DefaultFeatureConfig featureConfig) {
int i = chunkX >> 4;
int j = chunkZ >> 4;
randIn.setSeed((long) (i ^ j << 4) ^ seed);
randIn.nextInt();
return randIn.nextBoolean();
}
@Override
public String getName() {
return ID.toString();
}
@Override
public StructureStartFactory<DefaultFeatureConfig> getStructureStartFactory() {
return MeteoriteStructureStart::new;
@@ -71,7 +71,7 @@ public final class PlacedMeteoriteSettings {
}
public CompoundTag write(CompoundTag tag) {
tag.putLong(Constants.TAG_POS, pos.toLong());
tag.putLong(Constants.TAG_POS, pos.asLong());
tag.putFloat(Constants.TAG_RADIUS, meteoriteRadius);
tag.putByte(Constants.TAG_CRATER, (byte) craterType.ordinal());