Fixed Rarity map, Fixed missing blocks

This commit is contained in:
Brian Fopiano 2021-12-25 18:40:25 -08:00
parent 24408e53a3
commit 8bbf98979e
2 changed files with 51 additions and 60 deletions

View File

@ -27,40 +27,35 @@ import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.stream.ProceduralStream; import com.volmit.iris.util.stream.ProceduralStream;
import com.volmit.iris.util.stream.arithmetic.FittedStream; import com.volmit.iris.util.stream.arithmetic.FittedStream;
import com.volmit.iris.util.stream.interpolation.Interpolated; import com.volmit.iris.util.stream.interpolation.Interpolated;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.HashMap; import java.util.*;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
public interface IRare { public interface IRare {
static <T extends IRare> ProceduralStream<T> stream(ProceduralStream<Double> noise, List<T> possibilities) static <T extends IRare> ProceduralStream<T> stream(ProceduralStream<Double> noise, List<T> possibilities) {
{
return ProceduralStream.of((x, z) -> pick(possibilities, noise.get(x, z)), return ProceduralStream.of((x, z) -> pick(possibilities, noise.get(x, z)),
(x, y, z) -> pick(possibilities, noise.get(x, y, z)), (x, y, z) -> pick(possibilities, noise.get(x, y, z)),
new Interpolated<T>() { new Interpolated<T>() {
@Override @Override
public double toDouble(T t) { public double toDouble(T t) {
return 0; return 0;
} }
@Override @Override
public T fromDouble(double d) { public T fromDouble(double d) {
return null; return null;
} }
}); });
} }
static <T extends IRare> T pickSlowly(List<T> possibilities, double noiseValue)
{ static <T extends IRare> T pickSlowly(List<T> possibilities, double noiseValue) {
if(possibilities.isEmpty()) if (possibilities.isEmpty()) {
{
return null; return null;
} }
if(possibilities.size() == 1) if (possibilities.size() == 1) {
{
return possibilities.get(0); return possibilities.get(0);
} }
@ -77,23 +72,44 @@ public interface IRare {
return rarityTypes.get((int) (noiseValue * rarityTypes.last())); return rarityTypes.get((int) (noiseValue * rarityTypes.last()));
} }
static <T extends IRare> T pick(List<T> possibilities, double noiseValue) static <T extends IRare> T pick(List<T> possibilities, double noiseValue) {
{ if (possibilities.isEmpty()) {
if(possibilities.isEmpty())
{
return null; return null;
} }
if(possibilities.size() == 1) if (possibilities.size() == 1) {
{ return possibilities.get(0);
}
int totalWeight = 0; // This is he baseline
int buffer = 0;
for (T i : possibilities) { // Im adding all of the rarity together
totalWeight += i.getRarity();
}
double threshold = totalWeight * (possibilities.size() - 1) * noiseValue;
for (T i : possibilities) {
buffer += totalWeight - i.getRarity();
if (buffer >= threshold) {
return i;
}
}
return possibilities.get(possibilities.size() - 1);
}
static <T extends IRare> T pickOld(List<T> possibilities, double noiseValue) {
if (possibilities.isEmpty()) {
return null;
}
if (possibilities.size() == 1) {
return possibilities.get(0); return possibilities.get(0);
} }
double completeWeight = 0.0; double completeWeight = 0.0;
double highestWeight = 0.0; double highestWeight = 0.0;
for (T item : possibilities) for (T item : possibilities) {
{
double weight = Math.max(item.getRarity(), 1); double weight = Math.max(item.getRarity(), 1);
highestWeight = Math.max(highestWeight, weight); highestWeight = Math.max(highestWeight, weight);
completeWeight += weight; completeWeight += weight;
@ -105,8 +121,7 @@ public interface IRare {
for (T item : possibilities) { for (T item : possibilities) {
double weight = Math.max(highestWeight - Math.max(item.getRarity(), 1), 1); double weight = Math.max(highestWeight - Math.max(item.getRarity(), 1), 1);
countWeight += weight; countWeight += weight;
if (countWeight >= r) if (countWeight >= r) {
{
return item; return item;
} }
} }

View File

@ -46,7 +46,6 @@ import static org.bukkit.Material.*;
public class B { public class B {
private static final Material AIR_MATERIAL = Material.AIR; private static final Material AIR_MATERIAL = Material.AIR;
private static final ReentrantLock createLock = new ReentrantLock();
private static final BlockData AIR = AIR_MATERIAL.createBlockData(); private static final BlockData AIR = AIR_MATERIAL.createBlockData();
private static final IntSet foliageCache = buildFoliageCache(); private static final IntSet foliageCache = buildFoliageCache();
private static final IntSet deepslateCache = buildDeepslateCache(); private static final IntSet deepslateCache = buildDeepslateCache();
@ -441,31 +440,8 @@ public class B {
return AIR; return AIR;
} }
private static BlockData createBlockData(String s) { private static synchronized BlockData createBlockData(String s) {
BlockData be = null; return Bukkit.createBlockData(s);
try {
be = Bukkit.createBlockData(s);
} catch (Throwable e) {
}
if (be == null) {
try {
createLock.lock();
be = Bukkit.createBlockData(s);
createLock.unlock();
if (be != null) {
Iris.info("We have fixed: " + s);
}
return be;
} catch (Throwable ee) {
}
Iris.error("Oh no... " + s);
}
return be;
} }
private static BlockData parseBlockData(String ix) { private static BlockData parseBlockData(String ix) {