Compare commits

...

2 Commits

Author SHA1 Message Date
Thiago Gebrim f0691e494d fixes 2024-04-21 17:49:09 -03:00
Thiago Gebrim 9093ab24fd fixes 2024-04-21 17:10:32 -03:00
1 changed files with 35 additions and 8 deletions

View File

@ -765,21 +765,27 @@ public class HerbalismManager extends SkillManager {
case "carrots": case "carrots":
seed = Material.matchMaterial("CARROT"); seed = Material.matchMaterial("CARROT");
break; break;
case "wheat": case "wheat":
seed = Material.matchMaterial("WHEAT_SEEDS"); seed = Material.matchMaterial("WHEAT_SEEDS");
break; break;
case "nether_wart": case "nether_wart":
seed = Material.matchMaterial("NETHER_WART"); seed = Material.getMaterial("NETHER_WART");
break; break;
case "potatoes": case "potatoes":
seed = Material.matchMaterial("POTATO"); seed = Material.matchMaterial("POTATO");
break; break;
case "beetroots": case "beetroots":
seed = Material.matchMaterial("BEETROOT_SEEDS"); seed = Material.matchMaterial("BEETROOT_SEEDS");
break; break;
case "cocoa": case "cocoa":
seed = Material.matchMaterial("COCOA_BEANS"); seed = Material.matchMaterial("COCOA_BEANS");
break; break;
case "torchflower": case "torchflower":
seed = Material.matchMaterial("TORCHFLOWER_SEEDS"); seed = Material.matchMaterial("TORCHFLOWER_SEEDS");
break; break;
@ -798,7 +804,8 @@ public class HerbalismManager extends SkillManager {
return false; return false;
} }
if (!playerInventory.contains(seedStack)) { // Check for seeds in both the main hand and off-hand
if (!(playerInventory.containsAtLeast(seedStack, 1) || playerInventory.getItemInOffHand().getType() == seed)) {
NotificationManager.sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET, "Skills.NeedMore", StringUtils.getPrettyItemString(seed)); NotificationManager.sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET, "Skills.NeedMore", StringUtils.getPrettyItemString(seed));
return false; return false;
} }
@ -807,20 +814,40 @@ public class HerbalismManager extends SkillManager {
return false; return false;
} }
// Check if the event should be cancelled based on the sub-skill block event
if (EventUtils.callSubSkillBlockEvent(player, SubSkillType.HERBALISM_GREEN_THUMB, blockState.getBlock()).isCancelled()) { if (EventUtils.callSubSkillBlockEvent(player, SubSkillType.HERBALISM_GREEN_THUMB, blockState.getBlock()).isCancelled()) {
return false; return false;
} else { } else {
playerInventory.removeItem(new ItemStack(seed, 1)); boolean seedFound = false;
// Retrieve all contents from the player's inventory
ItemStack[] inventoryContents = player.getInventory().getContents();
player.updateInventory(); // Iterate through each item in the inventory to find the seed
for (ItemStack item : inventoryContents) {
if (item != null && item.getType() == seed) {
item.setAmount(item.getAmount() - 1); // Decrement the amount of the seed
if (item.getAmount() <= 0) {
item.setType(Material.AIR); // Completely remove the item if the count goes to zero
}
seedFound = true;
break; // Stop the loop once the seed is found and modified
}
}
if (!seedFound) {
return false; // Return false if the seed was not found in the inventory
}
player.updateInventory(); // Update the player's inventory to reflect changes
// Play a sound effect to indicate the item was consumed
SoundManager.sendSound(player, player.getLocation(), SoundType.ITEM_CONSUMED); SoundManager.sendSound(player, player.getLocation(), SoundType.ITEM_CONSUMED);
return true;
}
// new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0); return true; // Return true to indicate the operation was successful
}
} }
private boolean processGrowingPlants(BlockState blockState, Ageable ageable, BlockBreakEvent blockBreakEvent, boolean greenTerra) { private boolean processGrowingPlants(BlockState blockState, Ageable ageable, BlockBreakEvent blockBreakEvent, boolean greenTerra) {
//This check is needed //This check is needed
if(isBizarreAgeable(ageable)) { if(isBizarreAgeable(ageable)) {
@ -889,4 +916,4 @@ public class HerbalismManager extends SkillManager {
return RankUtils.getRank(getPlayer(), SubSkillType.HERBALISM_GREEN_THUMB); return RankUtils.getRank(getPlayer(), SubSkillType.HERBALISM_GREEN_THUMB);
} }
} }