Meteorite
This commit is contained in:
+5
-6
@@ -32,7 +32,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MutableBoundingBox;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
@@ -71,9 +71,9 @@ public final class MeteoritePlacer {
|
||||
private final CraterType craterType;
|
||||
private final boolean pureCrater;
|
||||
private final boolean craterLake;
|
||||
private final MutableBoundingBox boundingBox;
|
||||
private final BlockBox boundingBox;
|
||||
|
||||
public MeteoritePlacer(WorldAccess world, PlacedMeteoriteSettings settings, MutableBoundingBox boundingBox) {
|
||||
public MeteoritePlacer(WorldAccess world, PlacedMeteoriteSettings settings, BlockBox boundingBox) {
|
||||
this.boundingBox = boundingBox;
|
||||
this.world = world;
|
||||
this.pos = settings.getPos();
|
||||
@@ -186,8 +186,7 @@ public final class MeteoritePlacer {
|
||||
}
|
||||
}
|
||||
|
||||
for (final Object o : world.getEntitiesWithinAABB(ItemEntity.class,
|
||||
new Box(minX(x - 30), y - 5, minZ(z - 30), maxX(x + 30), y + 30, maxZ(z + 30)))) {
|
||||
for (final Object o : world.getEntities(ItemEntity.class, new Box(minX(x - 30), y - 5, minZ(z - 30), maxX(x + 30), y + 30, maxZ(z + 30)), null)) {
|
||||
final Entity e = (Entity) o;
|
||||
e.remove();
|
||||
}
|
||||
@@ -354,7 +353,7 @@ public final class MeteoritePlacer {
|
||||
final double height = this.crater * (extraRange + 0.2)
|
||||
- Math.abs(dist - this.crater * 1.7);
|
||||
|
||||
if (!xf.isAir(world, blockPosDown) && height > 0 && Math.random() > 0.6) {
|
||||
if (!xf.isAir() && height > 0 && Math.random() > 0.6) {
|
||||
randomShit++;
|
||||
this.type.getRandomFall(world, blockPos);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package appeng.worldgen.meteorite;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.source.BiomeSource;
|
||||
import net.minecraft.world.gen.ChunkRandom;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
||||
import net.minecraft.world.gen.feature.StructureFeature;
|
||||
|
||||
public class MeteoriteStructure extends StructureFeature<DefaultFeatureConfig> {
|
||||
|
||||
public static final Identifier ID = AppEng.makeId("meteorite");
|
||||
|
||||
public static final StructureFeature<DefaultFeatureConfig> INSTANCE = new MeteoriteStructure(DefaultFeatureConfig.CODEC);
|
||||
|
||||
public MeteoriteStructure(Codec<DefaultFeatureConfig> configCodec) {
|
||||
super(configCodec);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
+13
-12
@@ -20,13 +20,14 @@ package appeng.worldgen.meteorite;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.structure.StructurePiece;
|
||||
import net.minecraft.structure.StructurePieceType;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.math.MutableBoundingBox;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.world.ServerWorldAccess;
|
||||
import net.minecraft.world.gen.StructureAccessor;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.feature.structure.IStructurePieceType;
|
||||
import net.minecraft.world.gen.feature.structure.StructurePiece;
|
||||
import net.minecraft.structure.StructureManager;
|
||||
|
||||
import appeng.core.worlddata.WorldData;
|
||||
@@ -34,10 +35,10 @@ import appeng.worldgen.meteorite.fallout.FalloutMode;
|
||||
|
||||
public class MeteoriteStructurePiece extends StructurePiece {
|
||||
|
||||
public static final IStructurePieceType TYPE = IStructurePieceType.register(MeteoriteStructurePiece::new,
|
||||
public static final StructurePieceType TYPE = StructurePieceType.register(MeteoriteStructurePiece::new,
|
||||
"AE2MTRT");
|
||||
|
||||
private PlacedMeteoriteSettings settings;
|
||||
private final PlacedMeteoriteSettings settings;
|
||||
|
||||
protected MeteoriteStructurePiece(BlockPos center, float coreRadius, CraterType craterType, FalloutMode fallout,
|
||||
boolean pureCrater, boolean craterLake) {
|
||||
@@ -49,8 +50,8 @@ public class MeteoriteStructurePiece extends StructurePiece {
|
||||
int range = 4 * 16;
|
||||
|
||||
ChunkPos chunkPos = new ChunkPos(center);
|
||||
this.boundingBox = new MutableBoundingBox(chunkPos.getXStart() - range, center.getY(),
|
||||
chunkPos.getZStart() - range, chunkPos.getXEnd() + range, center.getY(), chunkPos.getZEnd() + range);
|
||||
this.boundingBox = new BlockBox(chunkPos.getStartX() - range, center.getY(),
|
||||
chunkPos.getStartZ() - range, chunkPos.getEndX() + range, center.getY(), chunkPos.getEndZ() + range);
|
||||
}
|
||||
|
||||
public MeteoriteStructurePiece(StructureManager templateManager, CompoundTag tag) {
|
||||
@@ -75,9 +76,9 @@ public class MeteoriteStructurePiece extends StructurePiece {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readAdditional(CompoundTag tag) {
|
||||
protected void toNbt(CompoundTag tag) {
|
||||
tag.putFloat(Constants.TAG_RADIUS, settings.getMeteoriteRadius());
|
||||
tag.putLong(Constants.TAG_POS, settings.getPos().toLong());
|
||||
tag.putLong(Constants.TAG_POS, settings.getPos().asLong());
|
||||
tag.putByte(Constants.TAG_CRATER, (byte) settings.getCraterType().ordinal());
|
||||
tag.putByte(Constants.TAG_FALLOUT, (byte) settings.getFallout().ordinal());
|
||||
tag.putBoolean(Constants.TAG_PURE, settings.isPureCrater());
|
||||
@@ -85,12 +86,12 @@ public class MeteoriteStructurePiece extends StructurePiece {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean create(WorldAccess world, ChunkGenerator chunkGeneratorIn, Random rand, MutableBoundingBox bounds,
|
||||
ChunkPos chunkPos) {
|
||||
public boolean generate(ServerWorldAccess world, StructureAccessor structureAccessor, ChunkGenerator chunkGenerator, Random random, BlockBox bounds, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
MeteoritePlacer placer = new MeteoritePlacer(world, settings, bounds);
|
||||
placer.place();
|
||||
|
||||
WorldData.instance().compassData().service().tryUpdateArea(world, chunkPos); // FIXME: We know the y-range here...
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+26
-29
@@ -12,16 +12,14 @@ import net.minecraft.tag.BlockTags;
|
||||
import net.minecraft.tag.Tag;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MutableBoundingBox;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.Biome.Category;
|
||||
import net.minecraft.world.biome.Biome.TempCategory;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.Heightmap.Type;
|
||||
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
||||
import net.minecraft.world.gen.feature.structure.Structure;
|
||||
import net.minecraft.world.gen.feature.structure.StructureStart;
|
||||
import net.minecraft.world.gen.feature.StructureFeature;
|
||||
import net.minecraft.structure.StructureManager;
|
||||
|
||||
import appeng.worldgen.meteorite.fallout.FalloutMode;
|
||||
@@ -32,20 +30,19 @@ public class MeteoriteStructureStart extends StructureStart<DefaultFeatureConfig
|
||||
private final Tag<Block> terracottaTag = BlockTags.getContainer()
|
||||
.getOrCreate(new Identifier("forge:terracotta"));
|
||||
|
||||
public MeteoriteStructureStart(Structure<?> p_i225815_1_, int p_i225815_2_, int p_i225815_3_,
|
||||
MutableBoundingBox p_i225815_4_, int p_i225815_5_, long p_i225815_6_) {
|
||||
super(p_i225815_1_, p_i225815_2_, p_i225815_3_, p_i225815_4_, p_i225815_5_, p_i225815_6_);
|
||||
public MeteoriteStructureStart(StructureFeature<DefaultFeatureConfig> feature, int chunkX, int chunkZ, BlockBox box, int references, long seed) {
|
||||
super(feature, chunkX, chunkZ, box, references, seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(ChunkGenerator generator, StructureManager templateManagerIn, int chunkX, int chunkZ,
|
||||
Biome biome, DefaultFeatureConfig config) {
|
||||
final int centerX = chunkX * 16 + this.rand.nextInt(16);
|
||||
final int centerZ = chunkZ * 16 + this.rand.nextInt(16);
|
||||
final float meteoriteRadius = (this.rand.nextFloat() * 6.0f) + 2;
|
||||
final int centerX = chunkX * 16 + this.random.nextInt(16);
|
||||
final int centerZ = chunkZ * 16 + this.random.nextInt(16);
|
||||
final float meteoriteRadius = (this.random.nextFloat() * 6.0f) + 2;
|
||||
final int yOffset = (int) Math.ceil(meteoriteRadius) + 1;
|
||||
|
||||
final Set<Biome> t2 = generator.getBiomeProvider().getBiomes(centerX, 0, centerZ, 0);
|
||||
final Set<Biome> t2 = generator.getBiomeSource().getBiomesInArea(centerX, 0, centerZ, 0);
|
||||
final Biome spawnBiome = t2.stream().findFirst().orElse(biome);
|
||||
|
||||
final boolean isOcean = spawnBiome.getCategory() == Category.OCEAN;
|
||||
@@ -76,13 +73,13 @@ public class MeteoriteStructureStart extends StructureStart<DefaultFeatureConfig
|
||||
|
||||
boolean craterLake = this.locateWaterAroundTheCrater(generator, actualPos, meteoriteRadius);
|
||||
CraterType craterType = this.determineCraterType(spawnBiome);
|
||||
boolean pureCrater = this.rand.nextFloat() > .9f;
|
||||
FalloutMode fallout = getFalloutFromBaseBlock(spawnBiome.getSurfaceBuilderConfig().getTop());
|
||||
boolean pureCrater = this.random.nextFloat() > .9f;
|
||||
FalloutMode fallout = getFalloutFromBaseBlock(spawnBiome.getSurfaceConfig().getTopMaterial());
|
||||
|
||||
components.add(
|
||||
children.add(
|
||||
new MeteoriteStructurePiece(actualPos, meteoriteRadius, craterType, fallout, pureCrater, craterLake));
|
||||
|
||||
this.recalculateStructureSize();
|
||||
this.setBoundingBoxFromChildren();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,7 +117,7 @@ public class MeteoriteStructureStart extends StructureStart<DefaultFeatureConfig
|
||||
}
|
||||
|
||||
private CraterType determineCraterType(Biome biome) {
|
||||
final TempCategory temp = biome.getTempCategory();
|
||||
final Biome.TemperatureGroup temp = biome.getTemperatureGroup();
|
||||
final Category category = biome.getCategory();
|
||||
|
||||
// No craters in oceans
|
||||
@@ -129,7 +126,7 @@ public class MeteoriteStructureStart extends StructureStart<DefaultFeatureConfig
|
||||
}
|
||||
|
||||
// 50% chance for a special meteor
|
||||
final boolean specialMeteor = rand.nextFloat() > .5f;
|
||||
final boolean specialMeteor = random.nextFloat() > .5f;
|
||||
|
||||
// Just a normal one
|
||||
if (!specialMeteor) {
|
||||
@@ -137,10 +134,10 @@ public class MeteoriteStructureStart extends StructureStart<DefaultFeatureConfig
|
||||
}
|
||||
|
||||
// Warm biomes, higher chance for lava
|
||||
if (temp == TempCategory.WARM) {
|
||||
if (temp == Biome.TemperatureGroup.WARM) {
|
||||
|
||||
// 50% chance to actually spawn as lava
|
||||
final boolean lava = rand.nextFloat() > .5f;
|
||||
final boolean lava = random.nextFloat() > .5f;
|
||||
|
||||
switch (biome.getPrecipitation()) {
|
||||
// No rainfall, only lava
|
||||
@@ -149,7 +146,7 @@ public class MeteoriteStructureStart extends StructureStart<DefaultFeatureConfig
|
||||
|
||||
// 25% chance to convert a lava to obsidian
|
||||
case RAIN:
|
||||
final boolean obsidian = rand.nextFloat() > .75f;
|
||||
final boolean obsidian = random.nextFloat() > .75f;
|
||||
final CraterType alternativObsidian = obsidian ? CraterType.OBSIDIAN : CraterType.LAVA;
|
||||
return lava ? alternativObsidian : CraterType.NORMAL;
|
||||
|
||||
@@ -160,11 +157,11 @@ public class MeteoriteStructureStart extends StructureStart<DefaultFeatureConfig
|
||||
}
|
||||
|
||||
// Temperate biomes. Water or maybe lava
|
||||
if (temp == TempCategory.MEDIUM) {
|
||||
if (temp == Biome.TemperatureGroup.MEDIUM) {
|
||||
// 75% chance to actually spawn with a crater lake
|
||||
final boolean lake = rand.nextFloat() > .25f;
|
||||
final boolean lake = random.nextFloat() > .25f;
|
||||
// 20% to spawn with lava
|
||||
final boolean lava = rand.nextFloat() > .8f;
|
||||
final boolean lava = random.nextFloat() > .8f;
|
||||
|
||||
switch (biome.getPrecipitation()) {
|
||||
// No rainfall, water how?
|
||||
@@ -172,13 +169,13 @@ public class MeteoriteStructureStart extends StructureStart<DefaultFeatureConfig
|
||||
return lava ? CraterType.LAVA : CraterType.NORMAL;
|
||||
// Rainfall, can also turn lava to obsidian
|
||||
case RAIN:
|
||||
final boolean obsidian = rand.nextFloat() > .75f;
|
||||
final boolean obsidian = random.nextFloat() > .75f;
|
||||
final CraterType alternativObsidian = obsidian ? CraterType.OBSIDIAN : CraterType.LAVA;
|
||||
final CraterType craterLake = lake ? CraterType.WATER : CraterType.NORMAL;
|
||||
return lava ? alternativObsidian : craterLake;
|
||||
// No lava, but snow
|
||||
case SNOW:
|
||||
final boolean snow = rand.nextFloat() > .75f;
|
||||
final boolean snow = random.nextFloat() > .75f;
|
||||
final CraterType water = lake ? CraterType.WATER : CraterType.NORMAL;
|
||||
return snow ? CraterType.SNOW : water;
|
||||
}
|
||||
@@ -186,13 +183,13 @@ public class MeteoriteStructureStart extends StructureStart<DefaultFeatureConfig
|
||||
}
|
||||
|
||||
// Cold biomes, Snow or Ice, maybe water and very rarely lava.
|
||||
if (temp == TempCategory.COLD) {
|
||||
if (temp == Biome.TemperatureGroup.COLD) {
|
||||
// 75% chance to actually spawn with a crater lake
|
||||
final boolean lake = rand.nextFloat() > .25f;
|
||||
final boolean lake = random.nextFloat() > .25f;
|
||||
// 5% to spawn with lava
|
||||
final boolean lava = rand.nextFloat() > .95f;
|
||||
final boolean lava = random.nextFloat() > .95f;
|
||||
// 75% chance to freeze
|
||||
final boolean frozen = rand.nextFloat() > .25f;
|
||||
final boolean frozen = random.nextFloat() > .25f;
|
||||
|
||||
switch (biome.getPrecipitation()) {
|
||||
// No rainfall, water how?
|
||||
+3
-3
@@ -39,7 +39,7 @@ public class MeteoriteSpawner {
|
||||
float coreRadius, CraterType craterType, boolean pureCrater, boolean worldGen) {
|
||||
int stepSize = Math.min(5, (int) Math.ceil(coreRadius) + 1);
|
||||
int minY = 10 + stepSize;
|
||||
BlockPos.Mutable mutablePos = new BlockPos.Mutable(startPos);
|
||||
BlockPos.Mutable mutablePos = startPos.mutableCopy();
|
||||
|
||||
mutablePos.move(Direction.DOWN, stepSize);
|
||||
|
||||
@@ -80,7 +80,7 @@ public class MeteoriteSpawner {
|
||||
}
|
||||
|
||||
private static boolean isAirBelowSpawnPoint(WorldView w, BlockPos pos) {
|
||||
BlockPos.Mutable testPos = new BlockPos.Mutable(pos);
|
||||
BlockPos.Mutable testPos = pos.mutableCopy();
|
||||
for (int j = pos.getY() - 15; j < pos.getY() - 1; j++) {
|
||||
testPos.setY(j);
|
||||
if (w.isAir(testPos)) {
|
||||
@@ -100,7 +100,7 @@ public class MeteoriteSpawner {
|
||||
testPos.setY(j);
|
||||
for (int k = pos.getZ() - 15; k < pos.getZ() + 15; k++) {
|
||||
testPos.setZ(k);
|
||||
if (w.canBlockSeeSky(testPos)) {
|
||||
if (w.isSkyVisibleAllowingSea(testPos)) {
|
||||
skyMode++;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -36,7 +36,7 @@ public class FalloutCopy extends Fallout {
|
||||
public FalloutCopy(final WorldAccess w, BlockPos pos, final MeteoriteBlockPutter putter, final BlockState skyStone) {
|
||||
super(putter, skyStone);
|
||||
this.putter = putter;
|
||||
this.block = w.getBiome(pos).getSurfaceBuilderConfig().getTop();
|
||||
this.block = w.getBiome(pos).getSurfaceConfig().getTopMaterial();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -28,9 +28,9 @@ import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.math.MutableBoundingBox;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
@@ -114,7 +114,7 @@ public class MeteoritePlacerItem extends AEBaseItem {
|
||||
// we have to assume maximum size
|
||||
int range = (int) Math.ceil((coreRadius * 2 + 5) * 5f);
|
||||
|
||||
MutableBoundingBox boundingBox = new MutableBoundingBox(pos.getX() - range, pos.getY(), pos.getZ() - range,
|
||||
BlockBox boundingBox = new BlockBox(pos.getX() - range, pos.getY(), pos.getZ() - range,
|
||||
pos.getX() + range, pos.getY(), pos.getZ() + range);
|
||||
|
||||
final MeteoritePlacer placer = new MeteoritePlacer(world, spawned, boundingBox);
|
||||
|
||||
@@ -1,176 +0,0 @@
|
||||
package appeng.worldgen.meteorite;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.world.PersistentState;
|
||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||||
|
||||
/**
|
||||
* This is per-world data to track where Meteorites have been spawned.
|
||||
*/
|
||||
public final class MeteoriteSpawnData {
|
||||
|
||||
private static final String NAME = "ae2_meteorite_spawns";
|
||||
|
||||
private final SavedData data;
|
||||
|
||||
private MeteoriteSpawnData(SavedData data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public void setGenerated(ChunkPos chunkPos) {
|
||||
synchronized (data) {
|
||||
// edit.
|
||||
data.generated.add(chunkPos.asLong());
|
||||
data.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasGenerated(ChunkPos pos) {
|
||||
synchronized (data) {
|
||||
return data.generated.contains(pos.asLong());
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private CompoundTag getSpawnData(int chunkX, int chunkZ, boolean create) {
|
||||
chunkX /= 16;
|
||||
chunkZ /= 16;
|
||||
String key = chunkX + "," + chunkZ;
|
||||
Tag inbt = data.spawns.get(key);
|
||||
if (!(inbt instanceof CompoundTag)) {
|
||||
if (create) {
|
||||
inbt = new CompoundTag();
|
||||
data.spawns.put(key, inbt);
|
||||
data.markDirty();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return (CompoundTag) inbt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether another meteorite has spawned within the given block range of
|
||||
* the given position.
|
||||
*/
|
||||
public boolean isMeteoriteSpawnInRange(BlockPos pos, int rangeSquared) {
|
||||
synchronized (data) {
|
||||
ChunkPos chunkPos = new ChunkPos(pos);
|
||||
CompoundTag spawnData = getSpawnData(chunkPos.x, chunkPos.z, false);
|
||||
if (spawnData == null) {
|
||||
return false;
|
||||
}
|
||||
final int size = spawnData.getInt("num");
|
||||
for (int i = 0; i < size; i++) {
|
||||
CompoundTag existingSettingsNbt = spawnData.getCompound(String.valueOf(i));
|
||||
BlockPos existingPos = PlacedMeteoriteSettings.read(existingSettingsNbt).getPos();
|
||||
int deltaX = (existingPos.getX() - pos.getX());
|
||||
int deltaZ = (existingPos.getZ() - pos.getZ());
|
||||
if (deltaX * deltaX + deltaZ * deltaZ <= rangeSquared) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean tryAddSpawnedMeteorite(PlacedMeteoriteSettings settings, int minDistanceSquared) {
|
||||
synchronized (data) {
|
||||
if (isMeteoriteSpawnInRange(settings.getPos(), minDistanceSquared)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
addSpawnedMeteorite(settings);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addSpawnedMeteorite(PlacedMeteoriteSettings settings) {
|
||||
synchronized (data) {
|
||||
ChunkPos chunkPos = new ChunkPos(settings.getPos());
|
||||
CompoundTag spawnData = getSpawnData(chunkPos.x, chunkPos.z, true);
|
||||
final int size = spawnData.getInt("num");
|
||||
spawnData.put(String.valueOf(size), settings.write(new CompoundTag()));
|
||||
spawnData.putInt("num", size + 1);
|
||||
data.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<PlacedMeteoriteSettings> getNearByMeteorites(int chunkX, int chunkZ) {
|
||||
final Collection<PlacedMeteoriteSettings> ll = new ArrayList<>();
|
||||
|
||||
synchronized (data) {
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
for (int z = -1; z <= 1; z++) {
|
||||
final int cx = x + (chunkX >> 4);
|
||||
final int cz = z + (chunkZ >> 4);
|
||||
|
||||
final CompoundTag data = getSpawnData(cx << 4, cz << 4, false);
|
||||
|
||||
if (data != null) {
|
||||
// edit.
|
||||
final int size = data.getInt("num");
|
||||
for (int s = 0; s < size; s++) {
|
||||
CompoundTag settingsNbt = data.getCompound(String.valueOf(s));
|
||||
ll.add(PlacedMeteoriteSettings.read(settingsNbt));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ll;
|
||||
}
|
||||
|
||||
public synchronized static MeteoriteSpawnData get(WorldAccess world) {
|
||||
ServerWorld serverWorld;
|
||||
if (world instanceof ServerWorld) {
|
||||
serverWorld = (ServerWorld) world;
|
||||
} else {
|
||||
MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
|
||||
serverWorld = server.getWorld(world.getDimension().getType());
|
||||
}
|
||||
|
||||
SavedData savedData = serverWorld.getPersistentStateManager().getOrCreate(SavedData::new, NAME);
|
||||
return new MeteoriteSpawnData(savedData);
|
||||
}
|
||||
|
||||
private static class SavedData extends PersistentState {
|
||||
|
||||
private LongOpenHashSet generated;
|
||||
private CompoundTag spawns;
|
||||
|
||||
public SavedData() {
|
||||
super(NAME);
|
||||
this.generated = new LongOpenHashSet();
|
||||
this.spawns = new CompoundTag();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void fromTag(CompoundTag nbt) {
|
||||
this.generated = new LongOpenHashSet(nbt.getLongArray("generated"));
|
||||
this.spawns = nbt.getCompound("spawns");
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized CompoundTag toTag(CompoundTag compound) {
|
||||
compound.putLongArray("generated", generated.toLongArray());
|
||||
compound.put("spawns", spawns);
|
||||
return compound;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
package appeng.worldgen.meteorite;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.mojang.serialization.Dynamic;
|
||||
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.BiomeManager;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.EndChunkGenerator;
|
||||
import net.minecraft.world.gen.NetherChunkGenerator;
|
||||
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
||||
import net.minecraft.world.gen.feature.StructureFeature;
|
||||
import net.minecraft.world.gen.feature.structure.ScatteredStructure;
|
||||
import net.minecraft.world.gen.feature.structure.Structure;
|
||||
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.AppEng;
|
||||
|
||||
public class MeteoriteStructure extends StructureFeature<DefaultFeatureConfig> {
|
||||
|
||||
public static final StructureFeature<DefaultFeatureConfig> INSTANCE = new MeteoriteStructure(DefaultFeatureConfig::deserialize);
|
||||
|
||||
static {
|
||||
INSTANCE.setRegistryName(AppEng.MOD_ID, "meteorite");
|
||||
}
|
||||
|
||||
public MeteoriteStructure(Function<Dynamic<?>, ? extends DefaultFeatureConfig> configFactoryIn) {
|
||||
super(configFactoryIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeGenerated(BiomeManager biomeManagerIn, ChunkGenerator generator, Random randIn, int chunkX,
|
||||
int chunkZ, Biome biomeIn) {
|
||||
if (super.canBeGenerated(biomeManagerIn, generator, randIn, chunkX, chunkZ, biomeIn)) {
|
||||
// In case the biome blacklist fails, we still double-check here that we're not
|
||||
// generating chunks for
|
||||
// the nether or end.
|
||||
if (generator.getClass().equals(EndChunkGenerator.class)
|
||||
|| generator.getClass().equals(NetherChunkGenerator.class)) {
|
||||
AELog.warn("ignoring attempt to generate meteorite in nether/end.");
|
||||
return false;
|
||||
}
|
||||
|
||||
int i = chunkX >> 4;
|
||||
int j = chunkZ >> 4;
|
||||
randIn.setSeed((long) (i ^ j << 4) ^ generator.getSeed());
|
||||
randIn.nextInt();
|
||||
return randIn.nextBoolean();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStructureName() {
|
||||
return INSTANCE.getRegistryName().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StructureStartFactory<DefaultFeatureConfig> getStructureStartFactory() {
|
||||
return MeteoriteStructureStart::new;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSeedModifier() {
|
||||
return 124895654;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user