Moving to source sets

This commit is contained in:
Sebastian Hartte
2020-07-01 23:36:51 +02:00
parent f2e3d81fd7
commit 2642ced86b
2924 changed files with 794 additions and 796 deletions
@@ -1,45 +0,0 @@
package appeng.worldgen;
import com.google.common.collect.ImmutableMap;
import com.mojang.datafixers.Dynamic;
import com.mojang.datafixers.types.DynamicOps;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.world.gen.feature.IFeatureConfig;
import net.minecraft.world.gen.feature.ReplaceBlockConfig;
import appeng.core.AEConfig;
/**
* Extends a {@link ReplaceBlockConfig} with a chance.
*/
public class ChargedQuartzOreConfig implements IFeatureConfig {
public final BlockState target;
public final BlockState state;
public final float chance;
public ChargedQuartzOreConfig(BlockState target, BlockState state, float chance) {
this.target = target;
this.state = state;
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,61 +0,0 @@
package appeng.worldgen;
import java.util.Random;
import java.util.function.Function;
import com.mojang.datafixers.Dynamic;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.GenerationSettings;
import net.minecraft.world.gen.Heightmap;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.ReplaceBlockFeature;
import appeng.core.AppEng;
/**
* Extends {@link ReplaceBlockFeature} 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);
static {
INSTANCE.setRegistryName(AppEng.MOD_ID, "charged_quartz_ore");
}
public ChargedQuartzOreFeature(Function<Dynamic<?>, ? extends ChargedQuartzOreConfig> p_i51444_1_) {
super(p_i51444_1_);
}
@Override
public boolean place(WorldAccess worldIn, ChunkGenerator<? extends GenerationSettings> generator, Random rand,
BlockPos pos, ChargedQuartzOreConfig config) {
ChunkPos chunkPos = new ChunkPos(pos);
BlockPos.Mutable bpos = new BlockPos.Mutable();
int height = worldIn.getHeight(Heightmap.Type.WORLD_SURFACE_WG, pos.getX(), pos.getZ());
Chunk chunk = worldIn.getChunk(pos);
for (int y = 0; y < height; y++) {
bpos.setY(y);
for (int x = chunkPos.getXStart(); x <= chunkPos.getXEnd(); x++) {
bpos.setX(x);
for (int z = chunkPos.getZStart(); z <= chunkPos.getZEnd(); z++) {
bpos.setZ(z);
if (chunk.getBlockState(bpos).getBlock() == config.target.getBlock()
&& rand.nextFloat() < config.chance) {
chunk.setBlockState(bpos, config.state, false);
}
}
}
}
return true;
}
}
@@ -1,27 +0,0 @@
/*
* 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;
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";
public static final String TAG_LAKE = "l";
}
@@ -1,74 +0,0 @@
/*
* 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,38 +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.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldAccess;
public class MeteoriteBlockPutter {
public boolean put(final WorldAccess w, BlockPos pos, final BlockState blk) {
final BlockState original = w.getBlockState(pos);
if (original.getBlock() == Blocks.BEDROCK || original == blk) {
return false;
}
w.setBlockState(pos, blk, 0);
return true;
}
}
@@ -1,430 +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 java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.ItemEntity;
import net.minecraft.item.Item;
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.world.WorldAccess;
import appeng.api.AEApi;
import appeng.api.definitions.IBlockDefinition;
import appeng.api.definitions.IBlocks;
import appeng.api.definitions.IMaterials;
import appeng.api.features.AEFeature;
import appeng.core.AEConfig;
import appeng.core.worlddata.WorldData;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
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;
private static final int SKYSTONE_SPAWN_LIMIT = 12;
private final IBlockDefinition skyChestDefinition;
private final BlockState skyStone;
private final Item skyStoneItem;
private final MeteoriteBlockPutter putter = new MeteoriteBlockPutter();
private final WorldAccess world;
private final Fallout type;
private final BlockPos pos;
private final int x;
private final int y;
private final int z;
private final double meteoriteSize;
private final double realCrater;
private final double squaredMeteoriteSize;
private final double crater;
private final boolean placeCrater;
private final CraterType craterType;
private final boolean pureCrater;
private final boolean craterLake;
private final MutableBoundingBox boundingBox;
public MeteoritePlacer(WorldAccess world, PlacedMeteoriteSettings settings, MutableBoundingBox boundingBox) {
this.boundingBox = boundingBox;
this.world = world;
this.pos = settings.getPos();
this.x = settings.getPos().getX();
this.y = settings.getPos().getY();
this.z = settings.getPos().getZ();
this.meteoriteSize = settings.getMeteoriteRadius();
this.realCrater = this.meteoriteSize * 2 + 5;
this.placeCrater = settings.shouldPlaceCrater();
this.craterType = settings.getCraterType();
this.pureCrater = settings.isPureCrater();
this.craterLake = settings.isCraterLake();
this.squaredMeteoriteSize = this.meteoriteSize * this.meteoriteSize;
this.crater = this.realCrater * this.realCrater;
final IBlocks blocks = AEApi.instance().definitions().blocks();
this.skyChestDefinition = blocks.skyStoneChest();
this.skyStone = blocks.skyStoneBlock().block().getDefaultState();
this.skyStoneItem = blocks.skyStoneBlock().item();
this.type = getFallout(world, settings.getPos(), settings.getFallout());
}
public void place() {
// creator
if (placeCrater) {
this.placeCrater();
}
this.placeMeteorite();
// collapse blocks...
if (placeCrater) {
this.decay();
}
if (craterLake) {
this.placeCraterLake();
}
}
private int minX(int x) {
if (x < boundingBox.minX) {
return boundingBox.minX;
} else if (x > boundingBox.maxX) {
return boundingBox.maxX;
}
return x;
}
private int minZ(int x) {
if (x < boundingBox.minZ) {
return boundingBox.minZ;
} else if (x > boundingBox.maxZ) {
return boundingBox.maxZ;
}
return x;
}
private int maxX(int x) {
if (x < boundingBox.minX) {
return boundingBox.minX;
} else if (x > boundingBox.maxX) {
return boundingBox.maxX;
}
return x;
}
private int maxZ(int x) {
if (x < boundingBox.minZ) {
return boundingBox.minZ;
} else if (x > boundingBox.maxZ) {
return boundingBox.maxZ;
}
return x;
}
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;
final double dz = k - z;
final double h = y - this.meteoriteSize + 1 + this.type.adjustCrater();
final double distanceFrom = dx * dx + dz * dz;
if (j > h + distanceFrom * 0.02) {
BlockState currentBlock = world.getBlockState(blockPos);
if (craterType != CraterType.NORMAL && j < y && currentBlock.getMaterial().isSolid()) {
if (j > h + distanceFrom * 0.02) {
this.putter.put(world, blockPos, filler);
}
} else {
this.putter.put(world, blockPos, Blocks.AIR.getDefaultState());
}
}
}
}
}
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)))) {
final Entity e = (Entity) o;
e.remove();
}
}
private void placeMeteorite() {
// spawn meteor
this.placeMeteoriteSkyStone();
placeChest();
}
private void placeChest() {
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);
if (ap != null && !ap.containsItems()) // FIXME: band-aid for meteorites being generated multiple times
{
// TODO: loot tables would be better
int primary = Math.max(1, (int) (Math.random() * 4));
if (primary > 3) // in case math breaks...
{
primary = 3;
}
for (int zz = 0; zz < primary; zz++) {
int r;
boolean duplicate;
do {
duplicate = false;
if (Math.random() > PRESSES_SPAWN_CHANCE) {
r = WorldData.instance().storageData().getNextOrderedValue("presses", 0);
} else {
r = (int) (Math.random() * 1000);
}
ItemStack toAdd = ItemStack.EMPTY;
final IMaterials materials = AEApi.instance().definitions().materials();
switch (r % 4) {
case 0:
toAdd = materials.calcProcessorPress().maybeStack(1).orElse(ItemStack.EMPTY);
break;
case 1:
toAdd = materials.engProcessorPress().maybeStack(1).orElse(ItemStack.EMPTY);
break;
case 2:
toAdd = materials.logicProcessorPress().maybeStack(1).orElse(ItemStack.EMPTY);
break;
case 3:
toAdd = materials.siliconPress().maybeStack(1).orElse(ItemStack.EMPTY);
break;
default:
}
if (!toAdd.isEmpty()) {
if (ap.simulateRemove(1, toAdd, null).isEmpty()) {
ap.addItems(toAdd);
} else {
duplicate = true;
}
}
} while (duplicate);
}
final int secondary = Math.max(1, (int) (Math.random() * 3));
for (int zz = 0; zz < secondary; zz++) {
switch ((int) (Math.random() * 1000) % 3) {
case 0:
final int amount = (int) ((Math.random() * SKYSTONE_SPAWN_LIMIT) + 1);
ap.addItems(new ItemStack(skyStoneItem, amount));
break;
case 1:
final List<ItemStack> possibles = new ArrayList<>();
possibles.add(new ItemStack(net.minecraft.item.Items.GOLD_NUGGET));
ItemStack nugget = Platform.pickRandom(possibles);
if (nugget != null && !nugget.isEmpty()) {
nugget = nugget.copy();
nugget.setCount((int) (Math.random() * 12) + 1);
ap.addItems(nugget);
}
break;
}
}
}
}
}
private void placeMeteoriteSkyStone() {
final int meteorXLength = minX(x - 8);
final int meteorXHeight = maxX(x + 8);
final int meteorZLength = minZ(z - 8);
final int meteorZHeight = maxZ(z + 8);
BlockPos.Mutable pos = new BlockPos.Mutable();
for (int i = meteorXLength; i <= meteorXHeight; i++) {
pos.setX(i);
for (int j = y - 8; j < y + 8; j++) {
pos.setY(j);
for (int k = meteorZLength; k <= meteorZHeight; k++) {
pos.setZ(k);
final double dx = i - x;
final double dy = j - y;
final double dz = k - z;
if (dx * dx * 0.7 + dy * dy * (j > y ? 1.4 : 0.8) + dz * dz * 0.7 < this.squaredMeteoriteSize) {
this.putter.put(world, pos, skyStone);
}
}
}
}
}
private void decay() {
double randomShit = 0;
final int meteorXLength = minX(x - 30);
final int meteorXHeight = maxX(x + 30);
final int meteorZLength = minZ(z - 30);
final int meteorZHeight = maxZ(z + 30);
BlockPos.Mutable blockPos = new BlockPos.Mutable();
BlockPos.Mutable blockPosUp = new BlockPos.Mutable();
BlockPos.Mutable blockPosDown = new BlockPos.Mutable();
for (int i = meteorXLength; i <= meteorXHeight; i++) {
blockPos.setX(i);
blockPosUp.setX(i);
blockPosDown.setX(i);
for (int k = meteorZLength; k <= meteorZHeight; k++) {
blockPos.setZ(k);
blockPosUp.setZ(k);
blockPosDown.setZ(k);
for (int j = y - 9; j < y + 30; j++) {
blockPos.setY(j);
blockPosUp.setY(j + 1);
blockPosDown.setY(j - 1);
BlockState state = world.getBlockState(blockPos);
Block blk = world.getBlockState(blockPos).getBlock();
if (this.pureCrater && blk == craterType.getFiller()) {
continue;
}
// TODO reconsider
if (state.getMaterial().isReplaceable()) {
if (!world.isAir(blockPosUp)) {
final BlockState stateUp = world.getBlockState(blockPosUp);
world.setBlockState(blockPos, stateUp, 3);
} else if (randomShit < 100 * this.crater) {
final double dx = i - x;
final double dy = j - y;
final double dz = k - z;
final double dist = dx * dx + dy * dy + dz * dz;
final BlockState xf = world.getBlockState(blockPosDown);
if (!xf.getMaterial().isReplaceable()) {
final double extraRange = Math.random() * 0.6;
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) {
randomShit++;
this.type.getRandomFall(world, blockPos);
}
}
}
} else {
// decay.
if (world.isAir(blockPosUp)) {
if (Math.random() > 0.4) {
final double dx = i - x;
final double dy = j - y;
final double dz = k - z;
if (dx * dx + dy * dy + dz * dz < this.crater * 1.6) {
this.type.getRandomInset(world, blockPos);
}
}
}
}
}
}
}
}
/**
* If it finds a single water block at y62, it will replace any air blocks below
* the sea level with water.
*/
private void placeCraterLake() {
final int maxY = world.getSeaLevel() - 1;
BlockPos.Mutable blockPos = new BlockPos.Mutable();
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;
final double dz = k - z;
final double h = y - this.meteoriteSize + 1 + this.type.adjustCrater();
final double distanceFrom = dx * dx + dz * dz;
if (j > h + distanceFrom * 0.02) {
BlockState currentBlock = world.getBlockState(blockPos);
if (currentBlock.getBlock() == Blocks.AIR) {
this.putter.put(world, blockPos, Blocks.WATER.getDefaultState());
}
}
}
}
}
}
private Fallout getFallout(WorldAccess w, BlockPos pos, FalloutMode mode) {
switch (mode) {
case SAND:
return new FalloutSand(w, pos, this.putter, this.skyStone);
case TERRACOTTA:
return new FalloutCopy(w, pos, this.putter, this.skyStone);
case ICE_SNOW:
return new FalloutSnow(w, pos, this.putter, this.skyStone);
case DEFAULT:
default:
return new Fallout(this.putter, this.skyStone);
}
}
}
@@ -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.INBT;
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;
INBT 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,74 +0,0 @@
package appeng.worldgen.meteorite;
import java.util.Random;
import java.util.function.Function;
import com.mojang.datafixers.Dynamic;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeManager;
import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.EndChunkGenerator;
import net.minecraft.world.gen.NetherChunkGenerator;
import net.minecraft.world.gen.feature.NoFeatureConfig;
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 ScatteredStructure<NoFeatureConfig> {
public static final Structure<NoFeatureConfig> INSTANCE = new MeteoriteStructure(NoFeatureConfig::deserialize);
static {
INSTANCE.setRegistryName(AppEng.MOD_ID, "meteorite");
}
public MeteoriteStructure(Function<Dynamic<?>, ? extends NoFeatureConfig> 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 Structure.IStartFactory getStartFactory() {
return MeteoriteStructureStart::new;
}
@Override
protected int getSeedModifier() {
return 124895654;
}
}
@@ -1,96 +0,0 @@
/*
* 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.CompoundTag;
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.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, CraterType craterType, FalloutMode fallout,
boolean pureCrater, boolean craterLake) {
super(TYPE, 0);
this.settings = new PlacedMeteoriteSettings(center, coreRadius, craterType, fallout, pureCrater, craterLake);
// Assume a normal max height of 128 blocks for most biomes,
// meteors spawned at about y64 are 9x9 chunks large at most.
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);
}
public MeteoriteStructurePiece(TemplateManager templateManager, CompoundTag tag) {
super(TYPE, tag);
BlockPos center = BlockPos.fromLong(tag.getLong(Constants.TAG_POS));
float coreRadius = 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);
boolean craterLake = tag.getBoolean(Constants.TAG_LAKE);
this.settings = new PlacedMeteoriteSettings(center, coreRadius, craterType, fallout, pureCrater, craterLake);
}
public boolean isFinalized() {
return settings.getCraterType() != null;
}
public PlacedMeteoriteSettings getSettings() {
return settings;
}
@Override
protected void readAdditional(CompoundTag tag) {
tag.putFloat(Constants.TAG_RADIUS, settings.getMeteoriteRadius());
tag.putLong(Constants.TAG_POS, settings.getPos().toLong());
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());
tag.putBoolean(Constants.TAG_LAKE, settings.isCraterLake());
}
@Override
public boolean create(WorldAccess world, ChunkGenerator<?> chunkGeneratorIn, Random rand, MutableBoundingBox bounds,
ChunkPos chunkPos) {
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;
}
}
@@ -1,227 +0,0 @@
package appeng.worldgen.meteorite;
import java.util.Set;
import com.google.common.math.StatsAccumulator;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
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.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.Heightmap;
import net.minecraft.world.gen.Heightmap.Type;
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 {
private final Tag<Block> sandTag = BlockTags.getContainer().getOrCreate(new Identifier("minecraft:sand"));
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 void init(ChunkGenerator<?> generator, TemplateManager templateManagerIn, int chunkX, int chunkZ,
Biome biome) {
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 yOffset = (int) Math.ceil(meteoriteRadius) + 1;
final Set<Biome> t2 = generator.getBiomeProvider().getBiomes(centerX, 0, centerZ, 0);
final Biome spawnBiome = t2.stream().findFirst().orElse(biome);
final boolean isOcean = spawnBiome.getCategory() == Category.OCEAN;
final Type heightmapType = isOcean ? Heightmap.Type.OCEAN_FLOOR_WG : Heightmap.Type.WORLD_SURFACE_WG;
// Accumulate stats about the surrounding heightmap
StatsAccumulator stats = new StatsAccumulator();
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.func_222529_a(centerX + x, centerZ + z, heightmapType);
stats.add(h);
}
}
int centerY = (int) stats.mean();
// Spawn it down a bit further with a high variance.
if (stats.populationVariance() > 5) {
centerY -= (stats.mean() - stats.min()) * .75;
}
// Offset caused by the meteorsize
centerY -= yOffset;
// Limit to not spawn below y32
centerY = Math.max(32, centerY);
BlockPos actualPos = new BlockPos(centerX, centerY, centerZ);
boolean craterLake = this.locateWaterAroundTheCrater(generator, actualPos, meteoriteRadius);
CraterType craterType = this.determineCraterType(spawnBiome);
boolean pureCrater = this.rand.nextFloat() > .9f;
FalloutMode fallout = getFalloutFromBaseBlock(spawnBiome.getSurfaceBuilderConfig().getTop());
components.add(
new MeteoriteStructurePiece(actualPos, meteoriteRadius, craterType, fallout, pureCrater, craterLake));
this.recalculateStructureSize();
}
/**
* Scan for water about 1 block further than the crater radius 333 1174
*
* @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 maxY = seaLevel - 1;
BlockPos.Mutable blockPos = new BlockPos.Mutable();
blockPos.setY(maxY);
for (int i = pos.getX() - 32; i <= pos.getX() + 32; i++) {
blockPos.setX(i);
for (int k = pos.getZ() - 32; k <= pos.getZ() + 32; k++) {
blockPos.setZ(k);
final double dx = i - pos.getX();
final double dz = k - pos.getZ();
final double h = pos.getY() - radius + 1;
final double distanceFrom = dx * dx + dz * dz;
if (maxY > h + distanceFrom * 0.0175 && maxY < h + distanceFrom * 0.02) {
int heigth = generator.func_222529_a(blockPos.getX(), blockPos.getZ(), Heightmap.Type.OCEAN_FLOOR);
if (heigth < seaLevel) {
return true;
}
}
}
}
return false;
}
private CraterType determineCraterType(Biome biome) {
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;
}
private FalloutMode getFalloutFromBaseBlock(BlockState blockState) {
final Block block = blockState.getBlock();
if (block.isIn(sandTag)) {
return FalloutMode.SAND;
} else if (block.isIn(terracottaTag)) {
return FalloutMode.TERRACOTTA;
} else if (block == Blocks.SNOW || block == Blocks.SNOW || block == Blocks.SNOW_BLOCK || block == Blocks.ICE
|| block == Blocks.PACKED_ICE) {
return FalloutMode.ICE_SNOW;
} else {
return FalloutMode.DEFAULT;
}
}
}
@@ -1,102 +0,0 @@
/*
* 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.CompoundTag;
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;
private final boolean craterLake;
public PlacedMeteoriteSettings(BlockPos pos, float meteoriteRadius, CraterType craterType, FalloutMode fallout,
boolean pureCrater, boolean craterLake) {
this.pos = pos;
this.craterType = craterType;
this.meteoriteRadius = meteoriteRadius;
this.fallout = fallout;
this.pureCrater = pureCrater;
this.craterLake = craterLake;
}
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 boolean isCraterLake() {
return craterLake;
}
public CompoundTag write(CompoundTag 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);
tag.putBoolean(Constants.TAG_LAKE, this.craterLake);
return tag;
}
public static PlacedMeteoriteSettings read(CompoundTag 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);
boolean craterLake = tag.getBoolean(Constants.TAG_LAKE);
return new PlacedMeteoriteSettings(pos, meteoriteRadius, craterType, fallout, pureCrater, craterLake);
}
@Override
public String toString() {
return "PlacedMeteoriteSettings [pos=" + pos + ", meteoriteRadius=" + meteoriteRadius + ", craterType="
+ craterType + ", fallout=" + fallout + ", pureCrater=" + pureCrater + ", craterLake=" + craterLake
+ "]";
}
}
@@ -1,145 +0,0 @@
/*
* 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.debug;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldView;
import appeng.worldgen.meteorite.CraterType;
import appeng.worldgen.meteorite.PlacedMeteoriteSettings;
/**
* Makes decisions about spawning meteorites in the world.
*/
public class MeteoriteSpawner {
public MeteoriteSpawner() {
}
public PlacedMeteoriteSettings trySpawnMeteoriteAtSuitableHeight(WorldView world, BlockPos startPos,
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);
mutablePos.move(Direction.DOWN, stepSize);
while (mutablePos.getY() > minY) {
PlacedMeteoriteSettings spawned = trySpawnMeteorite(world, mutablePos, coreRadius, craterType, pureCrater);
if (spawned != null) {
return spawned;
}
mutablePos.setY(mutablePos.getY() - stepSize);
}
return null;
}
@Nullable
public PlacedMeteoriteSettings trySpawnMeteorite(WorldView world, BlockPos pos, float coreRadius,
CraterType craterType, boolean pureCrater) {
if (!areSurroundingsSuitable(world, pos)) {
return null;
}
// we can spawn here!
int skyMode = countBlockWithSkyLight(world, pos);
boolean placeCrater = skyMode > 10;
boolean solid = !isAirBelowSpawnPoint(world, pos);
if (!solid || placeCrater) {
// return null;
}
// FalloutMode fallout = getFalloutFromBaseBlock(world.getBlockState(pos));
boolean craterLake = false;
return new PlacedMeteoriteSettings(pos, coreRadius, craterType, null, pureCrater, craterLake);
}
private static boolean isAirBelowSpawnPoint(WorldView w, BlockPos pos) {
BlockPos.Mutable testPos = new BlockPos.Mutable(pos);
for (int j = pos.getY() - 15; j < pos.getY() - 1; j++) {
testPos.setY(j);
if (w.isAir(testPos)) {
return true;
}
}
return false;
}
private int countBlockWithSkyLight(WorldView w, BlockPos pos) {
int skyMode = 0;
BlockPos.Mutable testPos = new BlockPos.Mutable();
for (int i = pos.getX() - 15; i < pos.getX() + 15; i++) {
testPos.setX(i);
for (int j = pos.getY() - 15; j < pos.getY() + 11; j++) {
testPos.setY(j);
for (int k = pos.getZ() - 15; k < pos.getZ() + 15; k++) {
testPos.setZ(k);
if (w.canBlockSeeSky(testPos)) {
skyMode++;
}
}
}
}
return skyMode;
}
private boolean areSurroundingsSuitable(WorldView w, BlockPos pos) {
int realValidBlocks = 0;
BlockPos.Mutable testPos = new BlockPos.Mutable();
for (int i = pos.getX() - 6; i < pos.getX() + 6; i++) {
testPos.setX(i);
for (int j = pos.getY() - 6; j < pos.getY() + 6; j++) {
testPos.setY(j);
for (int k = pos.getZ() - 6; k < pos.getZ() + 6; k++) {
testPos.setZ(k);
Block block = w.getBlockState(testPos).getBlock();
realValidBlocks++;
}
}
}
int validBlocks = 0;
for (int i = pos.getX() - 15; i < pos.getX() + 15; i++) {
testPos.setX(i);
for (int j = pos.getY() - 15; j < pos.getY() + 15; j++) {
testPos.setY(j);
for (int k = pos.getZ() - 15; k < pos.getZ() + 15; k++) {
testPos.setZ(k);
Block testBlk = w.getBlockState(testPos).getBlock();
validBlocks++;
}
}
}
final int minBlocks = 200;
return validBlocks > minBlocks && realValidBlocks > 80;
}
}
@@ -1,70 +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.fallout;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldAccess;
import appeng.worldgen.meteorite.MeteoriteBlockPutter;
public class Fallout {
private final MeteoriteBlockPutter putter;
private final BlockState skyStone;
public Fallout(final MeteoriteBlockPutter putter, final BlockState skyStone) {
this.putter = putter;
this.skyStone = skyStone;
}
public int adjustCrater() {
return 0;
}
public void getRandomFall(final WorldAccess w, BlockPos pos) {
final double a = Math.random();
if (a > 0.9) {
this.putter.put(w, pos, Blocks.STONE.getDefaultState());
} else if (a > 0.8) {
this.putter.put(w, pos, Blocks.COBBLESTONE.getDefaultState());
} else if (a > 0.7) {
this.putter.put(w, pos, Blocks.DIRT.getDefaultState());
} else {
this.putter.put(w, pos, Blocks.GRAVEL.getDefaultState());
}
}
public void getRandomInset(final WorldAccess w, BlockPos pos) {
final double a = Math.random();
if (a > 0.9) {
this.putter.put(w, pos, Blocks.COBBLESTONE.getDefaultState());
} else if (a > 0.8) {
this.putter.put(w, pos, Blocks.STONE.getDefaultState());
} else if (a > 0.7) {
this.putter.put(w, pos, Blocks.GRASS_BLOCK.getDefaultState());
} else if (a > 0.6) {
this.putter.put(w, pos, this.skyStone);
} else if (a > 0.5) {
this.putter.put(w, pos, Blocks.GRAVEL.getDefaultState());
} else {
this.putter.put(w, pos, Blocks.AIR.getDefaultState());
}
}
}
@@ -1,67 +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.fallout;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldAccess;
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;
private static final double BLOCK_THRESHOLD_STEP = 0.1;
private final BlockState block;
private final MeteoriteBlockPutter putter;
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();
}
@Override
public void getRandomFall(final WorldAccess w, BlockPos pos) {
final double a = Math.random();
if (a > SPECIFIED_BLOCK_THRESHOLD) {
this.putter.put(w, pos, this.block);
} else {
this.getOther(w, pos, a);
}
}
public void getOther(final WorldAccess w, BlockPos pos, final double a) {
}
@Override
public void getRandomInset(final WorldAccess w, BlockPos pos) {
final double a = Math.random();
if (a > SPECIFIED_BLOCK_THRESHOLD) {
this.putter.put(w, pos, this.block);
} else if (a > AIR_BLOCK_THRESHOLD) {
this.putter.put(w, pos, Blocks.AIR.getDefaultState());
} else {
this.getOther(w, pos, a - BLOCK_THRESHOLD_STEP);
}
}
}
@@ -1,29 +0,0 @@
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;
}
@@ -1,48 +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.fallout;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldAccess;
import appeng.worldgen.meteorite.MeteoriteBlockPutter;
public class FalloutSand extends FalloutCopy {
private static final double GLASS_THRESHOLD = 0.66;
private final MeteoriteBlockPutter putter;
public FalloutSand(final WorldAccess w, BlockPos pos, final MeteoriteBlockPutter putter, final BlockState skyStone) {
super(w, pos, putter, skyStone);
this.putter = putter;
}
@Override
public int adjustCrater() {
return 2;
}
@Override
public void getOther(final WorldAccess w, BlockPos pos, final double a) {
if (a > GLASS_THRESHOLD) {
this.putter.put(w, pos, Blocks.GLASS.getDefaultState());
}
}
}
@@ -1,51 +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.fallout;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldAccess;
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;
private final MeteoriteBlockPutter putter;
public FalloutSnow(final WorldAccess w, BlockPos pos, final MeteoriteBlockPutter putter, final BlockState skyStone) {
super(w, pos, putter, skyStone);
this.putter = putter;
}
@Override
public int adjustCrater() {
return 2;
}
@Override
public void getOther(final WorldAccess w, BlockPos pos, final double a) {
if (a > SNOW_THRESHOLD) {
this.putter.put(w, pos, Blocks.SNOW.getDefaultState());
} else if (a > ICE_THRESHOLD) {
this.putter.put(w, pos, Blocks.ICE.getDefaultState());
}
}
}