Added new meteor types (#4428)

This commit is contained in:
yueh
2020-06-22 22:18:21 +02:00
committed by GitHub
parent f32289d881
commit adf1bd0191
25 changed files with 563 additions and 470 deletions
+1 -1
View File
@@ -114,7 +114,7 @@ import appeng.tile.AEBaseTileEntity;
import appeng.tile.crafting.MolecularAssemblerRenderer;
import appeng.worldgen.ChargedQuartzOreConfig;
import appeng.worldgen.ChargedQuartzOreFeature;
import appeng.worldgen.MeteoriteStructure;
import appeng.worldgen.meteorite.MeteoriteStructure;
final class Registration {
@@ -18,30 +18,65 @@
package appeng.debug;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.play.server.SChunkDataPacket;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.MutableBoundingBox;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.server.ServerWorld;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
import appeng.worldgen.MeteoritePlacer;
import appeng.worldgen.MeteoriteSpawner;
import appeng.worldgen.PlacedMeteoriteSettings;
import appeng.worldgen.meteorite.CraterType;
import appeng.worldgen.meteorite.MeteoritePlacer;
import appeng.worldgen.meteorite.MeteoriteSpawner;
import appeng.worldgen.meteorite.PlacedMeteoriteSettings;
public class MeteoritePlacerItem extends AEBaseItem {
private static final String MODE_TAG = "mode";
public MeteoritePlacerItem(Properties properties) {
super(properties);
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
if (world.isRemote()) {
return ActionResult.resultPass(player.getHeldItem(hand));
}
if (player.isSneaking()) {
final ItemStack itemStack = player.getHeldItem(hand);
final CompoundNBT tag = itemStack.getOrCreateTag();
if (tag.contains(MODE_TAG)) {
final byte mode = tag.getByte("mode");
tag.putByte(MODE_TAG, (byte) ((mode + 1) % CraterType.values().length));
} else {
tag.putByte(MODE_TAG, (byte) CraterType.NORMAL.ordinal());
}
CraterType craterType = CraterType.values()[tag.getByte(MODE_TAG)];
player.sendMessage(new StringTextComponent(craterType.name()));
return ActionResult.resultSuccess(itemStack);
}
return super.onItemRightClick(world, player, hand);
}
@Override
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
if (context.getWorld().isRemote()) {
@@ -56,23 +91,28 @@ public class MeteoritePlacerItem extends AEBaseItem {
return ActionResultType.PASS;
}
CompoundNBT tag = stack.getOrCreateTag();
if (!tag.contains(MODE_TAG)) {
tag.putByte(MODE_TAG, (byte) CraterType.NORMAL.ordinal());
}
// See MeteoriteStructure for original code
float coreRadius = (Platform.getRandomFloat() * 6.0f) + 2;
boolean lava = Platform.getRandomFloat() > 0.9f;
boolean pureCrater = Platform.getRandomFloat() > 0.5f;
CraterType craterType = CraterType.values()[tag.getByte(MODE_TAG)];
MeteoriteSpawner spawner = new MeteoriteSpawner();
PlacedMeteoriteSettings spawned = spawner.trySpawnMeteoriteAtSuitableHeight(world, pos, coreRadius, lava);
PlacedMeteoriteSettings spawned = spawner.trySpawnMeteoriteAtSuitableHeight(world, pos, coreRadius, craterType,
pureCrater, false);
if (spawned == null) {
player.sendMessage(new StringTextComponent("Un-suitable Location."));
return ActionResultType.FAIL;
}
player.sendMessage(new StringTextComponent("Spawned at y=" + spawned.getPos().getY()));
// Since we don't know yet if the meteorite will be underground or not,
// we have to assume maximum size
int range = (int) Math.ceil((coreRadius * 2 + 5) * 1.25f);
int range = (int) Math.ceil((coreRadius * 2 + 5) * 5f);
MutableBoundingBox boundingBox = new MutableBoundingBox(pos.getX() - range, pos.getY(), pos.getZ() - range,
pos.getX() + range, pos.getY(), pos.getZ() + range);
@@ -80,6 +120,9 @@ public class MeteoritePlacerItem extends AEBaseItem {
final MeteoritePlacer placer = new MeteoritePlacer(world, spawned, boundingBox);
placer.place();
player.sendMessage(new StringTextComponent("Spawned at y=" + spawned.getPos().getY() + " range=" + range
+ " biomeCategory=" + world.getBiome(pos).getCategory()));
// The placer will not send chunks to the player since it's used as part
// of world-gen normally, so we'll have to do it ourselves. Since this
// is a debug tool, we'll not care about being terribly efficient here
@@ -41,10 +41,11 @@ import net.minecraft.world.gen.feature.structure.StructureStart;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.fml.server.ServerLifecycleHooks;
import appeng.core.AELog;
import appeng.server.ISubCommand;
import appeng.worldgen.MeteoriteStructure;
import appeng.worldgen.MeteoriteStructurePiece;
import appeng.worldgen.PlacedMeteoriteSettings;
import appeng.worldgen.meteorite.MeteoriteStructure;
import appeng.worldgen.meteorite.MeteoriteStructurePiece;
import appeng.worldgen.meteorite.PlacedMeteoriteSettings;
/**
* This is a testing command to validate quartz ore generation.
@@ -132,6 +133,9 @@ public class TestMeteoritesCommand implements ISubCommand {
stats.populationStandardDeviation());
int closestCount = Math.min(5, found.size());
found.forEach(entry -> {
AELog.info(entry.toString());
});
for (int i = 0; i < closestCount; i++) {
PlacedMeteoriteSettings settings = found.get(i);
BlockPos pos = settings.getPos();
@@ -154,8 +158,8 @@ public class TestMeteoritesCommand implements ISubCommand {
settings.getMeteoriteRadius(), state);
} else {
sendLine(sender, " #%d: pos=%d,%d,%d, radius=%.2f, crater=%s, lava=%s, fallout=%s", i + 1, pos.getX(),
pos.getY(), pos.getZ(), settings.getMeteoriteRadius(), settings.isPlaceCrater(),
settings.isLava(), settings.getFallout().name().toLowerCase());
pos.getY(), pos.getZ(), settings.getMeteoriteRadius(),
settings.getCraterType().name().toLowerCase(), settings.getFallout().name().toLowerCase());
}
}
}
@@ -26,6 +26,7 @@ public class ChargedQuartzOreConfig implements IFeatureConfig {
this.chance = chance;
}
@Override
public <T> Dynamic<T> serialize(DynamicOps<T> ops) {
return new Dynamic<>(ops,
ops.createMap(
@@ -34,6 +34,7 @@ public class ChargedQuartzOreFeature extends Feature<ChargedQuartzOreConfig> {
super(p_i51444_1_);
}
@Override
public boolean place(IWorld worldIn, ChunkGenerator<? extends GenerationSettings> generator, Random rand,
BlockPos pos, ChargedQuartzOreConfig config) {
ChunkPos chunkPos = new ChunkPos(pos);
@@ -1,103 +0,0 @@
package appeng.worldgen;
import java.util.Random;
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.IWorld;
import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.feature.structure.IStructurePieceType;
import net.minecraft.world.gen.feature.structure.StructurePiece;
import net.minecraft.world.gen.feature.template.TemplateManager;
import net.minecraftforge.common.util.Constants;
import appeng.core.worlddata.WorldData;
import appeng.worldgen.meteorite.FalloutMode;
public class MeteoriteStructurePiece extends StructurePiece {
public static final IStructurePieceType TYPE = IStructurePieceType.register(MeteoriteStructurePiece::new,
"AE2MTRT");
private PlacedMeteoriteSettings settings;
protected MeteoriteStructurePiece(BlockPos center, float coreRadius) {
super(TYPE, 0);
this.settings = new PlacedMeteoriteSettings(center, coreRadius, false, false, null);
// Since we don't know yet if the meteorite will be underground or not,
// we have to assume maximum size
int range = (int) Math.ceil((coreRadius * 2 + 5) * 1.25f);
this.boundingBox = new MutableBoundingBox(center.getX() - range, center.getY(), center.getZ() - range,
center.getX() + range, center.getY(), center.getZ() + range);
}
public MeteoriteStructurePiece(TemplateManager templateManager, CompoundNBT tag) {
super(TYPE, tag);
// Mandatory fields
BlockPos center = BlockPos.fromLong(tag.getLong("c"));
float coreRadius = tag.getFloat("r");
boolean placeCrater = false;
boolean lava = false;
FalloutMode fallout = null;
if (tag.contains("f", Constants.NBT.TAG_COMPOUND)) {
placeCrater = tag.getBoolean("pc");
lava = tag.getBoolean("l");
fallout = FalloutMode.values()[tag.getByte("f")];
}
this.settings = new PlacedMeteoriteSettings(center, coreRadius, lava, placeCrater, fallout);
}
public boolean isFinalized() {
return settings.getFallout() != null;
}
public PlacedMeteoriteSettings getSettings() {
return settings;
}
@Override
protected void readAdditional(CompoundNBT tag) {
tag.putFloat("r", settings.getMeteoriteRadius());
tag.putLong("c", settings.getPos().toLong());
if (isFinalized()) {
tag.putBoolean("pc", settings.isPlaceCrater());
tag.putBoolean("l", settings.isLava());
tag.putByte("f", (byte) settings.getFallout().ordinal());
}
}
@Override
public boolean create(IWorld world, ChunkGenerator<?> chunkGeneratorIn, Random rand, MutableBoundingBox bounds,
ChunkPos chunkPos) {
// The parent structure synchronizes on the list of components, so this
// placement should be
// mutually exclusive with any other chunk the structure is placed in. This
// allows us to
// finalize some of the placement parameters now that we have access to an
// actual world object
if (!isFinalized()) {
boolean lava = rand.nextFloat() > 0.9f;
MeteoriteSpawner spawner = new MeteoriteSpawner();
BlockPos center = settings.getPos();
float coreRadius = settings.getMeteoriteRadius();
settings = spawner.trySpawnMeteoriteAtSuitableHeight(world, center, coreRadius, lava);
if (settings == null) {
return false;
}
}
MeteoritePlacer placer = new MeteoritePlacer(world, settings, bounds);
placer.place();
WorldData.instance().compassData().service().updateArea(world, chunkPos); // FIXME: We know the y-range here...
return true;
}
}
@@ -1,66 +0,0 @@
package appeng.worldgen;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.math.BlockPos;
import appeng.worldgen.meteorite.FalloutMode;
public final class PlacedMeteoriteSettings {
private final BlockPos pos;
private final boolean lava;
private final boolean placeCrater;
private final float meteoriteRadius;
private final FalloutMode fallout;
public PlacedMeteoriteSettings(BlockPos pos, float meteoriteRadius, boolean lava, boolean placeCrater,
FalloutMode fallout) {
this.pos = pos;
this.lava = lava;
this.placeCrater = placeCrater;
this.meteoriteRadius = meteoriteRadius;
this.fallout = fallout;
}
public BlockPos getPos() {
return pos;
}
public boolean isLava() {
return lava;
}
public boolean isPlaceCrater() {
return placeCrater;
}
public float getMeteoriteRadius() {
return meteoriteRadius;
}
public FalloutMode getFallout() {
return fallout;
}
public CompoundNBT write(CompoundNBT tag) {
tag.putLong("c", pos.toLong());
tag.putFloat("mr", meteoriteRadius);
tag.putBoolean("l", lava);
tag.putBoolean("cr", placeCrater);
tag.putByte("f", (byte) fallout.ordinal());
return tag;
}
public static PlacedMeteoriteSettings read(CompoundNBT tag) {
BlockPos pos = BlockPos.fromLong(tag.getLong("c"));
float meteoriteRadius = tag.getFloat("mr");
boolean lava = tag.getBoolean("l");
boolean placeCrater = tag.getBoolean("cr");
FalloutMode fallout = FalloutMode.values()[tag.getByte("f")];
return new PlacedMeteoriteSettings(pos, meteoriteRadius, lava, placeCrater, fallout);
}
}
@@ -1,94 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, 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.worldgen.meteorite;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import net.minecraft.world.chunk.IChunk;
import appeng.util.Platform;
public class ChunkOnly extends StandardWorld {
private final IChunk target;
private final int cx;
private final int cz;
public ChunkOnly(final IWorld w, final int cx, final int cz) {
super(w);
this.target = w.getChunk(cx, cz);
this.cx = cx;
this.cz = cz;
}
@Override
public int minX(final int in) {
return Math.max(in, this.cx << 4);
}
@Override
public int minZ(final int in) {
return Math.max(in, this.cz << 4);
}
@Override
public int maxX(final int in) {
return Math.min(in, (this.cx + 1) << 4);
}
@Override
public int maxZ(final int in) {
return Math.min(in, (this.cz + 1) << 4);
}
@Override
public boolean contains(BlockPos pos) {
return this.range(pos);
}
@Override
public Block getBlock(BlockPos pos) {
if (this.range(pos)) {
return this.target.getBlockState(new BlockPos(pos)).getBlock();
}
return Blocks.AIR;
}
@Override
public void setBlock(BlockPos pos, final BlockState blk) {
if (this.range(pos)) {
target.setBlockState(new BlockPos(pos), blk, false);
}
}
@Override
public void setBlock(BlockPos pos, final BlockState state, final int flags) {
if (this.range(pos)) {
this.getWorld().setBlockState(new BlockPos(pos), state, flags & (~2));
}
}
@Override
public boolean range(BlockPos pos) {
return this.cx == (pos.getX() >> 4) && this.cz == (pos.getZ() >> 4);
}
}
@@ -1,6 +1,6 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
* Copyright (c) 2020, 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
@@ -15,37 +15,12 @@
* 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.worldgen.meteorite;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
public interface IMeteoriteWorld {
int minX(int in);
int minZ(int in);
int maxX(int in);
int maxZ(int in);
boolean contains(BlockPos pos);
Block getBlock(BlockPos pos);
boolean canBlockSeeTheSky(BlockPos pos);
TileEntity getTileEntity(BlockPos pos);
IWorld getWorld();
void setBlock(BlockPos pos, final BlockState state, final int flags);
void setBlock(BlockPos pos, BlockState blk);
BlockState getBlockState(BlockPos pos);
}
public class Constants {
public static final String TAG_POS = "c";
public static final String TAG_RADIUS = "r";
public static final String TAG_CRATER = "t";
public static final String TAG_FALLOUT = "f";
public static final String TAG_PURE = "p";
}
@@ -0,0 +1,74 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2020, 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.worldgen.meteorite;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
/**
* IMPORTANT: DO NOT CHANGE THE ORDER. Only append. No removals.
*/
public enum CraterType {
/**
* No crater at all.
*/
NONE(null),
/**
* Just the default. Nothing
*/
NORMAL(Blocks.AIR),
/**
* A crater lake filled with lava.
*/
LAVA(Blocks.LAVA),
/**
* A lava crater lake cooled down to obsidian.
*/
OBSIDIAN(Blocks.OBSIDIAN),
/**
* A crater filled with water by rain
*/
WATER(Blocks.WATER),
/**
* A crater filled with snow by snowing.
*/
SNOW(Blocks.SNOW_BLOCK),
/**
* A frozen water filled crater.
*/
ICE(Blocks.ICE);
private final Block filler;
CraterType(Block filler) {
this.filler = filler;
}
public Block getFiller() {
return filler;
}
}
@@ -1,5 +0,0 @@
package appeng.worldgen.meteorite;
public enum FalloutMode {
SAND, TERRACOTTA, ICE_SNOW, DEFAULT
}
@@ -16,7 +16,7 @@
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.worldgen;
package appeng.worldgen.meteorite;
import java.util.ArrayList;
import java.util.List;
@@ -44,7 +44,11 @@ import appeng.core.AEConfig;
import appeng.core.worlddata.WorldData;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.worldgen.meteorite.*;
import appeng.worldgen.meteorite.fallout.Fallout;
import appeng.worldgen.meteorite.fallout.FalloutCopy;
import appeng.worldgen.meteorite.fallout.FalloutMode;
import appeng.worldgen.meteorite.fallout.FalloutSand;
import appeng.worldgen.meteorite.fallout.FalloutSnow;
public final class MeteoritePlacer {
private static final double PRESSES_SPAWN_CHANCE = 0.7;
@@ -64,7 +68,8 @@ public final class MeteoritePlacer {
private final double squaredMeteoriteSize;
private final double crater;
private final boolean placeCrater;
private final boolean lava;
private final CraterType craterType;
private final boolean pureCrater;
private final MutableBoundingBox boundingBox;
public MeteoritePlacer(IWorld world, PlacedMeteoriteSettings settings, MutableBoundingBox boundingBox) {
@@ -76,8 +81,9 @@ public final class MeteoritePlacer {
this.z = settings.getPos().getZ();
this.meteoriteSize = settings.getMeteoriteRadius();
this.realCrater = this.meteoriteSize * 2 + 5;
this.placeCrater = settings.isPlaceCrater();
this.lava = settings.isLava();
this.placeCrater = settings.shouldPlaceCrater();
this.craterType = settings.getCraterType();
this.pureCrater = settings.isPureCrater();
this.squaredMeteoriteSize = this.meteoriteSize * this.meteoriteSize;
this.crater = this.realCrater * this.realCrater;
@@ -142,12 +148,15 @@ public final class MeteoritePlacer {
private void placeCrater() {
final int maxY = 255;
BlockPos.Mutable blockPos = new BlockPos.Mutable();
BlockState filler = craterType.getFiller().getDefaultState();
for (int j = y - 5; j <= maxY; j++) {
blockPos.setY(j);
for (int i = boundingBox.minX; i <= boundingBox.maxX; i++) {
blockPos.setX(i);
for (int k = boundingBox.minZ; k <= boundingBox.maxZ; k++) {
blockPos.setZ(k);
final double dx = i - x;
@@ -159,13 +168,14 @@ public final class MeteoritePlacer {
if (j > h + distanceFrom * 0.02) {
BlockState currentBlock = world.getBlockState(blockPos);
if (lava && j < y && currentBlock.getMaterial().isSolid()) {
if (craterType != CraterType.NORMAL && j < y && currentBlock.getMaterial().isSolid()) {
if (j > h + distanceFrom * 0.02) {
this.putter.put(world, blockPos, Blocks.LAVA.getDefaultState());
this.putter.put(world, blockPos, filler);
}
} else {
this.putter.put(world, blockPos, Blocks.AIR.getDefaultState());
}
}
}
}
@@ -317,7 +327,8 @@ public final class MeteoritePlacer {
blockPosDown.setY(j - 1);
BlockState state = world.getBlockState(blockPos);
Block blk = world.getBlockState(blockPos).getBlock();
if (blk == Blocks.LAVA) {
if (this.pureCrater && blk == craterType.getFiller()) {
continue;
}
@@ -1,4 +1,4 @@
package appeng.worldgen;
package appeng.worldgen.meteorite;
import java.util.ArrayList;
import java.util.Collection;
@@ -1,4 +1,21 @@
package appeng.worldgen;
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2020, 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.worldgen.meteorite;
import javax.annotation.Nullable;
@@ -11,10 +28,12 @@ import net.minecraft.tags.Tag;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.biome.Biome.Category;
import net.minecraft.world.gen.Heightmap;
import net.minecraft.world.gen.Heightmap.Type;
import appeng.core.AppEng;
import appeng.worldgen.meteorite.FalloutMode;
import appeng.worldgen.meteorite.fallout.FalloutMode;
/**
* Makes decisions about spawning meteorites in the world.
@@ -40,20 +59,27 @@ public class MeteoriteSpawner {
}
public PlacedMeteoriteSettings trySpawnMeteoriteAtSuitableHeight(IWorldReader world, BlockPos startPos,
float coreRadius, boolean lava) {
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);
// Place the center on the first solid ground block, but move it down a little
// to embed the meteorite more
// in the ground
int startY = world.getHeight(Heightmap.Type.WORLD_SURFACE_WG, startPos).getY() - stepSize / 2;
// Place the center on the first solid ground block,
// but move it down a little to embed the meteorite more in the ground
final boolean isOcean = world.getBiome(startPos).getCategory() == Category.OCEAN;
final Type heightmapType;
if (isOcean) {
heightmapType = worldGen ? Heightmap.Type.OCEAN_FLOOR_WG : Heightmap.Type.OCEAN_FLOOR;
} else {
heightmapType = worldGen ? Heightmap.Type.WORLD_SURFACE_WG : Heightmap.Type.WORLD_SURFACE;
}
int startY = world.getHeight(heightmapType, startPos).getY() - stepSize / 2;
mutablePos.setY(startY);
while (mutablePos.getY() > minY) {
PlacedMeteoriteSettings spawned = trySpawnMeteorite(world, mutablePos, coreRadius, lava);
PlacedMeteoriteSettings spawned = trySpawnMeteorite(world, mutablePos, coreRadius, craterType, pureCrater);
if (spawned != null) {
return spawned;
}
@@ -65,7 +91,8 @@ public class MeteoriteSpawner {
}
@Nullable
public PlacedMeteoriteSettings trySpawnMeteorite(IWorldReader world, BlockPos pos, float coreRadius, boolean lava) {
public PlacedMeteoriteSettings trySpawnMeteorite(IWorldReader world, BlockPos pos, float coreRadius,
CraterType craterType, boolean pureCrater) {
if (!areSurroundingsSuitable(world, pos)) {
return null;
}
@@ -76,13 +103,14 @@ public class MeteoriteSpawner {
boolean solid = !isAirBelowSpawnPoint(world, pos);
if (!solid) {
placeCrater = false;
if (!solid || placeCrater) {
// craterType = CraterType.NONE;
// TODO: WHAT
}
FalloutMode fallout = getFalloutFromBaseBlock(world.getBlockState(pos));
return new PlacedMeteoriteSettings(pos, coreRadius, lava, placeCrater, fallout);
return new PlacedMeteoriteSettings(pos, coreRadius, craterType, fallout, pureCrater);
}
private static boolean isAirBelowSpawnPoint(IWorldReader w, BlockPos pos) {
@@ -1,4 +1,4 @@
package appeng.worldgen;
package appeng.worldgen.meteorite;
import java.util.Random;
import java.util.function.Function;
@@ -0,0 +1,218 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2020, 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.worldgen.meteorite;
import java.util.Random;
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.IWorld;
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.ChunkGenerator;
import net.minecraft.world.gen.feature.structure.IStructurePieceType;
import net.minecraft.world.gen.feature.structure.StructurePiece;
import net.minecraft.world.gen.feature.template.TemplateManager;
import appeng.core.worlddata.WorldData;
import appeng.worldgen.meteorite.fallout.FalloutMode;
public class MeteoriteStructurePiece extends StructurePiece {
public static final IStructurePieceType TYPE = IStructurePieceType.register(MeteoriteStructurePiece::new,
"AE2MTRT");
private PlacedMeteoriteSettings settings;
protected MeteoriteStructurePiece(BlockPos center, float coreRadius) {
super(TYPE, 0);
this.settings = new PlacedMeteoriteSettings(center, coreRadius, null, null, false);
// Since we don't know yet if the meteorite will be underground or not,
// we have to assume maximum size
int range = (int) Math.ceil((coreRadius * 2 + 5) * 1.25f);
this.boundingBox = new MutableBoundingBox(center.getX() - range, center.getY(), center.getZ() - range,
center.getX() + range, center.getY(), center.getZ() + range);
}
public MeteoriteStructurePiece(TemplateManager templateManager, CompoundNBT tag) {
super(TYPE, tag);
// Mandatory fields
BlockPos center = BlockPos.fromLong(tag.getLong(Constants.TAG_POS));
float coreRadius = tag.getFloat(Constants.TAG_RADIUS);
CraterType craterType = null;
FalloutMode fallout = null;
boolean pureCrater = false;
if (tag.contains(Constants.TAG_CRATER)) {
craterType = CraterType.values()[tag.getByte(Constants.TAG_CRATER)];
fallout = FalloutMode.values()[tag.getByte(Constants.TAG_FALLOUT)];
pureCrater = tag.getBoolean(Constants.TAG_PURE);
}
this.settings = new PlacedMeteoriteSettings(center, coreRadius, craterType, fallout, pureCrater);
}
public boolean isFinalized() {
return settings.getCraterType() != null;
}
public PlacedMeteoriteSettings getSettings() {
return settings;
}
@Override
protected void readAdditional(CompoundNBT tag) {
tag.putFloat(Constants.TAG_RADIUS, settings.getMeteoriteRadius());
tag.putLong(Constants.TAG_POS, settings.getPos().toLong());
if (isFinalized()) {
tag.putByte(Constants.TAG_CRATER, (byte) settings.getCraterType().ordinal());
tag.putByte(Constants.TAG_FALLOUT, (byte) settings.getFallout().ordinal());
}
}
@Override
public boolean create(IWorld world, ChunkGenerator<?> chunkGeneratorIn, Random rand, MutableBoundingBox bounds,
ChunkPos chunkPos) {
// The parent structure synchronizes on the list of components, so this
// placement should be
// mutually exclusive with any other chunk the structure is placed in. This
// allows us to
// finalize some of the placement parameters now that we have access to an
// actual world object
if (!isFinalized()) {
MeteoriteSpawner spawner = new MeteoriteSpawner();
BlockPos center = settings.getPos();
float coreRadius = settings.getMeteoriteRadius();
CraterType craterType = determineCraterType(world, center, rand);
boolean pureCrater = rand.nextFloat() > .5f;
settings = spawner.trySpawnMeteoriteAtSuitableHeight(world, center, coreRadius, craterType, pureCrater,
true);
if (settings == null) {
return false;
}
}
MeteoritePlacer placer = new MeteoritePlacer(world, settings, bounds);
placer.place();
WorldData.instance().compassData().service().updateArea(world, chunkPos); // FIXME: We know the y-range here...
return true;
}
private CraterType determineCraterType(IWorld world, BlockPos center, Random rand) {
final Biome biome = world.getBiome(center);
final TempCategory temp = biome.getTempCategory();
final Category category = biome.getCategory();
// No craters in oceans
if (category == Category.OCEAN) {
return CraterType.NONE;
}
// 50% chance for a special meteor
final boolean specialMeteor = rand.nextFloat() > .5f;
// Just a normal one
if (!specialMeteor) {
return CraterType.NORMAL;
}
// Warm biomes, higher chance for lava
if (temp == TempCategory.WARM) {
// 50% chance to actually spawn as lava
final boolean lava = rand.nextFloat() > .5f;
switch (biome.getPrecipitation()) {
// No rainfall, only lava
case NONE:
return lava ? CraterType.LAVA : CraterType.NORMAL;
// 25% chance to convert a lava to obsidian
case RAIN:
final boolean obsidian = rand.nextFloat() > .75f;
final CraterType alternativObsidian = obsidian ? CraterType.OBSIDIAN : CraterType.LAVA;
return lava ? alternativObsidian : CraterType.NORMAL;
// Nothing for now.
default:
break;
}
}
// Temperate biomes. Water or maybe lava
if (temp == TempCategory.MEDIUM) {
// 75% chance to actually spawn with a crater lake
final boolean lake = rand.nextFloat() > .25f;
// 20% to spawn with lava
final boolean lava = rand.nextFloat() > .8f;
switch (biome.getPrecipitation()) {
// No rainfall, water how?
case NONE:
return lava ? CraterType.LAVA : CraterType.NORMAL;
// Rainfall, can also turn lava to obsidian
case RAIN:
final boolean obsidian = rand.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 CraterType water = lake ? CraterType.WATER : CraterType.NORMAL;
return snow ? CraterType.SNOW : water;
}
}
// Cold biomes, Snow or Ice, maybe water and very rarely lava.
if (temp == TempCategory.COLD) {
// 75% chance to actually spawn with a crater lake
final boolean lake = rand.nextFloat() > .25f;
// 5% to spawn with lava
final boolean lava = rand.nextFloat() > .95f;
// 75% chance to freeze
final boolean frozen = rand.nextFloat() > .25f;
switch (biome.getPrecipitation()) {
// No rainfall, water how?
case NONE:
return lava ? CraterType.LAVA : CraterType.NORMAL;
case RAIN:
final CraterType frozenLake = frozen ? CraterType.ICE : CraterType.WATER;
final CraterType craterLake = lake ? frozenLake : CraterType.NORMAL;
return lava ? CraterType.LAVA : craterLake;
case SNOW:
final CraterType snowCovered = lake ? CraterType.SNOW : CraterType.NORMAL;
return lava ? CraterType.LAVA : snowCovered;
}
}
return CraterType.NORMAL;
}
}
@@ -0,0 +1,93 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2020, 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.worldgen.meteorite;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.math.BlockPos;
import appeng.worldgen.meteorite.fallout.FalloutMode;
public final class PlacedMeteoriteSettings {
private final BlockPos pos;
private final float meteoriteRadius;
private final CraterType craterType;
private final FalloutMode fallout;
private final boolean pureCrater;
public PlacedMeteoriteSettings(BlockPos pos, float meteoriteRadius, CraterType craterType, FalloutMode fallout,
boolean pureCrater) {
this.pos = pos;
this.craterType = craterType;
this.meteoriteRadius = meteoriteRadius;
this.fallout = fallout;
this.pureCrater = pureCrater;
}
public BlockPos getPos() {
return pos;
}
public CraterType getCraterType() {
return this.craterType;
}
public float getMeteoriteRadius() {
return meteoriteRadius;
}
public FalloutMode getFallout() {
return fallout;
}
public boolean shouldPlaceCrater() {
return this.craterType != CraterType.NONE;
}
public boolean isPureCrater() {
return this.pureCrater;
}
public CompoundNBT write(CompoundNBT tag) {
tag.putLong(Constants.TAG_POS, pos.toLong());
tag.putFloat(Constants.TAG_RADIUS, meteoriteRadius);
tag.putByte(Constants.TAG_CRATER, (byte) craterType.ordinal());
tag.putByte(Constants.TAG_FALLOUT, (byte) fallout.ordinal());
tag.putBoolean(Constants.TAG_PURE, this.pureCrater);
return tag;
}
public static PlacedMeteoriteSettings read(CompoundNBT tag) {
BlockPos pos = BlockPos.fromLong(tag.getLong(Constants.TAG_POS));
float meteoriteRadius = tag.getFloat(Constants.TAG_RADIUS);
CraterType craterType = CraterType.values()[tag.getByte(Constants.TAG_CRATER)];
FalloutMode fallout = FalloutMode.values()[tag.getByte(Constants.TAG_FALLOUT)];
boolean pureCrater = tag.getBoolean(Constants.TAG_PURE);
return new PlacedMeteoriteSettings(pos, meteoriteRadius, craterType, fallout, pureCrater);
}
@Override
public String toString() {
return "PlacedMeteoriteSettings [pos=" + pos + ", meteoriteRadius=" + meteoriteRadius + ", craterType="
+ craterType + ", fallout=" + fallout + ", pureCrater=" + pureCrater + "]";
}
}
@@ -1,118 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, 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.worldgen.meteorite;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import appeng.util.Platform;
public class StandardWorld implements IMeteoriteWorld {
private final IWorld w;
public StandardWorld(final IWorld w) {
this.w = w;
}
@Override
public int minX(final int in) {
return in;
}
@Override
public int minZ(final int in) {
return in;
}
@Override
public int maxX(final int in) {
return in;
}
@Override
public int maxZ(final int in) {
return in;
}
@Override
public boolean contains(BlockPos pos) {
return true;
}
@Override
public Block getBlock(BlockPos pos) {
if (this.range(pos)) {
return this.getWorld().getBlockState(new BlockPos(pos)).getBlock();
}
return Blocks.AIR;
}
@Override
public boolean canBlockSeeTheSky(BlockPos pos) {
if (this.range(pos)) {
return this.getWorld().canBlockSeeSky(new BlockPos(pos));
}
return false;
}
@Override
public TileEntity getTileEntity(BlockPos pos) {
if (this.range(pos)) {
return this.getWorld().getTileEntity(new BlockPos(pos));
}
return null;
}
@Override
public IWorld getWorld() {
return this.w;
}
@Override
public void setBlock(BlockPos pos, final BlockState blk) {
if (this.range(pos)) {
// FIXME: Attempt at reducing impact of placing meteors by passing 16|32 here
this.getWorld().setBlockState(new BlockPos(pos), blk, 16 | 32);
}
}
public boolean range(BlockPos pos) {
return true;
}
@Override
public void setBlock(BlockPos pos, final BlockState state, final int l) {
if (this.range(pos)) {
this.w.setBlockState(new BlockPos(pos), state, l);
}
}
@Override
public BlockState getBlockState(BlockPos pos) {
if (this.range(pos)) {
return this.w.getBlockState(new BlockPos(pos));
}
return Blocks.AIR.getDefaultState();
}
}
@@ -16,7 +16,7 @@
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.worldgen.meteorite;
package appeng.worldgen.meteorite.fallout;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
@@ -24,6 +24,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import appeng.util.Platform;
import appeng.worldgen.meteorite.MeteoriteBlockPutter;
public class Fallout {
private final MeteoriteBlockPutter putter;
@@ -16,13 +16,15 @@
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.worldgen.meteorite;
package appeng.worldgen.meteorite.fallout;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import appeng.worldgen.meteorite.MeteoriteBlockPutter;
public class FalloutCopy extends Fallout {
private static final double SPECIFIED_BLOCK_THRESHOLD = 0.9;
private static final double AIR_BLOCK_THRESHOLD = 0.8;
@@ -0,0 +1,29 @@
package appeng.worldgen.meteorite.fallout;
public enum FalloutMode {
/**
* No fallout, e.g. when without a crater.
*/
NONE,
/**
* Default
*/
DEFAULT,
/**
* For sandy terrain
*/
SAND,
/**
* For terracotta (mesa)
*/
TERRACOTTA,
/**
* Icy/snowy terrain
*/
ICE_SNOW;
}
@@ -16,13 +16,15 @@
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.worldgen.meteorite;
package appeng.worldgen.meteorite.fallout;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import appeng.worldgen.meteorite.MeteoriteBlockPutter;
public class FalloutSand extends FalloutCopy {
private static final double GLASS_THRESHOLD = 0.66;
private final MeteoriteBlockPutter putter;
@@ -16,13 +16,15 @@
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.worldgen.meteorite;
package appeng.worldgen.meteorite.fallout;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import appeng.worldgen.meteorite.MeteoriteBlockPutter;
public class FalloutSnow extends FalloutCopy {
private static final double SNOW_THRESHOLD = 0.7;
private static final double ICE_THRESHOLD = 0.5;