forked from CloudburstMC/Nukkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlockMushroom.java
More file actions
112 lines (90 loc) · 2.93 KB
/
BlockMushroom.java
File metadata and controls
112 lines (90 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.level.Level;
import cn.nukkit.level.generator.object.mushroom.BigMushroom;
import cn.nukkit.level.particle.BoneMealParticle;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.NukkitRandom;
import cn.nukkit.utils.BlockColor;
import cn.nukkit.utils.DyeColor;
import java.util.concurrent.ThreadLocalRandom;
public abstract class BlockMushroom extends BlockFlowable {
public BlockMushroom() {
this(0);
}
public BlockMushroom(int meta) {
super(0);
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
if (!canStay()) {
getLevel().useBreakOn(this);
return Level.BLOCK_UPDATE_NORMAL;
}
}
return 0;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
if (block instanceof BlockWater || block.level.isBlockWaterloggedAt(block.getChunk(), (int) block.x, (int) block.y, (int) block.z)) {
return false;
}
if (canStay()) {
getLevel().setBlock(block, this, true, true);
return true;
}
return false;
}
@Override
public boolean canBeActivated() {
return true;
}
@Override
public boolean onActivate(Item item, Player player) {
if (item.getId() == Item.DYE && item.getDamage() == DyeColor.WHITE.getDyeData()) {
if (player != null && !player.isCreative()) {
item.count--;
}
if (ThreadLocalRandom.current().nextFloat() < 0.4) {
this.grow();
}
this.level.addParticle(new BoneMealParticle(this));
return true;
}
return false;
}
public boolean grow() {
this.level.setBlock(this, Block.get(BlockID.AIR), true, true);
BigMushroom generator = new BigMushroom(getType());
if (generator.generate(this.level, new NukkitRandom(), this)) {
return true;
} else {
this.level.setBlock(this, this, true, false);
return false;
}
}
public boolean canStay() {
Block block = this.down();
return block.getId() == MYCELIUM || block.getId() == PODZOL || (!block.isTransparent() && this.level.getBlockLightAt((int) this.x, (int) this.y, (int) this.z) < 13); // TODO: sky/full light
}
@Override
public BlockColor getColor() {
return BlockColor.FOLIAGE_BLOCK_COLOR;
}
@Override
public boolean canSilkTouch() {
return true;
}
protected abstract int getType();
@Override
public boolean breakWhenPushed() {
return true;
}
@Override
public Item toItem() {
return new ItemBlock(Block.get(this.getId(), 0), 0);
}
}