Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NukkitX standard generator #1303

Merged
merged 147 commits into from
Apr 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
d8ba11f
delete packages `cn.nukkit.level.generator` and `cn.nukkit.level.biome`
DaMatrix Jan 23, 2020
8085328
add some base generator interfaces
DaMatrix Jan 23, 2020
f700fa4
allow generators to define a custom selection of chunks for population
DaMatrix Jan 23, 2020
2a7501c
add a basic superflat generator
DaMatrix Jan 25, 2020
5b91d04
make the server be able to build and start again
DaMatrix Jan 25, 2020
20493ad
add tasks for generation and population, theoretically population sho…
DaMatrix Jan 25, 2020
d644006
redo `NukkitRandom` to make it be not bad, and eliminate dozens of un…
DaMatrix Jan 25, 2020
5d7a050
begin to implement a `ChunkManager` for population
DaMatrix Jan 25, 2020
aa36895
Merge remote-tracking branch 'upstream/2.0' into dev/generator-api-re…
DaMatrix Jan 25, 2020
e91ebc1
attempt to use population chunk manager, it's broken though...
DaMatrix Jan 25, 2020
0eca8ff
debug temp commit
DaMatrix Jan 26, 2020
e8ffc2b
Merge remote-tracking branch 'upstream/2.0' into dev/generator-api-re…
DaMatrix Feb 15, 2020
fdd49f4
Merge remote-tracking branch 'upstream/2.0' into dev/generator-api-re…
DaMatrix Feb 20, 2020
97427fd
Merge remote-tracking branch 'upstream/2.0' into dev/generator-api-re…
DaMatrix Feb 22, 2020
f088b32
totally remove NukkitRandom and remove all usages of BedrockRandom
DaMatrix Feb 22, 2020
4c502de
since we now can save all chunks, we can make this a lot cleaner
DaMatrix Feb 22, 2020
52dfe71
crash when an invalid generator is configured
DaMatrix Feb 22, 2020
8fdae79
make chunks completely unobtainable unless they and all of their neig…
DaMatrix Feb 22, 2020
3b91718
avoid useless array allocation
DaMatrix Feb 22, 2020
dd660a9
implement superflat presets
DaMatrix Feb 23, 2020
e39bc77
initial commit for standard generator
DaMatrix Feb 24, 2020
cf4f5e8
population chunks are always 3x3
DaMatrix Feb 24, 2020
cab9e40
Merge branch 'dev/generator-api-rewrite' into dev/nukkitx-standard-ge…
DaMatrix Feb 24, 2020
de5ab70
Merge remote-tracking branch 'upstream/2.0' into dev/generator-api-re…
DaMatrix Feb 24, 2020
326b259
Merge branch 'dev/generator-api-rewrite' into dev/nukkitx-standard-ge…
DaMatrix Feb 24, 2020
4641aaf
Merge remote-tracking branch 'upstream/2.0' into dev/nukkitx-standard…
DaMatrix Feb 25, 2020
35ccf5b
Merge remote-tracking branch 'upstream/2.0' into dev/nukkitx-standard…
DaMatrix Feb 25, 2020
0e57147
initial block replacer interface
DaMatrix Feb 25, 2020
77e60ea
load block replacers from registry
DaMatrix Feb 25, 2020
443fb3f
begin working on a noise generator registry as well
DaMatrix Feb 25, 2020
700ddc3
add a biome implementation
DaMatrix Feb 25, 2020
21746a5
we can now generate a world with surfaces
DaMatrix Feb 25, 2020
f274bc8
interpolate density values
DaMatrix Feb 25, 2020
f97a0a3
be able to use `BiomeMap` to actually select biomes
DaMatrix Feb 25, 2020
2ab5ad1
add populator registry as well
DaMatrix Feb 25, 2020
177a287
add "decorators" (basically populators, except at generation time)
DaMatrix Feb 26, 2020
12d3d0c
add simple tree populator
DaMatrix Feb 27, 2020
213a82e
make a system for matching an arbitrary number of block types with on…
DaMatrix Feb 27, 2020
f5384fe
make biome dictionary only contain IDs, everything else should be sep…
DaMatrix Feb 27, 2020
37e11d8
add simple surface decorator
DaMatrix Feb 27, 2020
39d3a0c
minor refactor (BlockMatcher to BlockFilter, add separate BlockMatche…
DaMatrix Feb 27, 2020
f7e4ed8
add block layers (i'll probably have to remove this again shortly)
DaMatrix Feb 28, 2020
d04a2be
begin migrating to jackson for loading generator config
DaMatrix Feb 29, 2020
27d15e4
okay this is a hell of a lot cleaner! begin porting everything to jac…
DaMatrix Feb 29, 2020
5a40454
everything except noise generation has now been ported to jackson
DaMatrix Feb 29, 2020
04c1f3a
noise generation loads with jackson now as well
DaMatrix Feb 29, 2020
608440b
allow overriding the local seed generation to ensure consistency
DaMatrix Feb 29, 2020
5bdce13
Merge remote-tracking branch 'upstream/2.0' into dev/nukkitx-standard…
DaMatrix Feb 29, 2020
604a497
Merge remote-tracking branch 'upstream/2.0' into dev/nukkitx-standard…
DaMatrix Mar 1, 2020
bc40d8e
theoretically be able to define biome-specific generation passes
DaMatrix Mar 1, 2020
fee16fb
actually implement biome-specific generation passes
DaMatrix Mar 2, 2020
4dc5950
prepare to implement vanilla noise
DaMatrix Mar 3, 2020
35f30cd
actually implement vanilla noise
DaMatrix Mar 3, 2020
6b0ec26
fix up biome generation heights
DaMatrix Mar 3, 2020
e0e1f4c
Merge remote-tracking branch 'upstream/2.0' into dev/nukkitx-standard…
DaMatrix Mar 4, 2020
731d438
break some stuff
DaMatrix Mar 5, 2020
26a996c
Merge remote-tracking branch 'upstream/2.0' into dev/nukkitx-standard…
DaMatrix Mar 5, 2020
d701883
theoretically make biome surface now be done using a block replacer i…
DaMatrix Mar 5, 2020
a4566d3
remove block replacers, because they add a lot of extra load for very…
DaMatrix Mar 5, 2020
64cdbda
make surfaces be generated using a decorator again, but this time do …
DaMatrix Mar 6, 2020
2066da9
implement basic tall grass populator and a block selection mechanism
DaMatrix Mar 6, 2020
74595ca
fix build
DaMatrix Mar 6, 2020
0a8abe3
set name in LevelConverter
DaMatrix Mar 6, 2020
bad5c77
implement vanilla-style flower generation
DaMatrix Mar 6, 2020
f22114d
make trees look nicer and add double plants
DaMatrix Mar 7, 2020
a05c6a3
begin working on implementing a decent biome selector
DaMatrix Mar 7, 2020
b59e94b
temp commit
DaMatrix Mar 8, 2020
b876373
Merge remote-tracking branch 'upstream/2.0' into dev/nukkitx-standard…
DaMatrix Mar 8, 2020
dd3f95a
implement biome selection zoom filter
DaMatrix Mar 8, 2020
c32ec2a
work on implementing more biome selection filters
DaMatrix Mar 9, 2020
dab54e8
stop trying to skid from vanilla and actually implement this myself, …
DaMatrix Mar 10, 2020
7a7a9e6
try and fail to make rivers
DaMatrix Mar 10, 2020
1b34764
something is very broken...
DaMatrix Mar 10, 2020
be99cb1
Merge remote-tracking branch 'upstream/2.0' into dev/nukkitx-standard…
DaMatrix Mar 14, 2020
f4bb0c2
fix biome selection artifacts when sampling at low resolutions
DaMatrix Mar 14, 2020
25ebc4a
try to fix biome generation heights part 1
DaMatrix Mar 14, 2020
7c67d93
try to fix biome generation heights part 2
DaMatrix Mar 14, 2020
f2e5010
revert previous changes
DaMatrix Mar 14, 2020
2c3e673
okay now i think i'm on the right track to fixing biome elevations
DaMatrix Mar 15, 2020
4553919
ores
DaMatrix Mar 15, 2020
27f0910
allow biomes to inherit from each other
DaMatrix Mar 17, 2020
4300a86
partially clean up trees
DaMatrix Mar 17, 2020
97ade38
Merge remote-tracking branch 'upstream/2.0' into dev/nukkitx-standard…
DaMatrix Mar 17, 2020
d932c2b
re-implement population around
DaMatrix Mar 18, 2020
7ee644d
Merge remote-tracking branch 'upstream/2.0' into dev/nukkitx-standard…
DaMatrix Mar 18, 2020
8ac5fcd
fix build
DaMatrix Mar 18, 2020
5df8345
spruce trees
DaMatrix Mar 18, 2020
d006744
partially make extreme hills ground cover correct
DaMatrix Mar 25, 2020
e0df32f
rename filtered to complex
DaMatrix Mar 26, 2020
d8cd9c6
make biome selection a lot like vanilla (part 1)
DaMatrix Mar 26, 2020
424aecf
Merge remote-tracking branch 'upstream/2.0' into dev/nukkitx-standard…
DaMatrix Mar 26, 2020
5bebfe0
make biome selection a lot like vanilla (part 2)
DaMatrix Mar 26, 2020
cdb5b41
make biome selection a lot like vanilla (part 3)
DaMatrix Mar 27, 2020
229a09b
make biome selection a lot like vanilla (part 4)
DaMatrix Mar 28, 2020
7687bf0
make biome selection a lot like vanilla (part 5)
DaMatrix Mar 28, 2020
fb9ccf4
make biome selection a lot like vanilla (part 6)
DaMatrix Mar 28, 2020
5023744
fully implement mushroom island and mushroom island shore
DaMatrix Mar 28, 2020
b21df7e
fully implement (frozen) river, (frozen) ocean, deep ocean
DaMatrix Mar 29, 2020
89d66d3
fully implement beach, stone beach, cold beach, fix generation of ext…
DaMatrix Mar 29, 2020
6d58c24
fully implement ice plains, ice plains spikes, ice mountains, fix gen…
DaMatrix Mar 29, 2020
78e4f51
fully implement (cold) taiga, (cold) taiga hills, (cold) taiga m
DaMatrix Mar 29, 2020
2ef99ba
fully implement mega taiga (hills), redwood taiga (hills)
DaMatrix Mar 30, 2020
aabd1f3
convert biome height variation from vanilla correctly
DaMatrix Mar 31, 2020
d9042f9
fully implement swampland (hills)
DaMatrix Mar 31, 2020
c943839
fully implement (flower) forest (hills), (tall) birch forest (hills)
DaMatrix Mar 31, 2020
a4b1b6c
Merge remote-tracking branch 'upstream/2.0' into dev/nukkitx-standard…
DaMatrix Mar 31, 2020
9bcaece
fully implement roofed forest (hills)
DaMatrix Mar 31, 2020
68e257a
fully implement (mutated) jungle (hills)
DaMatrix Apr 3, 2020
c542d30
fully implement (mutated) desert (hills)
DaMatrix Apr 3, 2020
2275e1c
fully implement (mutated) savanna (plateau)
DaMatrix Apr 3, 2020
f184656
fully implement (mutated) mesa (plateau)
DaMatrix Apr 4, 2020
97688bf
add all biomes to overworld biome selector and finalize overworld preset
DaMatrix Apr 4, 2020
24c34b8
add fallen trees
DaMatrix Apr 4, 2020
ffb7d35
make populators be per-block rather than per-chunk (part 1)
DaMatrix Apr 4, 2020
d9806c6
make populators be per-block rather than per-chunk (part 2)
DaMatrix Apr 4, 2020
b16b4ff
some minor things
DaMatrix Apr 5, 2020
e9447a1
try to implement end noise generation
DaMatrix Apr 5, 2020
d764d28
something something end terrain doesn't like me
DaMatrix Apr 11, 2020
a922d7d
Merge remote-tracking branch 'upstream/2.0' into dev/nukkitx-standard…
DaMatrix Apr 11, 2020
ce0e91e
this kind of almost works...
DaMatrix Apr 11, 2020
1aed528
finalize end density generation
DaMatrix Apr 11, 2020
c1ba6f9
add basic nether density source
DaMatrix Apr 13, 2020
729ce08
finalize nether terrain
DaMatrix Apr 14, 2020
a215fd4
mostly finalize end terrain
DaMatrix Apr 15, 2020
2a535b3
add water/lava lakes
DaMatrix Apr 15, 2020
ca4ce80
fix generation frequency of shrubs
DaMatrix Apr 15, 2020
655b4b2
partially fix empty chunks
DaMatrix Apr 16, 2020
59ad700
fix empty chunks for good
DaMatrix Apr 16, 2020
ad179fb
clean up+optimize chunk heightmap stuff somewhat and optimize chunk l…
DaMatrix Apr 16, 2020
17d1836
make the default preset be correct
DaMatrix Apr 16, 2020
1c37555
make generation+population a lot faster by caching biomes one chunk a…
DaMatrix Apr 16, 2020
2f67568
make density sources generate entire swaths at a time
DaMatrix Apr 17, 2020
f695a7a
make biomes actually have their own registry and eliminate "biome dic…
DaMatrix Apr 17, 2020
9d82740
implement "finish" pass for standard generator
DaMatrix Apr 17, 2020
2b8b491
fix ice/snow generation by actually using finishers correctly
DaMatrix Apr 17, 2020
8a63cff
stop randomly switching between the seed in config and the seed in le…
DaMatrix Apr 17, 2020
2ebbbeb
add an amplified preset
DaMatrix Apr 17, 2020
6ef998e
Merge remote-tracking branch 'upstream/2.0' into dev/nukkitx-standard…
DaMatrix Apr 17, 2020
9dd656f
add optimized swath implementations for overworld and end density sou…
DaMatrix Apr 18, 2020
cc82d75
make ice/snow generation altitude-based
DaMatrix Apr 18, 2020
e6c1687
fix up most of the TODOs
DaMatrix Apr 18, 2020
8705753
bake generation pass arrays once at the beginning, and use int keys i…
DaMatrix Apr 18, 2020
bcf120f
fix worlds config in default nukkit.yml
DaMatrix Apr 18, 2020
07380a2
make property naming more consistent
DaMatrix Apr 18, 2020
e45f86e
reformat
DaMatrix Apr 18, 2020
dc8209c
don't generate surface blocks one block below sea level
DaMatrix Apr 19, 2020
14f30d8
Merge remote-tracking branch 'upstream/2.0' into dev/nukkitx-standard…
DaMatrix Apr 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,4 @@ resource_packs
resource_packs/*
creativeitems.json
recipes.json
/run/
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.daporkchop.lib</groupId>
<artifactId>noise</artifactId>
<version>0.5.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.sf.jopt-simple</groupId>
<artifactId>jopt-simple</artifactId>
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/cn/nukkit/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import cn.nukkit.item.Item;
import cn.nukkit.item.enchantment.Enchantment;
import cn.nukkit.level.*;
import cn.nukkit.level.biome.EnumBiome;
import cn.nukkit.level.storage.StorageIds;
import cn.nukkit.locale.LocaleManager;
import cn.nukkit.locale.TextContainer;
Expand Down Expand Up @@ -81,6 +80,7 @@
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -197,6 +197,7 @@ public class Server {
private final BlockEntityRegistry blockEntityRegistry = BlockEntityRegistry.get();
private final ItemRegistry itemRegistry = ItemRegistry.get();
private final EntityRegistry entityRegistry = EntityRegistry.get();
private final BiomeRegistry biomeRegistry = BiomeRegistry.get();

private final Map<InetSocketAddress, Player> players = new HashMap<>();

Expand Down Expand Up @@ -520,6 +521,7 @@ public void boot() throws IOException {
this.blockRegistry.close();
this.itemRegistry.close();
this.entityRegistry.close();
this.biomeRegistry.close();
this.gameRuleRegistry.close();
this.generatorRegistry.close();
this.storageRegistry.close();
Expand Down Expand Up @@ -1893,7 +1895,6 @@ private void loadPacks() {

private void registerVanillaComponents() {
Enchantment.init();
EnumBiome.values(); //load class, this also registers biomes
Item.initCreativeItems();
Effect.init();
Potion.init();
Expand Down Expand Up @@ -1929,7 +1930,8 @@ private void loadLevels() {
Identifier generator = Identifier.fromString(this.getConfig("worlds." + name + ".generator"));
String options = this.getConfig("worlds." + name + ".options", "");

levelFutures.add(this.loadLevel().id(name).seed(seed)
levelFutures.add(this.loadLevel().id(name)
.seed(seed)
.generator(generator == null ? this.generatorRegistry.getFallback() : generator)
.generatorOptions(options)
.load());
Expand Down Expand Up @@ -1994,6 +1996,10 @@ public ItemRegistry getItemRegistry() {
return itemRegistry;
}

public GeneratorRegistry getGeneratorRegistry() {
return this.generatorRegistry;
}

public int getBaseTickRate() {
return baseTickRate;
}
Expand Down
78 changes: 39 additions & 39 deletions src/main/java/cn/nukkit/block/BlockCocoa.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,49 @@

import java.util.concurrent.ThreadLocalRandom;

import static cn.nukkit.block.BlockIds.LOG;
import static cn.nukkit.item.ItemIds.DYE;
import static cn.nukkit.block.BlockIds.*;
import static cn.nukkit.item.ItemIds.*;

/**
* Created by CreeperFace on 27. 10. 2016.
*/
public class BlockCocoa extends BlockTransparent implements Faceable {

protected static final AxisAlignedBB[] EAST = new SimpleAxisAlignedBB[]{new SimpleAxisAlignedBB(0.6875f, 0.4375f, 0.375f, 0.9375f, 0.75f, 0.625f), new SimpleAxisAlignedBB(0.5625f, 0.3125f, 0.3125f, 0.9375f, 0.75f, 0.6875f), new SimpleAxisAlignedBB(0.5625f, 0.3125f, 0.3125f, 0.9375f, 0.75f, 0.6875f)};
protected static final AxisAlignedBB[] WEST = new SimpleAxisAlignedBB[]{new SimpleAxisAlignedBB(0.0625f, 0.4375f, 0.375f, 0.3125f, 0.75f, 0.625f), new SimpleAxisAlignedBB(0.0625f, 0.3125f, 0.3125f, 0.4375f, 0.75f, 0.6875f), new SimpleAxisAlignedBB(0.0625f, 0.3125f, 0.3125f, 0.4375f, 0.75f, 0.6875f)};
protected static final AxisAlignedBB[] NORTH = new SimpleAxisAlignedBB[]{new SimpleAxisAlignedBB(0.375f, 0.4375f, 0.0625f, 0.625f, 0.75f, 0.3125f), new SimpleAxisAlignedBB(0.3125f, 0.3125f, 0.0625f, 0.6875f, 0.75f, 0.4375f), new SimpleAxisAlignedBB(0.3125f, 0.3125f, 0.0625f, 0.6875f, 0.75f, 0.4375f)};
protected static final AxisAlignedBB[] SOUTH = new SimpleAxisAlignedBB[]{new SimpleAxisAlignedBB(0.375f, 0.4375f, 0.6875f, 0.625f, 0.75f, 0.9375f), new SimpleAxisAlignedBB(0.3125f, 0.3125f, 0.5625f, 0.6875f, 0.75f, 0.9375f), new SimpleAxisAlignedBB(0.3125f, 0.3125f, 0.5625f, 0.6875f, 0.75f, 0.9375f)};
protected static final AxisAlignedBB[] ALL = new AxisAlignedBB[12];
protected static final AxisAlignedBB[] BB_NORTH = {
new SimpleAxisAlignedBB(0.375f, 0.4375f, 0.0625f, 0.625f, 0.75f, 0.3125f),
new SimpleAxisAlignedBB(0.3125f, 0.3125f, 0.0625f, 0.6875f, 0.75f, 0.4375f),
new SimpleAxisAlignedBB(0.3125f, 0.3125f, 0.0625f, 0.6875f, 0.75f, 0.4375f)
};
protected static final AxisAlignedBB[] BB_EAST = {
new SimpleAxisAlignedBB(0.6875f, 0.4375f, 0.375f, 0.9375f, 0.75f, 0.625f),
new SimpleAxisAlignedBB(0.5625f, 0.3125f, 0.3125f, 0.9375f, 0.75f, 0.6875f),
new SimpleAxisAlignedBB(0.5625f, 0.3125f, 0.3125f, 0.9375f, 0.75f, 0.6875f)
};
protected static final AxisAlignedBB[] BB_SOUTH = {
new SimpleAxisAlignedBB(0.375f, 0.4375f, 0.6875f, 0.625f, 0.75f, 0.9375f),
new SimpleAxisAlignedBB(0.3125f, 0.3125f, 0.5625f, 0.6875f, 0.75f, 0.9375f),
new SimpleAxisAlignedBB(0.3125f, 0.3125f, 0.5625f, 0.6875f, 0.75f, 0.9375f)
};
protected static final AxisAlignedBB[] BB_WEST = {
new SimpleAxisAlignedBB(0.0625f, 0.4375f, 0.375f, 0.3125f, 0.75f, 0.625f),
new SimpleAxisAlignedBB(0.0625f, 0.3125f, 0.3125f, 0.4375f, 0.75f, 0.6875f),
new SimpleAxisAlignedBB(0.0625f, 0.3125f, 0.3125f, 0.4375f, 0.75f, 0.6875f)
};
protected static final AxisAlignedBB[] BB_ALL = {
BB_NORTH[0], BB_EAST[0], BB_SOUTH[0], BB_WEST[0],
BB_NORTH[1], BB_EAST[1], BB_SOUTH[1], BB_WEST[1],
BB_NORTH[2], BB_EAST[2], BB_SOUTH[2], BB_WEST[2],
};

public static final int NORTH = 0;
public static final int EAST = 1;
public static final int SOUTH = 2;
public static final int WEST = 3;
public static final int DIR_MASK = 3;

public static final int STAGE_1 = 0;
public static final int STAGE_2 = 1;
public static final int STAGE_3 = 2;
public static final int STAGE_MASK = 12;

public BlockCocoa(Identifier id) {
super(id);
Expand Down Expand Up @@ -77,38 +107,8 @@ private AxisAlignedBB getRelativeBoundingBox() {
if (meta > 11) {
this.setMeta(meta = 11);
}
AxisAlignedBB boundingBox = ALL[meta];
if (boundingBox != null) return boundingBox;

AxisAlignedBB[] bbs;

switch (getMeta()) {
case 0:
case 4:
case 8:
bbs = NORTH;
break;
case 1:
case 5:
case 9:
bbs = EAST;
break;
case 2:
case 6:
case 10:
bbs = SOUTH;
break;
case 3:
case 7:
case 11:
bbs = WEST;
break;
default:
bbs = NORTH;
break;
}

return ALL[meta] = bbs[this.getMeta() >> 2];
return BB_ALL[meta];
}

@Override
Expand Down
32 changes: 24 additions & 8 deletions src/main/java/cn/nukkit/block/BlockGrass.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import cn.nukkit.event.block.BlockSpreadEvent;
import cn.nukkit.item.Item;
import cn.nukkit.level.Level;
import cn.nukkit.level.generator.object.ObjectTallGrass;
import cn.nukkit.level.particle.BoneMealParticle;
import cn.nukkit.math.BedrockRandom;
import cn.nukkit.math.NukkitRandom;
import cn.nukkit.player.Player;
import cn.nukkit.utils.BlockColor;
import cn.nukkit.utils.Identifier;
import com.nukkitx.math.vector.Vector3i;
import net.daporkchop.lib.random.PRandom;
import net.daporkchop.lib.random.impl.FastPRandom;

import java.util.concurrent.ThreadLocalRandom;

import static cn.nukkit.block.BlockIds.*;
import static cn.nukkit.item.ItemIds.DYE;
Expand Down Expand Up @@ -43,7 +44,23 @@ public boolean onActivate(Item item, Player player) {
item.decrementCount();
}
this.level.addParticle(new BoneMealParticle(this.getPosition()));
ObjectTallGrass.growGrass(this.getLevel(), this.getPosition(), new BedrockRandom());

PRandom random = new FastPRandom();

for (int i = 0; i < 64; i++) {
int blockY = this.getY() + random.nextInt(4) - random.nextInt(4);
if (blockY < 0 || blockY >= 255) {
continue;
}
int blockX = this.getX() + random.nextInt(8) - random.nextInt(8);
int blockZ = this.getZ() + random.nextInt(8) - random.nextInt(8);

Block tallGrass = Block.get(BlockIds.TALL_GRASS, 0, blockX, blockY + 1, blockZ, this.level);
Block toReplace = this.level.getBlock(blockX, blockY + 1, blockZ);
if (toReplace.getId() == BlockIds.AIR) {
tallGrass.place(null, toReplace, null, null, null, null);
}
}
return true;
} else if (item.isHoe()) {
item.useOn(this);
Expand All @@ -61,11 +78,10 @@ public boolean onActivate(Item item, Player player) {
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_RANDOM) {
NukkitRandom random = new NukkitRandom();
Vector3i pos = this.getPosition();
int x = random.nextRange(pos.getX() - 1, pos.getX() + 1);
int y = random.nextRange(pos.getY() - 2, pos.getY() + 2);
int z = random.nextRange(pos.getZ() - 1, pos.getZ() + 1);
int x = ThreadLocalRandom.current().nextInt(pos.getX() - 1, pos.getX() + 1);
int y = ThreadLocalRandom.current().nextInt(pos.getY() - 2, pos.getY() + 2);
int z = ThreadLocalRandom.current().nextInt(pos.getZ() - 1, pos.getZ() + 1);
Block block = this.getLevel().getBlock(x, y, z);
if (block.getId() == DIRT && block.getMeta() == 0) {
if (block.up() instanceof BlockAir) {
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/cn/nukkit/block/BlockHugeMushroomBrown.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@

import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.math.NukkitRandom;
import cn.nukkit.utils.BlockColor;
import cn.nukkit.utils.Identifier;

import java.util.concurrent.ThreadLocalRandom;

import static cn.nukkit.block.BlockIds.BROWN_MUSHROOM;

/**
* Created by Pub4Game on 28.01.2016.
*/
public class BlockHugeMushroomBrown extends BlockSolid {
public static final int NONE = 0;
public static final int TOP_NW = 1;
public static final int TOP_N = 2;
public static final int TOP_NE = 3;
public static final int TOP_W = 4;
public static final int TOP = 5;
public static final int TOP_E = 6;
public static final int TOP_SW = 7;
public static final int TOP_S = 8;
public static final int TOP_SE = 9;
public static final int STEM = 10;
public static final int ALL = 14;
public static final int STEM_ALL = 15;

public BlockHugeMushroomBrown(Identifier id) {
super(id);
Expand All @@ -34,7 +48,7 @@ public float getResistance() {

@Override
public Item[] getDrops(Item item) {
if (new NukkitRandom().nextRange(1, 20) == 0) {
if (ThreadLocalRandom.current().nextInt(0, 20) == 0) {
return new Item[]{
Item.get(BROWN_MUSHROOM)
};
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/cn/nukkit/block/BlockHugeMushroomRed.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@

import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.math.NukkitRandom;
import cn.nukkit.utils.BlockColor;
import cn.nukkit.utils.Identifier;

import java.util.concurrent.ThreadLocalRandom;

import static cn.nukkit.block.BlockIds.RED_MUSHROOM;

/**
* Created by Pub4Game on 28.01.2016.
*/
public class BlockHugeMushroomRed extends BlockSolid {
public static final int NONE = 0;
public static final int TOP_NW = 1;
public static final int TOP_N = 2;
public static final int TOP_NE = 3;
public static final int TOP_W = 4;
public static final int TOP = 5;
public static final int TOP_E = 6;
public static final int TOP_SW = 7;
public static final int TOP_S = 8;
public static final int TOP_SE = 9;
public static final int STEM = 10;
public static final int ALL = 14;
public static final int STEM_ALL = 15;

public BlockHugeMushroomRed(Identifier id) {
super(id);
Expand All @@ -34,7 +48,7 @@ public float getResistance() {

@Override
public Item[] getDrops(Item item) {
if (new NukkitRandom().nextRange(1, 20) == 0) {
if (ThreadLocalRandom.current().nextInt(0, 20) == 0) {
return new Item[]{
Item.get(RED_MUSHROOM)
};
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/cn/nukkit/block/BlockIds.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import lombok.experimental.UtilityClass;

@UtilityClass
public final class BlockIds {

public class BlockIds {
public static final Identifier AIR = Identifier.fromString("air");
public static final Identifier STONE = Identifier.fromString("stone");
public static final Identifier GRASS = Identifier.fromString("grass");
Expand Down Expand Up @@ -42,7 +41,6 @@ public final class BlockIds {
public static final Identifier PISTON = Identifier.fromString("piston");
public static final Identifier PISTON_ARM_COLLISION = Identifier.fromString("pistonArmCollision");
public static final Identifier WOOL = Identifier.fromString("wool");
// public static final Identifier ELEMENT_0 = Identifier.fromString("element_0");
public static final Identifier YELLOW_FLOWER = Identifier.fromString("yellow_flower");
public static final Identifier RED_FLOWER = Identifier.fromString("red_flower");
public static final Identifier BROWN_MUSHROOM = Identifier.fromString("brown_mushroom");
Expand Down Expand Up @@ -267,7 +265,8 @@ public final class BlockIds {
public static final Identifier STRIPPED_DARK_OAK_LOG = Identifier.fromString("stripped_dark_oak_log");
public static final Identifier STRIPPED_OAK_LOG = Identifier.fromString("stripped_oak_log");
public static final Identifier BLUE_ICE = Identifier.fromString("blue_ice");
// public static final Identifier ELEMENT_1 = Identifier.fromString("element_1");
// public static final Identifier ELEMENT_0 = Identifier.fromString("element_0");
// public static final Identifier ELEMENT_1 = Identifier.fromString("element_1");
// public static final Identifier ELEMENT_2 = Identifier.fromString("element_2");
// public static final Identifier ELEMENT_3 = Identifier.fromString("element_3");
// public static final Identifier ELEMENT_4 = Identifier.fromString("element_4");
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/cn/nukkit/block/BlockLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@
* Nukkit Project
*/
public class BlockLog extends BlockSolid {
public static final int OAK = 0;
public static final int OAK = 0;
public static final int SPRUCE = 1;
public static final int BIRCH = 2;
public static final int BIRCH = 2;
public static final int JUNGLE = 3;

public static final int UP_DOWN = 0 << 2;
public static final int EAST_WEST = 1 << 2;
public static final int NORTH_SOUTH = 2 << 2;
public static final int ALL = 3 << 2;

protected static final Identifier[] STRIPPED_IDS = new Identifier[]{
BlockIds.STRIPPED_OAK_LOG,
BlockIds.STRIPPED_SPRUCE_LOG,
Expand Down Expand Up @@ -107,7 +112,7 @@ public int getToolType() {

@Override
public BlockColor getColor() {
switch (getMeta() & 0x07) {
switch (getMeta() & 0x03) {
default:
case OAK:
return BlockColor.WOOD_BLOCK_COLOR;
Expand Down
Loading