Plex-FAWE/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/RandomOffsetTransform.java
dordsor21 8c0195970b
Add and apply .editorconfig from P2 (#1195)
* Consistenty use javax annotations.
 - Unfortunately jetbrains annotations seem to be exposed transitively via core somewhere, but with the correct IDE settings, annotations can be defaulted to javax
 - Cleaning up of import order in #1195
 - Must be merged before #1195

* Add and apply .editorconfig from P2
 - Does not rearrange entries

* Address some comments

* add back some javadoc comments

* Address final comments

Co-authored-by: NotMyFault <mc.cache@web.de>
2021-07-24 16:34:05 +01:00

59 lines
2.0 KiB
Java

package com.fastasyncworldedit.core.extent;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import java.util.SplittableRandom;
public class RandomOffsetTransform extends ResettableExtent {
private final int dx;
private final int dy;
private final int dz;
private transient SplittableRandom random;
public RandomOffsetTransform(Extent parent, int dx, int dy, int dz) {
super(parent);
this.dx = dx + 1;
this.dy = dy + 1;
this.dz = dz + 1;
this.random = new SplittableRandom();
}
@Override
public boolean setBiome(BlockVector3 pos, BiomeType biome) {
int x = pos.getBlockX() + random.nextInt(1 + (dx << 1)) - dx;
int y = pos.getBlockY() + random.nextInt(1 + (dy << 1)) - dy;
int z = pos.getBlockZ() + random.nextInt(1 + (dz << 1)) - dz;
return getExtent().setBiome(x, y, z, biome);
}
@Override
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 pos, T block)
throws WorldEditException {
int x = pos.getBlockX() + random.nextInt(1 + (dx << 1)) - dx;
int y = pos.getBlockY() + random.nextInt(1 + (dy << 1)) - dy;
int z = pos.getBlockZ() + random.nextInt(1 + (dz << 1)) - dz;
return getExtent().setBlock(x, y, z, block);
}
@Override
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block)
throws WorldEditException {
x = x + random.nextInt(1 + (dx << 1)) - dx;
y = y + random.nextInt(1 + (dy << 1)) - dy;
z = z + random.nextInt(1 + (dz << 1)) - dz;
return getExtent().setBlock(x, y, z, block);
}
@Override
public ResettableExtent setExtent(Extent extent) {
random = new SplittableRandom();
return super.setExtent(extent);
}
}