Skip to content

Commit e7021d0

Browse files
authored
Make flowers and DoublePlants break like vanilla (#2247)
1 parent 4b77baf commit e7021d0

3 files changed

Lines changed: 39 additions & 8 deletions

File tree

src/main/java/cn/nukkit/block/BlockDoublePlant.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import cn.nukkit.item.Item;
55
import cn.nukkit.item.ItemBlock;
66
import cn.nukkit.item.ItemDye;
7+
import cn.nukkit.item.ItemTool;
78
import cn.nukkit.level.Level;
89
import cn.nukkit.level.particle.BoneMealParticle;
10+
import cn.nukkit.level.particle.DestroyBlockParticle;
911
import cn.nukkit.math.BlockFace;
1012
import cn.nukkit.utils.BlockColor;
1113

@@ -100,9 +102,13 @@ public boolean onBreak(Item item) {
100102
if ((this.getDamage() & TOP_HALF_BITMASK) == TOP_HALF_BITMASK) { // Top half
101103
Block down = down();
102104
if (down instanceof BlockDoublePlant) {
103-
this.getLevel().useBreakOn(down);
105+
this.getLevel().useBreakOn(down, item, null, true);
104106
}
105107
} else {
108+
Block up = up();
109+
if (up instanceof BlockDoublePlant) {
110+
this.getLevel().addParticle(new DestroyBlockParticle(this.add(0.5, 1), this));
111+
}
106112
this.getLevel().setBlock(this, Block.get(BlockID.AIR), true, true);
107113
}
108114

@@ -176,4 +182,14 @@ public boolean onActivate(Item item, Player player) {
176182
public Item toItem() {
177183
return new ItemBlock(this, this.getDamage() & 0x07, 1);
178184
}
185+
186+
@Override
187+
public int getToolType() {
188+
return ItemTool.TYPE_SHEARS;
189+
}
190+
191+
@Override
192+
public boolean breakWhenPushed() {
193+
return true;
194+
}
179195
}

src/main/java/cn/nukkit/block/BlockFlower.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import cn.nukkit.Player;
44
import cn.nukkit.item.Item;
55
import cn.nukkit.item.ItemDye;
6+
import cn.nukkit.item.ItemTool;
67
import cn.nukkit.level.Level;
78
import cn.nukkit.level.particle.BoneMealParticle;
89
import cn.nukkit.math.BlockFace;
@@ -135,6 +136,11 @@ protected Block getUncommonFlower() {
135136
return get(DANDELION);
136137
}
137138

139+
@Override
140+
public int getToolType() {
141+
return ItemTool.TYPE_SHEARS;
142+
}
143+
138144
@Override
139145
public boolean breakWhenPushed() {
140146
return true;

src/main/java/cn/nukkit/item/ItemTool.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,26 @@ public boolean useOn(Block block) {
7676
block.getToolType() == ItemTool.TYPE_HOE && this.isHoe() ||
7777
block.getToolType() == ItemTool.TYPE_SWORD && this.isSword() ||
7878
block.getToolType() == ItemTool.TYPE_SHEARS && this.isShears()
79-
) {
79+
) {
8080
this.meta++;
81-
} else if (this.isSword() && block.getHardness() > 0) {
81+
return true;
82+
}
83+
84+
if (this.isSword() && block.getHardness() > 0) {
8285
this.meta += 2;
83-
} else if (this.isHoe()) {
84-
if (block.getId() == GRASS || block.getId() == DIRT) {
85-
this.meta++;
86-
}
87-
} else {
86+
return true;
87+
}
88+
89+
if (this.isHoe() && ((block.getId() == GRASS || block.getId() == DIRT))) {
8890
this.meta++;
91+
return true;
92+
}
93+
94+
if (block.getId() == TALL_GRASS || block.getId() == FLOWER || block.getId() == DOUBLE_PLANT) {
95+
return true;
8996
}
97+
98+
this.meta++;
9099
return true;
91100
}
92101

0 commit comments

Comments
 (0)