mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-07-30 19:15:28 +02:00
Fix bug where Green Thumb did not replant if seeds were solely in the offhand Fixes #4994
This commit is contained in:
@@ -33,6 +33,7 @@ import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.Ageable;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -41,6 +42,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.gmail.nossr50.util.ItemUtils.hasItemIncludingOffHand;
|
||||
import static com.gmail.nossr50.util.ItemUtils.removeItemIncludingOffHand;
|
||||
|
||||
public class HerbalismManager extends SkillManager {
|
||||
public HerbalismManager(McMMOPlayer mcMMOPlayer) {
|
||||
super(mcMMOPlayer, PrimarySkillType.HERBALISM);
|
||||
@@ -745,13 +749,14 @@ public class HerbalismManager extends SkillManager {
|
||||
* @param blockState The {@link BlockState} to check ability activation for
|
||||
* @param greenTerra boolean to determine if greenTerra is active or not
|
||||
*/
|
||||
private boolean processGreenThumbPlants(BlockState blockState, BlockBreakEvent blockBreakEvent, boolean greenTerra) {
|
||||
private boolean processGreenThumbPlants(@NotNull BlockState blockState, @NotNull BlockBreakEvent blockBreakEvent,
|
||||
boolean greenTerra) {
|
||||
if (!ItemUtils.isHoe(blockBreakEvent.getPlayer().getInventory().getItemInMainHand())
|
||||
&& !ItemUtils.isAxe(blockBreakEvent.getPlayer().getInventory().getItemInMainHand())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BlockData blockData = blockState.getBlockData();
|
||||
final BlockData blockData = blockState.getBlockData();
|
||||
|
||||
if (!(blockData instanceof Ageable ageable)) {
|
||||
return false;
|
||||
@@ -759,47 +764,28 @@ public class HerbalismManager extends SkillManager {
|
||||
|
||||
//If the ageable is NOT mature and the player is NOT using a hoe, abort
|
||||
|
||||
Player player = getPlayer();
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
Material seed;
|
||||
final Player player = getPlayer();
|
||||
final Material replantMaterial;
|
||||
|
||||
switch (blockState.getType().getKey().getKey().toLowerCase(Locale.ROOT)) {
|
||||
case "carrots":
|
||||
seed = Material.matchMaterial("CARROT");
|
||||
break;
|
||||
|
||||
case "wheat":
|
||||
seed = Material.matchMaterial("WHEAT_SEEDS");
|
||||
break;
|
||||
|
||||
case "nether_wart":
|
||||
seed = Material.getMaterial("NETHER_WART");
|
||||
break;
|
||||
|
||||
case "potatoes":
|
||||
seed = Material.matchMaterial("POTATO");
|
||||
break;
|
||||
|
||||
case "beetroots":
|
||||
seed = Material.matchMaterial("BEETROOT_SEEDS");
|
||||
break;
|
||||
|
||||
case "cocoa":
|
||||
seed = Material.matchMaterial("COCOA_BEANS");
|
||||
break;
|
||||
|
||||
case "torchflower":
|
||||
seed = Material.matchMaterial("TORCHFLOWER_SEEDS");
|
||||
break;
|
||||
default:
|
||||
switch (blockState.getType().getKey().getKey().toLowerCase(Locale.ENGLISH)) {
|
||||
case "carrots" -> replantMaterial = Material.matchMaterial("CARROT");
|
||||
case "wheat" -> replantMaterial = Material.matchMaterial("WHEAT_SEEDS");
|
||||
case "nether_wart" -> replantMaterial = Material.getMaterial("NETHER_WART");
|
||||
case "potatoes" -> replantMaterial = Material.matchMaterial("POTATO");
|
||||
case "beetroots" -> replantMaterial = Material.matchMaterial("BEETROOT_SEEDS");
|
||||
case "cocoa" -> replantMaterial = Material.matchMaterial("COCOA_BEANS");
|
||||
case "torchflower" -> replantMaterial = Material.matchMaterial("TORCHFLOWER_SEEDS");
|
||||
default -> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ItemStack seedStack = new ItemStack(seed);
|
||||
if (replantMaterial == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ItemUtils.isAxe(blockBreakEvent.getPlayer().getInventory().getItemInMainHand())
|
||||
&& blockState.getType() != Material.COCOA) {
|
||||
&& blockState.getType() != Material.COCOA) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -807,25 +793,25 @@ public class HerbalismManager extends SkillManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!playerInventory.containsAtLeast(seedStack, 1)) {
|
||||
if (!hasItemIncludingOffHand(player, replantMaterial)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!processGrowingPlants(blockState, ageable, blockBreakEvent, greenTerra)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(EventUtils.callSubSkillBlockEvent(player, SubSkillType.HERBALISM_GREEN_THUMB, blockState.getBlock()).isCancelled()) {
|
||||
if(EventUtils.callSubSkillBlockEvent(player, SubSkillType.HERBALISM_GREEN_THUMB, blockState.getBlock())
|
||||
.isCancelled()) {
|
||||
return false;
|
||||
} else {
|
||||
playerInventory.removeItem(seedStack);
|
||||
player.updateInventory(); // Needed until replacement available
|
||||
if (!processGrowingPlants(blockState, ageable, blockBreakEvent, greenTerra)) {
|
||||
return false;
|
||||
}
|
||||
// remove the item from the player's inventory
|
||||
removeItemIncludingOffHand(player, replantMaterial, 1);
|
||||
// player.updateInventory(); // Needed until replacement available
|
||||
|
||||
//Play sound
|
||||
SoundManager.sendSound(player, player.getLocation(), SoundType.ITEM_CONSUMED);
|
||||
return true;
|
||||
}
|
||||
|
||||
// new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0);
|
||||
}
|
||||
|
||||
private boolean processGrowingPlants(BlockState blockState, Ageable ageable, BlockBreakEvent blockBreakEvent, boolean greenTerra) {
|
||||
|
Reference in New Issue
Block a user