Remove broken VeinGenerator

This commit is contained in:
modmuss50 2017-06-12 14:40:30 +01:00
parent cf5ed6afa0
commit 7426d83900
No known key found for this signature in database
GPG key ID: 203A5ED4D3E48BEA
2 changed files with 0 additions and 272 deletions

View file

@ -1,179 +0,0 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2017 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.world.veins;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.apache.commons.lang3.tuple.Pair;
import techreborn.utils.OreDictUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
public class VeinGenerator {
public static final int BASE_VEIN_SIZE_Y = 17;
public static final int BASE_VEIN_SIZE_WIDTH = 23;
public static final int BASE_VEIN_SIZE_DEPTH = 11;
public static final int VEIN_DENSITY = 4;
private static final HashMap<Integer, ArrayList<VeinInfo>> dimensionVeins = new HashMap<>();
private static void registerVeinInternal(int dimension, VeinInfo veinInfo) {
if (!dimensionVeins.containsKey(dimension))
dimensionVeins.put(dimension, new ArrayList<>());
dimensionVeins.get(dimension).add(veinInfo);
}
public static void registerVein(int dimension, float chance, float minSize, float maxSize, int minHeight, int maxHeight, Map<Integer, IBlockState> blocks) {
registerVeinInternal(dimension, new VeinInfo(minSize, maxSize, minHeight, maxHeight, (int) (chance * 100), blocks));
}
public static void registerVein(int dimension, float chance, float averageSize, int minHeight, int maxHeight, Pair<Float, IBlockState>... varargs) {
HashMap<Integer, IBlockState> veinBlocks = new HashMap<>();
for (Pair<Float, IBlockState> block : varargs)
veinBlocks.put((int) (block.getKey() * 100), block.getValue());
registerVein(dimension, chance, averageSize - 0.2f, averageSize + 0.2f, minHeight, maxHeight, veinBlocks);
}
public static void generateRandomVein(Random random, int chunkX, int chunkZ, World world) {
int dimension = world.provider.getDimension();
if (dimensionVeins.containsKey(dimension)) {
ArrayList<VeinInfo> veins = dimensionVeins.get(dimension);
VeinInfo randomVein = getRandomVein(veins, random);
if (randomVein != null) {
VeinGenerator.generateVein(world, chunkX, chunkZ, random, randomVein);
}
}
}
public static boolean generateVein(World world, int chunkX, int chunkZ, Random random, VeinInfo veinInfo) {
float veinSize = veinInfo.getRandomSize(random);
boolean invertXZ = random.nextBoolean();
int veinSizeX = invertXZ ? BASE_VEIN_SIZE_DEPTH : BASE_VEIN_SIZE_WIDTH;
int veinStartX = chunkX * 16 + random.nextInt(16);
int veinSizeZ = invertXZ ? BASE_VEIN_SIZE_DEPTH : BASE_VEIN_SIZE_WIDTH;
int veinStartZ = chunkZ * 16 + random.nextInt(16);
int veinMaxY = world.getTopSolidOrLiquidBlock(new BlockPos(veinStartX, 1, veinStartZ)).getY();
int veinSizeY = (int) (BASE_VEIN_SIZE_Y * veinSize);
int veinStartY = veinInfo.getRandomY(random, veinSizeY, veinMaxY);
if (isStone(world, new BlockPos(veinStartX, veinStartY, veinStartZ))) {
for (int veinX = 0; veinX < veinSizeX; veinX++) {
for (int veinZ = 0; veinZ < veinSizeZ; veinZ++) {
for (int veinY = 0; veinY < veinSizeY; veinY++) {
BlockPos veinBlockPos = new BlockPos(
veinStartX + veinX,
veinStartY + veinY,
veinStartZ + veinZ);
if (random.nextInt(VEIN_DENSITY) == 0 && isStone(world, veinBlockPos))
world.setBlockState(veinBlockPos, getOreBlock(veinInfo, random));
}
}
}
return true;
}
return false;
}
public static IBlockState getOreBlock(VeinInfo veinInfo, Random random) {
Map<Integer, IBlockState> veinBlocks = veinInfo.getVeinBlocks();
ArrayList<RangedValue<IBlockState>> blocks = new ArrayList<>();
int maxValue = 0;
for (Map.Entry<Integer, IBlockState> entry : veinBlocks.entrySet()) {
blocks.add(new RangedValue<>(maxValue, maxValue += entry.getKey(), entry.getValue()));
}
int randomValue = random.nextInt(maxValue);
for (RangedValue<IBlockState> rangedValue : blocks) {
if (rangedValue.isInBounds(randomValue))
return rangedValue.get();
}
//if you found diamond block in the vein, report it!
return Blocks.DIAMOND_BLOCK.getDefaultState();
}
private static VeinInfo getRandomVein(ArrayList<VeinInfo> veins, Random random) {
if (veins.isEmpty())
return null;
ArrayList<RangedValue<VeinInfo>> blocks = new ArrayList<>();
int maxValue = 0;
for (VeinInfo entry : veins) {
blocks.add(new RangedValue<>(maxValue, maxValue += entry.getChance(), entry));
}
int randomValue = random.nextInt(maxValue);
for (RangedValue<VeinInfo> rangedValue : blocks) {
if (rangedValue.isInBounds(randomValue))
return rangedValue.get();
}
return null;
}
public static boolean isStone(World world, BlockPos blockPos) {
IBlockState block = world.getBlockState(blockPos);
switch (world.provider.getDimension()) {
case 1:
return block.getBlock() == Blocks.END_STONE || OreDictUtils.isOre(block, "endstone");
case -1:
return block.getBlock() == Blocks.NETHERRACK || OreDictUtils.isOre(block, "netherrack");
default:
return block.getBlock() == Blocks.STONE || OreDictUtils.isOre(block, "stone");
}
}
private static class RangedValue<T> {
private final int min, max;
private final T block;
public RangedValue(int min, int max, T block) {
this.min = min;
this.max = max;
this.block = block;
}
public boolean isInBounds(int num) {
return num >= min && num <= max;
}
public T get() {
return block;
}
}
}

View file

@ -1,93 +0,0 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2017 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.world.veins;
import com.google.common.collect.ImmutableMap;
import net.minecraft.block.state.IBlockState;
import java.util.Map;
import java.util.Random;
public class VeinInfo {
private final float minSize, maxSize;
private final int minHeight, maxHeight;
private final int chance;
private final ImmutableMap<Integer, IBlockState> veinBlocks;
public VeinInfo(float minSize, float maxSize, int minHeight, int maxHeight, int chance, Map<Integer, IBlockState> veinBlocks) {
this.minSize = minSize;
this.maxSize = maxSize;
this.minHeight = minHeight;
this.maxHeight = maxHeight;
this.chance = chance;
this.veinBlocks = ImmutableMap.copyOf(veinBlocks);
}
public float getMinSize() {
return minSize;
}
public float getMaxSize() {
return maxSize;
}
public float getRandomSize(Random random) {
return minSize + random.nextFloat() * maxSize;
}
public int getMinHeight() {
return minHeight;
}
public int getMaxHeight() {
return maxHeight;
}
public int getRandomY(Random random, int boxHeight, int groundHeight) {
int maxValue = groundHeight > maxHeight ? maxHeight : groundHeight;
int randomY = (int) (minHeight + random.nextFloat() * maxValue);
if (randomY + boxHeight > maxValue) {
return randomY - (boxHeight - (maxValue - randomY));
} else if (randomY - boxHeight < minHeight) {
return randomY + (boxHeight - (randomY - minHeight));
}
return randomY;
}
public int getChance() {
return chance;
}
public boolean shouldGenerate(Random random) {
return chance >= random.nextInt(100);
}
public ImmutableMap<Integer, IBlockState> getVeinBlocks() {
return veinBlocks;
}
}