Remove most of PseudoRandom, a few minor cleaning changes, and an upstream change

Dieser Commit ist enthalten in:
matt 2019-03-26 13:41:09 -04:00
Ursprung 0d88a6bce2
Commit 3420b8329b
15 geänderte Dateien mit 128 neuen und 147 gelöschten Zeilen

Datei anzeigen

@ -24,7 +24,6 @@ import com.boydti.fawe.util.TaskManager;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.entity.BaseEntity;
@ -36,7 +35,7 @@ import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.gamemode.GameMode;
@ -51,11 +50,12 @@ import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import javax.annotation.Nullable;
public class BukkitPlayer extends AbstractPlayerActor {
private Player player;
@ -106,25 +106,24 @@ public class BukkitPlayer extends AbstractPlayerActor {
}
final ItemStack item = player.getItemInHand();
player.setItemInHand(newItem);
if (item != null) {
HashMap<Integer, ItemStack> overflow = inv.addItem(item);
if (overflow != null && !overflow.isEmpty()) {
TaskManager.IMP.sync(new RunnableVal<Object>() {
@Override
public void run(Object value) {
for (Map.Entry<Integer, ItemStack> entry : overflow.entrySet()) {
ItemStack stack = entry.getValue();
if (stack.getType() != Material.AIR && stack.getAmount() > 0) {
Item dropped = player.getWorld().dropItem(player.getLocation(), stack);
PlayerDropItemEvent event = new PlayerDropItemEvent(player, dropped);
if (event.isCancelled()) {
dropped.remove();
}
HashMap<Integer, ItemStack> overflow = inv.addItem(item);
if (!overflow.isEmpty()) {
TaskManager.IMP.sync(new RunnableVal<Object>() {
@Override
public void run(Object value) {
for (Map.Entry<Integer, ItemStack> entry : overflow.entrySet()) {
ItemStack stack = entry.getValue();
if (stack.getType() != Material.AIR && stack.getAmount() > 0) {
Item
dropped = player.getWorld().dropItem(player.getLocation(), stack);
PlayerDropItemEvent event = new PlayerDropItemEvent(player, dropped);
if (event.isCancelled()) {
dropped.remove();
}
}
}
});
}
}
});
}
player.updateInventory();
}

Datei anzeigen

@ -19,6 +19,7 @@ import com.boydti.fawe.util.SetQueue;
import com.boydti.fawe.util.TaskManager;
import com.boydti.fawe.util.WEManager;
import com.boydti.fawe.wrappers.WorldWrapper;
import com.google.common.collect.Sets;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
@ -192,12 +193,12 @@ public class FaweAPI {
List<? extends World> worlds = platform.getWorlds();
for (World current : worlds) {
if (Fawe.imp().getWorldName(current).equals(worldName)) {
return WorldWrapper.wrap((AbstractWorld) current);
return WorldWrapper.wrap(current);
}
}
for (World current : worlds) {
if (current.getName().equals(worldName)) {
return WorldWrapper.wrap((AbstractWorld) current);
return WorldWrapper.wrap(current);
}
}
return null;
@ -247,11 +248,10 @@ public class FaweAPI {
/**
* Use ThreadLocalRandom instead
*
* @return
*/
@Deprecated
public static PseudoRandom getFastRandom() {
return new PseudoRandom();
throw new UnsupportedOperationException("Please Use ThreadLocalRandom instead.");
}
/**
@ -365,20 +365,17 @@ public class FaweAPI {
}
}
World world = origin.getWorld();
Collections.sort(files, new Comparator<File>() {
@Override
public int compare(File a, File b) {
String aName = a.getName();
String bName = b.getName();
int aI = Integer.parseInt(aName.substring(0, aName.length() - 3));
int bI = Integer.parseInt(bName.substring(0, bName.length() - 3));
long value = aI - bI;
return value == 0 ? 0 : value < 0 ? -1 : 1;
}
files.sort((a, b) -> {
String aName = a.getName();
String bName = b.getName();
int aI = Integer.parseInt(aName.substring(0, aName.length() - 3));
int bI = Integer.parseInt(bName.substring(0, bName.length() - 3));
long value = aI - bI;
return value == 0 ? 0 : value < 0 ? -1 : 1;
});
RegionWrapper bounds = new RegionWrapper(origin.x - radius, origin.x + radius, origin.z - radius, origin.z + radius);
RegionWrapper boundsPlus = new RegionWrapper(bounds.minX - 64, bounds.maxX + 512, bounds.minZ - 64, bounds.maxZ + 512);
HashSet<RegionWrapper> regionSet = new HashSet<>(Arrays.asList(bounds));
HashSet<RegionWrapper> regionSet = Sets.<RegionWrapper>newHashSet(bounds);
ArrayList<DiskStorageHistory> result = new ArrayList<>();
for (File file : files) {
UUID uuid = UUID.fromString(file.getParentFile().getName());

Datei anzeigen

@ -21,6 +21,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
public enum BBC {
@ -523,7 +524,7 @@ public enum BBC {
}
public BBC or(BBC... others) {
int index = PseudoRandom.random.nextInt(others.length + 1);
int index = ThreadLocalRandom.current().nextInt(others.length + 1);
return index == 0 ? this : others[index - 1];
}

Datei anzeigen

@ -46,6 +46,7 @@ import java.io.IOException;
import java.lang.reflect.Field;
import java.util.*;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import javax.annotation.Nullable;
// TODO FIXME
@ -513,7 +514,8 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
for (int z = 0; z < getLength(); z++) {
for (int x = 0; x < getWidth(); x++, index++) {
int height = img.getRGB(x, z) & 0xFF;
if (height == 255 || height > 0 && !white && PseudoRandom.random.nextInt(256) <= height) {
if (height == 255 || height > 0 && !white && ThreadLocalRandom.current()
.nextInt(256) <= height) {
int newHeight = table.average(x, z, index);
setLayerHeightRaw(index, newHeight);
}
@ -576,7 +578,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
for (int x = 0; x < getWidth(); x++, index++) {
int y = heights.getByte(index) & 0xFF;
int height = img.getRGB(x, z) & 0xFF;
if (height == 0 || PseudoRandom.random.nextInt(256) > height * doubleRarity) {
if (height == 0 || ThreadLocalRandom.current().nextInt(256) > height * doubleRarity) {
continue;
}
mutable.mutX(x);
@ -624,7 +626,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
mutable.mutZ(z);
for (int x = 0; x < getWidth(); x++, index++) {
int y = heights.getByte(index) & 0xFF;
if (PseudoRandom.random.nextInt(256) > scaledRarity) {
if (ThreadLocalRandom.current().nextInt(256) > scaledRarity) {
continue;
}
mutable.mutX(x);
@ -1085,7 +1087,8 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
for (int z = 0; z < getLength(); z++) {
for (int x = 0; x < getWidth(); x++, index++) {
int height = img.getRGB(x, z) & 0xFF;
if (height == 255 || height > 0 && !white && PseudoRandom.random.nextInt(256) <= height) {
if (height == 255 || height > 0 && !white && ThreadLocalRandom.current()
.nextInt(256) <= height) {
biomeArr[index] = biome;
}
}
@ -1136,7 +1139,8 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
}
if (imgMask != null) {
int height = imgMask.getRGB(x, z) & 0xFF;
if (height != 255 && (height <= 0 || !whiteOnly || PseudoRandom.random.nextInt(256) > height)) continue;
if (height != 255 && (height <= 0 || !whiteOnly || ThreadLocalRandom
.current().nextInt(256) > height)) continue;
}
int color = img.getRGB(x, z);
if (textureUtil.getIsBlockCloserThanBiome(buffer, color, primtives.biomePriority)) {
@ -1220,7 +1224,8 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
for (int z = 0; z < getLength(); z++) {
for (int x = 0; x < getWidth(); x++, index++) {
int height = mask.getRGB(x, z) & 0xFF;
if (height == 255 || height > 0 && !white && PseudoRandom.random.nextInt(256) <= height) {
if (height == 255 || height > 0 && !white && ThreadLocalRandom.current()
.nextInt(256) <= height) {
int color = img.getRGB(x, z);
BlockType block = textureUtil.getNearestBlock(color);
if (block != null) {
@ -1353,7 +1358,8 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
mutable.mutZ(z);
for (int x = 0; x < getWidth(); x++, index++) {
int height = img.getRGB(x, z) & 0xFF;
if (height == 255 || height > 0 && !white && PseudoRandom.random.nextInt(256) <= height) {
if (height == 255 || height > 0 && !white && ThreadLocalRandom.current()
.nextInt(256) <= height) {
mutable.mutX(x);
mutable.mutY(height);
overlayArr[index] = pattern.apply(mutable.toBlockVector3()).getInternalId();
@ -1380,7 +1386,8 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
mutable.mutZ(z);
for (int x = 0; x < getWidth(); x++, index++) {
int height = img.getRGB(x, z) & 0xFF;
if (height == 255 || height > 0 && !white && PseudoRandom.random.nextInt(256) <= height) {
if (height == 255 || height > 0 && !white && ThreadLocalRandom.current()
.nextInt(256) <= height) {
mutable.mutX(x);
mutable.mutY(height);
mainArr[index] = pattern.apply(mutable.toBlockVector3()).getInternalId();
@ -1405,7 +1412,8 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
mutable.mutZ(z);
for (int x = 0; x < getWidth(); x++, index++) {
int height = img.getRGB(x, z) & 0xFF;
if (height == 255 || height > 0 && !white && PseudoRandom.random.nextInt(256) <= height) {
if (height == 255 || height > 0 && !white && ThreadLocalRandom.current()
.nextInt(256) <= height) {
mutable.mutX(x);
mutable.mutY(height);
floorArr[index] = pattern.apply(mutable.toBlockVector3()).getInternalId();
@ -1432,7 +1440,8 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
mutable.mutZ(z);
for (int x = 0; x < getWidth(); x++, index++) {
int height = img.getRGB(x, z) & 0xFF;
if (height == 255 || height > 0 && !white && PseudoRandom.random.nextInt(256) <= height) {
if (height == 255 || height > 0 && !white && ThreadLocalRandom.current()
.nextInt(256) <= height) {
mutable.mutX(x);
mutable.mutY(height);
int combined = pattern.apply(mutable.toBlockVector3()).getInternalId();
@ -2078,7 +2087,8 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
for (int z = 0; z < getLength(); z++) {
for (int x = 0; x < getWidth(); x++, index++) {
int height = img.getRGB(x, z) & 0xFF;
if (height == 255 || height > 0 && white && PseudoRandom.random.nextInt(256) <= height) {
if (height == 255 || height > 0 && white && ThreadLocalRandom.current()
.nextInt(256) <= height) {
overlay.get()[index] = combined;
}
}
@ -2096,7 +2106,8 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
for (int z = 0; z < getLength(); z++) {
for (int x = 0; x < getWidth(); x++, index++) {
int height = img.getRGB(x, z) & 0xFF;
if (height == 255 || height > 0 && !white && PseudoRandom.random.nextInt(256) <= height) {
if (height == 255 || height > 0 && !white && ThreadLocalRandom.current()
.nextInt(256) <= height) {
main.get()[index] = combined;
}
}
@ -2113,7 +2124,8 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
for (int z = 0; z < getLength(); z++) {
for (int x = 0; x < getWidth(); x++, index++) {
int height = img.getRGB(x, z) & 0xFF;
if (height == 255 || height > 0 && !white && PseudoRandom.random.nextInt(256) <= height) {
if (height == 255 || height > 0 && !white && ThreadLocalRandom.current()
.nextInt(256) <= height) {
floor.get()[index] = combined;
}
}
@ -2131,7 +2143,8 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
for (int z = 0; z < getLength(); z++) {
for (int x = 0; x < getWidth(); x++, index++) {
int height = img.getRGB(x, z) & 0xFF;
if (height == 255 || height > 0 && !white && PseudoRandom.random.nextInt(256) <= height) {
if (height == 255 || height > 0 && !white && ThreadLocalRandom.current()
.nextInt(256) <= height) {
main.get()[index] = combined;
floor.get()[index] = combined;
}

Datei anzeigen

@ -1,16 +1,15 @@
package com.boydti.fawe.jnbt.anvil.generator;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.object.PseudoRandom;
import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.concurrent.ThreadLocalRandom;
public class CavesGen extends GenBase {
private boolean evenCaveDistribution = false;
@ -42,7 +41,8 @@ public class CavesGen extends GenBase {
}
protected void generateLargeCaveNode(long seed, BlockVector2 pos, Extent chunk, double x, double y, double z) throws WorldEditException {
generateCaveNode(seed, pos, chunk, x, y, z, 1.0F + PseudoRandom.random.nextDouble() * 6.0F, 0.0F, 0.0F, -1, -1, 0.5D);
generateCaveNode(seed, pos, chunk, x, y, z, 1.0F + ThreadLocalRandom.current().nextDouble()
* 6.0F, 0.0F, 0.0F, -1, -1, 0.5D);
}
protected void generateCaveNode(long seed, BlockVector2 chunkPos, Extent chunk, double x, double y, double z, double paramdouble1, double paramdouble2, double paramdouble3, int angle, int maxAngle, double paramDouble4) throws WorldEditException {
@ -54,11 +54,9 @@ public class CavesGen extends GenBase {
double f1 = 0.0F;
double f2 = 0.0F;
PseudoRandom localRandom = new PseudoRandom(seed);
if (maxAngle <= 0) {
int checkAreaSize = this.getCheckAreaSize() * 16 - 16;
maxAngle = checkAreaSize - localRandom.nextInt(checkAreaSize / 4);
maxAngle = checkAreaSize - ThreadLocalRandom.current().nextInt(checkAreaSize / 4);
}
boolean isLargeCave = false;
@ -67,8 +65,8 @@ public class CavesGen extends GenBase {
isLargeCave = true;
}
int j = localRandom.nextInt(maxAngle / 2) + maxAngle / 4;
int k = localRandom.nextInt(6) == 0 ? 1 : 0;
int j = ThreadLocalRandom.current().nextInt(maxAngle / 2) + maxAngle / 4;
int k = ThreadLocalRandom.current().nextInt(6) == 0 ? 1 : 0;
for (; angle < maxAngle; angle++) {
double d3 = 1.5D + MathMan.sinInexact(angle * 3.141593F / maxAngle) * paramdouble1 * 1.0F;
@ -90,15 +88,19 @@ public class CavesGen extends GenBase {
f2 *= 0.9F;
f1 *= 0.75F;
f2 += (localRandom.nextDouble() - localRandom.nextDouble()) * localRandom.nextDouble() * 2.0F;
f1 += (localRandom.nextDouble() - localRandom.nextDouble()) * localRandom.nextDouble() * 4.0F;
f2 += (ThreadLocalRandom.current().nextDouble() - ThreadLocalRandom.current()
.nextDouble()) * ThreadLocalRandom.current().nextDouble() * 2.0F;
f1 += (ThreadLocalRandom.current().nextDouble() - ThreadLocalRandom.current()
.nextDouble()) * ThreadLocalRandom.current().nextDouble() * 4.0F;
if ((!isLargeCave) && (angle == j) && (paramdouble1 > 1.0F) && (maxAngle > 0)) {
generateCaveNode(localRandom.nextLong(), chunkPos, chunk, x, y, z, localRandom.nextDouble() * 0.5F + 0.5F, paramdouble2 - 1.570796F, paramdouble3 / 3.0F, angle, maxAngle, 1.0D);
generateCaveNode(localRandom.nextLong(), chunkPos, chunk, x, y, z, localRandom.nextDouble() * 0.5F + 0.5F, paramdouble2 + 1.570796F, paramdouble3 / 3.0F, angle, maxAngle, 1.0D);
generateCaveNode(ThreadLocalRandom.current().nextLong(), chunkPos, chunk, x, y, z, ThreadLocalRandom
.current().nextDouble() * 0.5F + 0.5F, paramdouble2 - 1.570796F, paramdouble3 / 3.0F, angle, maxAngle, 1.0D);
generateCaveNode(ThreadLocalRandom.current().nextLong(), chunkPos, chunk, x, y, z, ThreadLocalRandom
.current().nextDouble() * 0.5F + 0.5F, paramdouble2 + 1.570796F, paramdouble3 / 3.0F, angle, maxAngle, 1.0D);
return;
}
if ((!isLargeCave) && (localRandom.nextInt(4) == 0)) {
if ((!isLargeCave) && (ThreadLocalRandom.current().nextInt(4) == 0)) {
continue;
}
@ -145,7 +147,7 @@ public class CavesGen extends GenBase {
for (int local_x = m; (!waterFound) && (local_x < n); local_x++) {
for (int local_z = i3; (!waterFound) && (local_z < i4); local_z++) {
for (int local_y = i2 + 1; (!waterFound) && (local_y >= i1 - 1); local_y--) {
if (local_y >= 0 && local_y < 255) {
if (local_y < 255) {
BlockStateHolder material = chunk.getLazyBlock(bx + local_x, local_y, bz + local_z);
if (material.getBlockType() == BlockTypes.WATER) {
waterFound = true;
@ -220,42 +222,48 @@ public class CavesGen extends GenBase {
@Override
public void generateChunk(int chunkX, int chunkZ, BlockVector2 originChunk, Extent chunk) throws WorldEditException {
PseudoRandom random = getRandom();
int i = random.nextInt(random.nextInt(random.nextInt(this.caveFrequency) + 1) + 1);
int i = ThreadLocalRandom.current().nextInt(ThreadLocalRandom.current()
.nextInt(ThreadLocalRandom.current().nextInt(this.caveFrequency) + 1) + 1);
if (this.evenCaveDistribution)
i = this.caveFrequency;
if (random.nextInt(100) >= this.caveRarity)
if (ThreadLocalRandom.current().nextInt(100) >= this.caveRarity)
i = 0;
for (int j = 0; j < i; j++) {
double x = (chunkX << 4) + random.nextInt(16);
double x = (chunkX << 4) + ThreadLocalRandom.current().nextInt(16);
double y;
if (this.evenCaveDistribution)
y = random.nextInt(this.caveMinAltitude, this.caveMaxAltitude);
else
y = random.nextInt(random.nextInt(this.caveMaxAltitude - this.caveMinAltitude + 1) + 1) + this.caveMinAltitude;
y = ThreadLocalRandom.current().nextInt(this.caveMinAltitude, this.caveMaxAltitude);
else {
y = ThreadLocalRandom.current()
.nextInt(ThreadLocalRandom.current()
.nextInt(this.caveMaxAltitude - this.caveMinAltitude + 1) + 1) + this.caveMinAltitude;
}
double z = (chunkZ << 4) + random.nextInt(16);
double z = (chunkZ << 4) + ThreadLocalRandom.current().nextInt(16);
int count = this.caveSystemFrequency;
boolean largeCaveSpawned = false;
if (random.nextInt(100) <= this.individualCaveRarity) {
generateLargeCaveNode(random.nextLong(), originChunk, chunk, x, y, z);
if (ThreadLocalRandom.current().nextInt(100) <= this.individualCaveRarity) {
generateLargeCaveNode(ThreadLocalRandom.current().nextLong(), originChunk, chunk, x, y, z);
largeCaveSpawned = true;
}
if ((largeCaveSpawned) || (random.nextInt(100) <= this.caveSystemPocketChance - 1)) {
count += random.nextInt(this.caveSystemPocketMinSize, this.caveSystemPocketMaxSize);
if ((largeCaveSpawned) || (ThreadLocalRandom.current().nextInt(100)
<= this.caveSystemPocketChance - 1)) {
count += ThreadLocalRandom.current()
.nextInt(this.caveSystemPocketMinSize, this.caveSystemPocketMaxSize);
}
while (count > 0) {
count--;
double f1 = random.nextDouble() * 3.141593F * 2.0F;
double f2 = (random.nextDouble() - 0.5F) * 2.0F / 8.0F;
double f3 = random.nextDouble() * 2.0F + random.nextDouble();
generateCaveNode(random.nextLong(), originChunk, chunk, x, y, z, f3, f1, f2, 0, 0, 1.0D);
double f1 = ThreadLocalRandom.current().nextDouble() * 3.141593F * 2.0F;
double f2 = (ThreadLocalRandom.current().nextDouble() - 0.5F) * 2.0F / 8.0F;
double f3 = ThreadLocalRandom.current().nextDouble() * 2.0F + ThreadLocalRandom
.current().nextDouble();
generateCaveNode(ThreadLocalRandom.current().nextLong(), originChunk, chunk, x, y, z, f3, f1, f2, 0, 0, 1.0D);
}
}
}
}
}

Datei anzeigen

@ -5,6 +5,8 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector2;
import java.util.concurrent.ThreadLocalRandom;
public abstract class GenBase {
private final int checkAreaSize;
@ -15,9 +17,9 @@ public abstract class GenBase {
public GenBase(int area) {
this.random = new PseudoRandom();
this.checkAreaSize = area;
this.seed = PseudoRandom.random.nextLong();
this.worldSeed1 = PseudoRandom.random.nextLong();
this.worldSeed2 = PseudoRandom.random.nextLong();
this.seed = ThreadLocalRandom.current().nextLong();
this.worldSeed1 = ThreadLocalRandom.current().nextLong();
this.worldSeed2 = ThreadLocalRandom.current().nextLong();
}
public int getCheckAreaSize() {
@ -34,7 +36,6 @@ public abstract class GenBase {
int chunkZ = chunkPos.getBlockZ();
for (int x = chunkX - i; x <= chunkX + i; x++) {
for (int z = chunkZ - i; z <= chunkZ + i; z++) {
this.random.setSeed(worldSeed1 * x ^ worldSeed2 * z ^ seed);
generateChunk(x, z, chunkPos, chunk);
}
}

Datei anzeigen

@ -1,5 +1,7 @@
package com.boydti.fawe.object;
import java.util.concurrent.ThreadLocalRandom;
@Deprecated
/**
* @Deprecated use ThreadLocalRandom instead
@ -7,50 +9,15 @@ package com.boydti.fawe.object;
public class PseudoRandom {
public static PseudoRandom random = new PseudoRandom();
private long state;
public PseudoRandom() {
this.state = System.nanoTime();
}
public PseudoRandom(final long state) {
this.state = state;
}
public void setSeed(long state) {
this.state = state;
}
public long nextLong() {
final long a = this.state;
this.state = this.xorShift64(a);
return a;
}
public long xorShift64(long a) {
a ^= (a << 21);
a ^= (a >>> 35);
a ^= (a << 4);
return a;
}
public double nextDouble() {
return 0x1.0p-63 * (((nextLong()) & 0x7FFFFFFFFFFFFFFFl));
}
public int random(final int n) {
if (n == 1) {
return 0;
}
final long r = ((this.nextLong() >>> 32) * n) >> 32;
final long r = ((ThreadLocalRandom.current().nextLong() >>> 32) * n) >> 32;
return (int) r;
}
public int nextInt(int i) {
return random(i);
}
public int nextInt(int start, int end) {
return nextInt(end - start + 1) + start;
}
}

Datei anzeigen

@ -2,7 +2,6 @@ package com.boydti.fawe.object.brush;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.PseudoRandom;
import com.boydti.fawe.object.brush.visualization.VisualExtent;
import com.boydti.fawe.object.clipboard.ResizableClipboardBuilder;
import com.boydti.fawe.object.function.NullRegionFunction;
@ -11,7 +10,6 @@ import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.command.tool.brush.Brush;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
@ -26,7 +24,8 @@ import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import java.util.concurrent.ThreadLocalRandom;
public class CopyPastaBrush implements Brush, ResettableTool {
@ -94,7 +93,7 @@ public class CopyPastaBrush implements Brush, ResettableTool {
AffineTransform transform = null;
if (randomRotate) {
if (transform == null) transform = new AffineTransform();
int rotate = 90 * PseudoRandom.random.nextInt(4);
int rotate = 90 * ThreadLocalRandom.current().nextInt(4);
transform = transform.rotateY(rotate);
}
if (autoRotate) {
@ -120,4 +119,4 @@ public class CopyPastaBrush implements Brush, ResettableTool {
editSession.flushQueue();
}
}
}
}

Datei anzeigen

@ -3,7 +3,6 @@ package com.boydti.fawe.object.brush;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.jnbt.anvil.HeightMapMCAGenerator;
import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.object.PseudoRandom;
import com.boydti.fawe.object.brush.heightmap.HeightMap;
import com.boydti.fawe.object.brush.heightmap.RotatableHeightMap;
import com.boydti.fawe.object.brush.heightmap.ScalableHeightMap;
@ -22,6 +21,7 @@ import com.sk89q.worldedit.math.Vector3;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.ThreadLocalRandom;
public class HeightBrush implements Brush {
@ -60,7 +60,7 @@ public class HeightBrush implements Brush {
heightMap = new RotatableHeightMap(heightMap);
}
RotatableHeightMap rotatable = (RotatableHeightMap) heightMap;
rotatable.rotate(PseudoRandom.random.nextInt(360));
rotatable.rotate(ThreadLocalRandom.current().nextInt(360));
}
return heightMap;
}

Datei anzeigen

@ -1,6 +1,5 @@
package com.boydti.fawe.object.brush;
import com.boydti.fawe.object.PseudoRandom;
import com.boydti.fawe.object.collection.BlockVectorSet;
import com.boydti.fawe.object.collection.LocalBlockVectorSet;
import com.boydti.fawe.object.mask.AdjacentAnyMask;
@ -18,6 +17,7 @@ import com.sk89q.worldedit.function.visitor.RecursiveVisitor;
import com.sk89q.worldedit.math.BlockVector3;
import java.util.Arrays;
import java.util.concurrent.ThreadLocalRandom;
public class ScatterBrush implements Brush {
@ -63,7 +63,7 @@ public class ScatterBrush implements Brush {
LocalBlockVectorSet placed = new LocalBlockVectorSet();
int maxFails = 1000;
for (int i = 0; i < count; i++) {
int index = PseudoRandom.random.nextInt(length);
int index = ThreadLocalRandom.current().nextInt(length);
BlockVector3 pos = visited.get(index);
if (pos != null && canApply(editSession, pos)) {
int x = pos.getBlockX();
@ -97,4 +97,4 @@ public class ScatterBrush implements Brush {
public void apply(EditSession editSession, LocalBlockVectorSet placed, BlockVector3 pt, Pattern p, double size) throws MaxChangedBlocksException {
editSession.setBlock(pt, p);
}
}
}

Datei anzeigen

@ -1,11 +1,11 @@
package com.boydti.fawe.object.clipboard;
import com.boydti.fawe.object.PseudoRandom;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.session.ClipboardHolder;
import java.net.URI;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import static com.google.common.base.Preconditions.checkNotNull;
@ -144,7 +144,7 @@ public class MultiClipboardHolder extends URIClipboardHolder {
case 1: return available[0];
}
int index = PseudoRandom.random.nextInt(available.length);
int index = ThreadLocalRandom.current().nextInt(available.length);
return available[index];
}
@ -167,4 +167,4 @@ public class MultiClipboardHolder extends URIClipboardHolder {
holder.close();
}
}
}
}

Datei anzeigen

@ -63,7 +63,6 @@ public abstract class FaweBlockMatcher {
// return setBlock(blocks.iterator().next());
// }
// final BaseBlock[] array = blocks.toArray(new BaseBlock[blocks.size()]);
// final PseudoRandom random = new PseudoRandom(System.nanoTime());
// final int size = array.length;
// return new FaweBlockMatcher() {
// @Override

Datei anzeigen

@ -1,9 +1,6 @@
package com.boydti.fawe.object.pattern;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.object.PseudoRandom;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.function.pattern.AbstractPattern;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.function.visitor.BreadthFirstSearch;
@ -12,6 +9,7 @@ import com.sk89q.worldedit.math.MutableBlockVector;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import java.io.IOException;
import java.util.concurrent.ThreadLocalRandom;
public class SurfaceRandomOffsetPattern extends AbstractPattern {
private final Pattern pattern;
@ -57,7 +55,7 @@ public class SurfaceRandomOffsetPattern extends AbstractPattern {
if (index == 0) {
return cur.toBlockVector3();
}
next = allowed[PseudoRandom.random.nextInt(index)];
next = allowed[ThreadLocalRandom.current().nextInt(index)];
cur.setComponents(next.getBlockX(), next.getBlockY(), next.getBlockZ());
}
return cur.toBlockVector3();
@ -117,4 +115,4 @@ public class SurfaceRandomOffsetPattern extends AbstractPattern {
stream.defaultReadObject();
init();
}
}
}

Datei anzeigen

@ -1,8 +1,6 @@
package com.boydti.fawe.regions.general.plot;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.PseudoRandom;
import com.boydti.fawe.util.EditSessionBuilder;
import com.boydti.fawe.util.TaskManager;
import com.github.intellectualsites.plotsquared.commands.Command;
@ -30,6 +28,7 @@ import com.sk89q.worldedit.world.biome.Biomes;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
@CommandDeclaration(
command = "generatebiome",
@ -82,7 +81,7 @@ public class PlotSetBiome extends Command {
.player(FawePlayer.wrap(player.getName()))
.limitUnlimited()
.build();
long seed = PseudoRandom.random.nextLong();
long seed = ThreadLocalRandom.current().nextLong();
for (RegionWrapper region : regions) {
CuboidRegion cuboid = new CuboidRegion(BlockVector3.at(region.minX, 0, region.minZ), BlockVector3.at(region.maxX, 256, region.maxZ));
session.regenerate(cuboid, biome, seed);

Datei anzeigen

@ -1,11 +1,10 @@
package com.boydti.fawe.util;
import com.boydti.fawe.object.PseudoRandom;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.io.FileNotFoundException;
import java.util.concurrent.ThreadLocalRandom;
public class RandomTextureUtil extends CachedTextureUtil {
@ -33,9 +32,10 @@ public class RandomTextureUtil extends CachedTextureUtil {
private int random(int i) {
if (i < 0) {
return -PseudoRandom.random.nextInt((-i));
int i1 = (-i);
return -ThreadLocalRandom.current().nextInt(i1);
} else {
return PseudoRandom.random.nextInt(i);
return ThreadLocalRandom.current().nextInt(i);
}
}