Compiles again.

This commit is contained in:
Sebastian Hartte
2020-07-27 23:50:28 +02:00
parent 56ecda5173
commit 84e6aaa122
136 changed files with 1004 additions and 1108 deletions
@@ -1,9 +1,11 @@
package appeng.worldgen;
import com.google.common.collect.ImmutableMap;
import com.mojang.serialization.Codec;
import com.mojang.serialization.Dynamic;
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.world.gen.feature.IFeatureConfig;
@@ -16,6 +18,12 @@ import appeng.core.AEConfig;
*/
public class ChargedQuartzOreConfig implements IFeatureConfig {
public static final Codec<ChargedQuartzOreConfig> CODEC = RecordCodecBuilder.create((instance) -> instance
.group(BlockState.field_235877_b_.fieldOf("target").forGetter((config) -> config.target),
BlockState.field_235877_b_.fieldOf("state").forGetter((config) -> config.state),
Codec.FLOAT.fieldOf("chance").withDefault(0f).forGetter((config) -> config.chance))
.apply(instance, ChargedQuartzOreConfig::new));
public final BlockState target;
public final BlockState state;
public final float chance;
@@ -26,20 +34,4 @@ public class ChargedQuartzOreConfig implements IFeatureConfig {
this.chance = chance;
}
@Override
public <T> Dynamic<T> serialize(DynamicOps<T> ops) {
return new Dynamic<>(ops,
ops.createMap(
ImmutableMap.of(ops.createString("target"), BlockState.serialize(ops, this.target).getValue(),
ops.createString("state"), BlockState.serialize(ops, this.state).getValue(),
ops.createString("chance"), ops.createFloat(this.chance))));
}
public static <T> ChargedQuartzOreConfig deserialize(Dynamic<T> p_214657_0_) {
BlockState target = p_214657_0_.get("target").map(BlockState::deserialize).orElse(Blocks.AIR.getDefaultState());
BlockState state = p_214657_0_.get("state").map(BlockState::deserialize).orElse(Blocks.AIR.getDefaultState());
float chance = p_214657_0_.get("chance").asFloat(AEConfig.instance().getSpawnChargedChance());
return new ChargedQuartzOreConfig(target, state, chance);
}
}
@@ -1,9 +1,6 @@
package appeng.worldgen;
import java.util.Random;
import com.mojang.serialization.Codec;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.ISeedReader;
@@ -11,31 +8,25 @@ import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.Heightmap;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.ReplaceBlockFeature;
import net.minecraft.world.gen.feature.structure.StructureManager;
import appeng.core.AppEng;
import java.util.Random;
/**
* Extends {@link ReplaceBlockFeature} by also allowing for a replacement
* chance. In addition, the feature will check every block in the chunk.
* Extends {@link net.minecraft.world.gen.feature.OreFeature} by also allowing
* for a replacement chance. In addition, the feature will check every block in
* the chunk.
*/
public class ChargedQuartzOreFeature extends Feature<ChargedQuartzOreConfig> {
public static final ChargedQuartzOreFeature INSTANCE = new ChargedQuartzOreFeature(
ChargedQuartzOreConfig::deserialize);
public static final ChargedQuartzOreFeature INSTANCE = new ChargedQuartzOreFeature(ChargedQuartzOreConfig.CODEC);
static {
INSTANCE.setRegistryName(AppEng.MOD_ID, "charged_quartz_ore");
}
public ChargedQuartzOreFeature(Codec<ChargedQuartzOreConfig> p_i51444_1_) {
super(p_i51444_1_);
public ChargedQuartzOreFeature(Codec<ChargedQuartzOreConfig> codec) {
super(codec);
}
@Override
public boolean func_230362_a_(ISeedReader worldIn, StructureManager sm, ChunkGenerator generator, Random rand,
BlockPos pos, ChargedQuartzOreConfig config) {
public boolean func_230362_a_(ISeedReader worldIn, StructureManager structureAccessor, ChunkGenerator generator, Random rand, BlockPos pos, ChargedQuartzOreConfig config) {
ChunkPos chunkPos = new ChunkPos(pos);
BlockPos.Mutable bpos = new BlockPos.Mutable();
@@ -1,176 +0,0 @@
package appeng.worldgen.meteorite;
import java.util.ArrayList;
import java.util.Collection;
import javax.annotation.Nullable;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.IWorld;
import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.storage.WorldSavedData;
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 CompoundNBT getSpawnData(int chunkX, int chunkZ, boolean create) {
chunkX /= 16;
chunkZ /= 16;
String key = chunkX + "," + chunkZ;
INBT inbt = data.spawns.get(key);
if (!(inbt instanceof CompoundNBT)) {
if (create) {
inbt = new CompoundNBT();
data.spawns.put(key, inbt);
data.markDirty();
} else {
return null;
}
}
return (CompoundNBT) 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);
CompoundNBT 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++) {
CompoundNBT 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());
CompoundNBT spawnData = getSpawnData(chunkPos.x, chunkPos.z, true);
final int size = spawnData.getInt("num");
spawnData.put(String.valueOf(size), settings.write(new CompoundNBT()));
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 CompoundNBT data = getSpawnData(cx << 4, cz << 4, false);
if (data != null) {
// edit.
final int size = data.getInt("num");
for (int s = 0; s < size; s++) {
CompoundNBT settingsNbt = data.getCompound(String.valueOf(s));
ll.add(PlacedMeteoriteSettings.read(settingsNbt));
}
}
}
}
}
return ll;
}
public synchronized static MeteoriteSpawnData get(IWorld world) {
ServerWorld serverWorld;
if (world instanceof ServerWorld) {
serverWorld = (ServerWorld) world;
} else {
MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
serverWorld = server.getWorld(world.getDimension().getType());
}
SavedData savedData = serverWorld.getSavedData().getOrCreate(SavedData::new, NAME);
return new MeteoriteSpawnData(savedData);
}
private static class SavedData extends WorldSavedData {
private LongOpenHashSet generated;
private CompoundNBT spawns;
public SavedData() {
super(NAME);
this.generated = new LongOpenHashSet();
this.spawns = new CompoundNBT();
}
@Override
public synchronized void read(CompoundNBT nbt) {
this.generated = new LongOpenHashSet(nbt.getLongArray("generated"));
this.spawns = nbt.getCompound("spawns");
}
@Override
public synchronized CompoundNBT write(CompoundNBT compound) {
compound.putLongArray("generated", generated.toLongArray());
compound.put("spawns", spawns);
return compound;
}
}
}
@@ -4,10 +4,15 @@ import java.util.Random;
import com.mojang.serialization.Codec;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SharedSeedRandom;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeManager;
import net.minecraft.world.biome.provider.BiomeProvider;
import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.feature.NoFeatureConfig;
import net.minecraft.world.gen.feature.StructureFeature;
import net.minecraft.world.gen.feature.structure.Structure;
import appeng.core.AELog;
@@ -15,56 +20,23 @@ import appeng.core.AppEng;
public class MeteoriteStructure extends Structure<NoFeatureConfig> {
public static final Structure<NoFeatureConfig> INSTANCE = new MeteoriteStructure(NoFeatureConfig.field_236558_a_);
public static final ResourceLocation ID = AppEng.makeId("meteorite");
static {
INSTANCE.setRegistryName(AppEng.MOD_ID, "meteorite");
}
public static final Structure<NoFeatureConfig> INSTANCE = new MeteoriteStructure(
NoFeatureConfig.field_236558_a_);
public MeteoriteStructure(Codec<NoFeatureConfig> p_i231997_1_) {
super(p_i231997_1_);
public MeteoriteStructure(Codec<NoFeatureConfig> configCodec) {
super(configCodec);
}
@Override
public boolean func_230363_a_(BiomeManager biomeManagerIn, ChunkGenerator generator, Random randIn, int chunkX,
int chunkZ, Biome biomeIn) {
if (super.func_230363_a_(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;
protected boolean func_230363_a_(ChunkGenerator generator, BiomeProvider biomeSource, long seed, SharedSeedRandom randIn, int chunkX, int chunkZ, Biome biome, ChunkPos chunkPos2, NoFeatureConfig featureConfig) {
return randIn.nextBoolean();
}
@Override
public String getStructureName() {
return INSTANCE.getRegistryName().toString();
}
@Override
public int getSize() {
return 2;
}
@Override
public Structure.IStartFactory getStartFactory() {
public IStartFactory<NoFeatureConfig> getStartFactory() {
return MeteoriteStructureStart::new;
}
@Override
protected int getSeedModifier() {
return 124895654;
}
}
@@ -23,9 +23,11 @@ import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.MutableBoundingBox;
import net.minecraft.world.ISeedReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.feature.structure.IStructurePieceType;
import net.minecraft.world.gen.feature.structure.StructureManager;
import net.minecraft.world.gen.feature.structure.StructurePiece;
import net.minecraft.world.gen.feature.template.TemplateManager;
@@ -85,12 +87,11 @@ public class MeteoriteStructurePiece extends StructurePiece {
}
@Override
public boolean create(IWorld world, ChunkGenerator<?> chunkGeneratorIn, Random rand, MutableBoundingBox bounds,
ChunkPos chunkPos) {
public boolean func_230383_a_(ISeedReader world, StructureManager p_230383_2_, ChunkGenerator chunkGeneratorIn, Random rand, MutableBoundingBox bounds, ChunkPos chunkPos, BlockPos p_230383_7_) {
MeteoritePlacer placer = new MeteoritePlacer(world, settings, bounds);
placer.place();
WorldData.instance().compassData().service().updateArea(world, chunkPos); // FIXME: We know the y-range here...
WorldData.instance().compassData().service().tryUpdateArea(world, chunkPos); // FIXME: We know the y-range here...
return true;
}
}
@@ -18,25 +18,26 @@ import net.minecraft.world.biome.Biome.TempCategory;
import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.Heightmap;
import net.minecraft.world.gen.Heightmap.Type;
import net.minecraft.world.gen.feature.NoFeatureConfig;
import net.minecraft.world.gen.feature.structure.Structure;
import net.minecraft.world.gen.feature.structure.StructureStart;
import net.minecraft.world.gen.feature.template.TemplateManager;
import appeng.worldgen.meteorite.fallout.FalloutMode;
public class MeteoriteStructureStart extends StructureStart {
public class MeteoriteStructureStart extends StructureStart<NoFeatureConfig> {
private final ITag<Block> sandTag = BlockTags.getCollection().getOrCreate(new ResourceLocation("minecraft:sand"));
private final ITag<Block> terracottaTag = BlockTags.getCollection()
.getOrCreate(new ResourceLocation("forge:terracotta"));
public MeteoriteStructureStart(Structure<?> p_i225815_1_, int p_i225815_2_, int p_i225815_3_,
public MeteoriteStructureStart(Structure<NoFeatureConfig> 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 void init(ChunkGenerator<?> generator, TemplateManager templateManagerIn, int chunkX, int chunkZ,
Biome biome) {
public void func_230364_a_(ChunkGenerator generator, TemplateManager templateManagerIn, int chunkX, int chunkZ,
Biome biome, NoFeatureConfig 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;
@@ -53,7 +54,7 @@ public class MeteoriteStructureStart extends StructureStart {
int scanRadius = (int) Math.max(1, meteoriteRadius * 2);
for (int x = -scanRadius; x <= scanRadius; x++) {
for (int z = -scanRadius; z <= scanRadius; z++) {
int h = generator.getHeight(centerX + x, centerZ + z, heightmapType);
int h = generator.func_222529_a(centerX + x, centerZ + z, heightmapType);
stats.add(h);
}
}
@@ -88,7 +89,7 @@ public class MeteoriteStructureStart extends StructureStart {
* @return true, if it found a single block of water
*/
private boolean locateWaterAroundTheCrater(ChunkGenerator generator, BlockPos pos, float radius) {
final int seaLevel = generator.getSeaLevel();
final int seaLevel = generator.func_230356_f_();
final int maxY = seaLevel - 1;
BlockPos.Mutable blockPos = new BlockPos.Mutable();
@@ -105,7 +106,7 @@ public class MeteoriteStructureStart extends StructureStart {
final double distanceFrom = dx * dx + dz * dz;
if (maxY > h + distanceFrom * 0.0175 && maxY < h + distanceFrom * 0.02) {
int heigth = generator.getHeight(blockPos.getX(), blockPos.getZ(), Heightmap.Type.OCEAN_FLOOR);
int heigth = generator.func_222529_a(blockPos.getX(), blockPos.getZ(), Heightmap.Type.OCEAN_FLOOR);
if (heigth < seaLevel) {
return true;
}