Skip to content

Commit 5b67aa0

Browse files
committed
support for various new additions from 1.21.5
1 parent 3578528 commit 5b67aa0

File tree

5 files changed

+88
-103
lines changed

5 files changed

+88
-103
lines changed

Changelog.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
Version 2.2.035
2+
Support for new additions from Minecraft 1.21.5
3+
Added 'Bush' to experience.yml for Herbalism
4+
Added 'Bush' to config.yml Bonus Drops for Herbalism
5+
Added 'Cactus_Flower' to experience.yml for Herbalism
6+
Added 'Cactus_Flower' to config.yml Bonus Drops for Herbalism
7+
Added 'Firefly_Bush' to experience.yml for Herbalism
8+
Added 'Firefly_Bush' to config.yml Bonus Drops for Herbalism
9+
Added 'Leaf_Litter' to experience.yml for Herbalism
10+
Added 'Leaf_Litter' to config.yml Bonus Drops for Herbalism
11+
Added 'Short_Dry_Grass' to experience.yml for Herbalism
12+
Added 'Short_Dry_Grass' to config.yml Bonus Drops for Herbalism
13+
Added 'Tall_Dry_Grass' to experience.yml for Herbalism
14+
Added 'Tall_Dry_Grass' to config.yml Bonus Drops for Herbalism
15+
Added 'Wildflowers' to experience.yml for Herbalism
16+
Added 'Wildflowers' to config.yml Bonus Drops for Herbalism
217
Swords subskill Stab is now configurable in advanced.yml
318
Added 'Skills.Swords.Stab.Base_Damage' to advanced.yml
419
Added 'Skills.Swords.Stab.Per_Rank_Multiplier' to advanced.yml
520

621
NOTES:
22+
The mob variants will use the "base" mob definition for values for now, such a a warm chicken using chicken values from experience.yml
723
The new config settings will be added automatically to advanced.yml
824

925
Version 2.2.034

src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java

Lines changed: 57 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@
5050
public class HerbalismManager extends SkillManager {
5151
private final static HashMap<String, Integer> plantBreakLimits;
5252

53+
private static final String CACTUS_STR = "cactus";
54+
private static final String CACTUS_FLOWER_STR = "cactus_flower";
55+
5356
static {
5457
plantBreakLimits = new HashMap<>();
55-
plantBreakLimits.put("cactus", 3);
58+
plantBreakLimits.put(CACTUS_STR, 3);
5659
plantBreakLimits.put("bamboo", 20);
5760
plantBreakLimits.put("sugar_cane", 3);
5861
plantBreakLimits.put("kelp", 26);
@@ -68,10 +71,13 @@ public boolean canGreenThumbBlock(BlockState blockState) {
6871
if (!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.HERBALISM_GREEN_THUMB))
6972
return false;
7073

71-
Player player = getPlayer();
72-
ItemStack item = player.getInventory().getItemInMainHand();
74+
final Player player = getPlayer();
75+
final ItemStack item = player.getInventory().getItemInMainHand();
7376

74-
return item.getAmount() > 0 && item.getType() == Material.WHEAT_SEEDS && BlockUtils.canMakeMossy(blockState) && Permissions.greenThumbBlock(player, blockState.getType());
77+
return item.getAmount() > 0
78+
&& item.getType() == Material.WHEAT_SEEDS
79+
&& BlockUtils.canMakeMossy(blockState.getBlock())
80+
&& Permissions.greenThumbBlock(player, blockState.getType());
7581
}
7682

7783
public boolean canUseShroomThumb(BlockState blockState) {
@@ -163,10 +169,6 @@ public boolean canUseHylianLuck() {
163169
return Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.HERBALISM_HYLIAN_LUCK);
164170
}
165171

166-
public boolean canGreenTerraBlock(BlockState blockState) {
167-
return mmoPlayer.getAbilityMode(SuperAbilityType.GREEN_TERRA) && BlockUtils.canMakeMossy(blockState);
168-
}
169-
170172
public boolean canActivateAbility() {
171173
return mmoPlayer.getToolPreparationMode(ToolType.HOE) && Permissions.greenTerra(getPlayer());
172174
}
@@ -222,9 +224,9 @@ public void processGreenTerraBlockConversion(Block block) {
222224
* @param blockBreakEvent The Block Break Event to process
223225
*/
224226
public void processHerbalismBlockBreakEvent(BlockBreakEvent blockBreakEvent) {
225-
Player player = getPlayer();
227+
final Player player = getPlayer();
226228

227-
Block block = blockBreakEvent.getBlock();
229+
final Block block = blockBreakEvent.getBlock();
228230

229231
if (mcMMO.p.getGeneralConfig().getHerbalismPreventAFK() && player.isInsideVehicle()) {
230232
if (block.hasMetadata(MetadataConstants.METADATA_KEY_REPLANT)) {
@@ -235,7 +237,7 @@ public void processHerbalismBlockBreakEvent(BlockBreakEvent blockBreakEvent) {
235237

236238
//Check if the plant was recently replanted
237239
if (block.getBlockData() instanceof Ageable ageableCrop) {
238-
if (block.getMetadata(MetadataConstants.METADATA_KEY_REPLANT).size() >= 1) {
240+
if (!block.getMetadata(MetadataConstants.METADATA_KEY_REPLANT).isEmpty()) {
239241
if (block.getMetadata(MetadataConstants.METADATA_KEY_REPLANT).get(0).asBoolean()) {
240242
if (isAgeableMature(ageableCrop)) {
241243
block.removeMetadata(MetadataConstants.METADATA_KEY_REPLANT, mcMMO.p);
@@ -254,9 +256,9 @@ public void processHerbalismBlockBreakEvent(BlockBreakEvent blockBreakEvent) {
254256
*/
255257

256258
//Grab all broken blocks
257-
HashSet<Block> brokenBlocks = getBrokenHerbalismBlocks(blockBreakEvent);
259+
final HashSet<Block> brokenBlocks = getBrokenHerbalismBlocks(blockBreakEvent);
258260

259-
if (brokenBlocks.size() == 0)
261+
if (brokenBlocks.isEmpty())
260262
return;
261263

262264
//Handle rewards, xp, ability interactions, etc
@@ -272,7 +274,8 @@ private void processHerbalismOnBlocksBroken(BlockBreakEvent blockBreakEvent, Has
272274
if (blockBreakEvent.isCancelled())
273275
return;
274276

275-
BlockState originalBreak = blockBreakEvent.getBlock().getState();
277+
final BlockState originalBreak = blockBreakEvent.getBlock().getState();
278+
// TODO: Storing this boolean for no reason, refactor
276279
boolean greenThumbActivated = false;
277280

278281
//TODO: The design of Green Terra needs to change, this is a mess
@@ -322,12 +325,12 @@ private void processHerbalismOnBlocksBroken(BlockBreakEvent blockBreakEvent, Has
322325
}
323326

324327
//Give out XP to the non-chorus blocks
325-
if (noDelayPlantBlocks.size() > 0) {
328+
if (!noDelayPlantBlocks.isEmpty()) {
326329
//Note: Will contain 1 chorus block if the original block was a chorus block, this is to prevent delays for the XP bar
327330
awardXPForPlantBlocks(noDelayPlantBlocks);
328331
}
329332

330-
if (delayedChorusBlocks.size() > 0) {
333+
if (!delayedChorusBlocks.isEmpty()) {
331334
//Check XP for chorus blocks
332335
DelayedHerbalismXPCheckTask delayedHerbalismXPCheckTask = new DelayedHerbalismXPCheckTask(mmoPlayer, delayedChorusBlocks);
333336

@@ -356,15 +359,9 @@ public void checkDoubleDropsOnBrokenPlants(Player player, Collection<Block> brok
356359

357360
//Check for double drops
358361
if (!mcMMO.getUserBlockTracker().isIneligible(brokenPlant)) {
359-
360362
/*
361-
*
362363
* Natural Blocks
363-
*
364-
*
365-
*
366364
*/
367-
368365
//Not all things that are natural should give double drops, make sure its fully mature as well
369366
if (plantData instanceof Ageable ageable) {
370367

@@ -378,13 +375,9 @@ public void checkDoubleDropsOnBrokenPlants(Player player, Collection<Block> brok
378375
markForBonusDrops(brokenPlant);
379376
}
380377
} else {
381-
382378
/*
383-
*
384379
* Unnatural Blocks
385-
*
386380
*/
387-
388381
//If it's a crop, we need to reward XP when its fully grown
389382
if (isAgeableAndFullyMature(plantData) && !isBizarreAgeable(plantData)) {
390383
//Add metadata to mark this block for double or triple drops
@@ -401,7 +394,7 @@ public void checkDoubleDropsOnBrokenPlants(Player player, Collection<Block> brok
401394
*/
402395
public boolean isBizarreAgeable(BlockData blockData) {
403396
if (blockData instanceof Ageable) {
404-
//Catcus and Sugar Canes cannot be trusted
397+
// Cactus and Sugar Canes cannot be trusted
405398
return switch (blockData.getMaterial()) {
406399
case CACTUS, KELP, SUGAR_CANE, BAMBOO -> true;
407400
default -> false;
@@ -440,12 +433,8 @@ public void awardXPForPlantBlocks(HashSet<Block> brokenPlants) {
440433

441434
if (mcMMO.getUserBlockTracker().isIneligible(brokenBlockNewState)) {
442435
/*
443-
*
444436
* Unnatural Blocks
445-
*
446-
*
447437
*/
448-
449438
//If its a Crop we need to reward XP when its fully grown
450439
if (isAgeableAndFullyMature(plantData) && !isBizarreAgeable(plantData)) {
451440
xpToReward += ExperienceConfig.getInstance().getXp(PrimarySkillType.HERBALISM, brokenBlockNewState.getType());
@@ -457,13 +446,9 @@ public void awardXPForPlantBlocks(HashSet<Block> brokenPlants) {
457446
mcMMO.getUserBlockTracker().setEligible(brokenBlockNewState);
458447
} else {
459448
/*
460-
*
461449
* Natural Blocks
462-
*
463-
*
464450
*/
465-
466-
//Calculate XP
451+
// Calculate XP
467452
if (plantData instanceof Ageable plantAgeable) {
468453

469454
if (isAgeableMature(plantAgeable) || isBizarreAgeable(plantData)) {
@@ -481,15 +466,14 @@ public void awardXPForPlantBlocks(HashSet<Block> brokenPlants) {
481466
}
482467

483468
if (mmoPlayer.isDebugMode()) {
484-
mmoPlayer.getPlayer().sendMessage("Plants processed: "+brokenPlants.size());
469+
mmoPlayer.getPlayer().sendMessage("Plants processed: " + brokenPlants.size());
485470
}
486471

487472
//Reward XP
488473
if (xpToReward > 0) {
489474
// get first block from hash set using stream API
490475
final Block firstBlock = brokenPlants.stream().findFirst().orElse(null);
491476
if (firstBlock != null
492-
&& firstXpReward != -1
493477
&& ExperienceConfig.getInstance().limitXPOnTallPlants()
494478
&& plantBreakLimits.containsKey(firstBlock.getType().getKey().getKey())) {
495479
int limit = plantBreakLimits.get(firstBlock.getType().getKey().getKey()) * firstXpReward;
@@ -501,16 +485,6 @@ public void awardXPForPlantBlocks(HashSet<Block> brokenPlants) {
501485
}
502486
}
503487

504-
private int getNaturalGrowthLimit(Material brokenPlant) {
505-
// This is an exploit counter-measure to prevent players from growing unnaturally tall plants and reaping XP
506-
if (plantBreakLimits.containsKey(brokenPlant.getKey().getKey())) {
507-
return plantBreakLimits.get(brokenPlant.getKey().getKey());
508-
} else {
509-
return 0;
510-
}
511-
}
512-
513-
514488
public boolean isAgeableMature(Ageable ageable) {
515489
return ageable.getAge() == ageable.getMaximumAge()
516490
&& ageable.getAge() != 0;
@@ -529,7 +503,7 @@ public void awardXPForBlockSnapshots(ArrayList<BlockSnapshot> brokenPlants) {
529503
int blocksGivingXP = 0;
530504

531505
for(BlockSnapshot blockSnapshot : brokenPlants) {
532-
BlockState brokenBlockNewState = blockSnapshot.getBlockRef().getState();
506+
final BlockState brokenBlockNewState = blockSnapshot.getBlockRef().getState();
533507

534508
//Remove metadata from the snapshot of blocks
535509
if (brokenBlockNewState.hasMetadata(MetadataConstants.METADATA_KEY_BONUS_DROPS)) {
@@ -570,65 +544,66 @@ public void awardXPForBlockSnapshots(ArrayList<BlockSnapshot> brokenPlants) {
570544
*/
571545
private HashSet<Block> getBrokenHerbalismBlocks(@NotNull BlockBreakEvent blockBreakEvent) {
572546
//Get an updated capture of this block
573-
BlockState originBlockState = blockBreakEvent.getBlock().getState();
574-
Material originBlockMaterial = originBlockState.getType();
575-
HashSet<Block> blocksBroken = new HashSet<>(); //Blocks broken
547+
final BlockState originBlockState = blockBreakEvent.getBlock().getState();
548+
final Material originBlockMaterial = originBlockState.getType();
549+
final HashSet<Block> blocksBroken = new HashSet<>(); //Blocks broken
576550

577551
//Add the initial block
578552
blocksBroken.add(originBlockState.getBlock());
579553

580554
if (!isOneBlockPlant(originBlockMaterial)) {
581555
//If the block is a multi-block structure, capture a set of all blocks broken and return that
582-
blocksBroken = getBrokenBlocksMultiBlockPlants(originBlockState);
556+
addBrokenBlocksMultiBlockPlants(originBlockState, blocksBroken);
583557
}
584558

585559
//Return all broken plant-blocks
586560
return blocksBroken;
587561
}
588562

589-
private HashSet<Block> getBrokenChorusBlocks(BlockState originalBreak) {
590-
return grabChorusTreeBrokenBlocksRecursive(originalBreak.getBlock(), new HashSet<>());
591-
}
592-
593-
private HashSet<Block> grabChorusTreeBrokenBlocksRecursive(Block currentBlock, HashSet<Block> traversed) {
563+
private void addChorusTreeBrokenBlocks(Block currentBlock, Set<Block> traversed) {
594564
if (!isChorusTree(currentBlock.getType()))
595-
return traversed;
565+
return;
596566

597567
// Prevent any infinite loops, who needs more than 256 chorus anyways
598568
if (traversed.size() > 256)
599-
return traversed;
569+
return;
600570

601571
if (!traversed.add(currentBlock))
602-
return traversed;
572+
return;
603573

604574
//Grab all Blocks in the Tree
605575
for (BlockFace blockFace : new BlockFace[] { BlockFace.UP, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST ,BlockFace.WEST})
606-
grabChorusTreeBrokenBlocksRecursive(currentBlock.getRelative(blockFace, 1), traversed);
607-
608-
traversed.add(currentBlock);
609-
610-
return traversed;
576+
addChorusTreeBrokenBlocks(currentBlock.getRelative(blockFace, 1), traversed);
611577
}
612578

613-
/**
614-
* Grab a set of all plant blocks that are broken as a result of this event
615-
* The method to grab these blocks is a bit hacky and does not hook into the API
616-
* Basically we expect the blocks to be broken if this event is not cancelled and we determine which block are broken on our end rather than any event state captures
617-
*
618-
* @return a set of plant-blocks broken from this event
619-
*/
620-
protected HashSet<Block> getBrokenBlocksMultiBlockPlants(BlockState brokenBlock) {
621-
//Track the broken blocks
622-
HashSet<Block> brokenBlocks;
623579

580+
protected void addBrokenBlocksMultiBlockPlants(BlockState brokenBlock, Set<Block> brokenBlocks) {
624581
if (isChorusBranch(brokenBlock.getType())) {
625-
brokenBlocks = getBrokenChorusBlocks(brokenBlock);
582+
addChorusTreeBrokenBlocks(brokenBlock.getBlock(), brokenBlocks);
583+
} else if (isCactus(brokenBlock.getType())) {
584+
addCactusBlocks(brokenBlock.getBlock(), brokenBlocks);
626585
} else {
627-
brokenBlocks = getBlocksBrokenAboveOrBelow(
628-
brokenBlock, false, mcMMO.getMaterialMapStore().isMultiBlockHangingPlant(brokenBlock.getType()));
586+
addBlocksBrokenAboveOrBelow(brokenBlock.getBlock(), brokenBlocks, mcMMO.getMaterialMapStore().isMultiBlockHangingPlant(brokenBlock.getType()));
629587
}
588+
}
589+
590+
private void addCactusBlocks(Block currentBlock, Set<Block> traversed) {
591+
if (!isCactus(currentBlock.getType()))
592+
return;
593+
594+
if (traversed.size() > 4) // Max size 3 cactus + flower
595+
return;
630596

631-
return brokenBlocks;
597+
if (!traversed.add(currentBlock))
598+
return;
599+
600+
addCactusBlocks(currentBlock.getRelative(BlockFace.UP), traversed);
601+
addCactusBlocks(currentBlock.getRelative(BlockFace.DOWN), traversed);
602+
}
603+
604+
private boolean isCactus(Material material) {
605+
return material.getKey().getKey().equalsIgnoreCase(CACTUS_STR)
606+
|| material.getKey().getKey().equalsIgnoreCase(CACTUS_FLOWER_STR);
632607
}
633608

634609
private boolean isChorusBranch(Material blockType) {
@@ -639,43 +614,22 @@ private boolean isChorusTree(Material blockType) {
639614
return blockType == Material.CHORUS_PLANT || blockType == Material.CHORUS_FLOWER;
640615
}
641616

642-
/**
643-
* Grabs blocks upwards from a target block
644-
* A lot of Plants/Crops in Herbalism only break vertically from a broken block
645-
* The vertical search returns early if it runs into anything that is not a multi-block plant
646-
* Multi-block plants are hard-coded and kept in {@link MaterialMapStore}
647-
*
648-
* @param originBlock The point of the "break"
649-
* @param inclusive Whether to include the origin block
650-
* @param below Whether to search down instead of up.
651-
* @return A set of blocks above the target block which can be assumed to be broken
652-
*/
653-
private HashSet<Block> getBlocksBrokenAboveOrBelow(BlockState originBlock, boolean inclusive, boolean below) {
654-
HashSet<Block> brokenBlocks = new HashSet<>();
655-
Block block = originBlock.getBlock();
656-
657-
//Add the initial block to the set
658-
if (inclusive)
659-
brokenBlocks.add(block);
660-
617+
private void addBlocksBrokenAboveOrBelow(Block originBlock, Set<Block> brokenBlocks, boolean below) {
661618
//Limit our search
662619
int maxHeight = 512;
663620

664621
final BlockFace relativeFace = below ? BlockFace.DOWN : BlockFace.UP;
665622

666623
// Search vertically for multi-block plants, exit early if any non-multi block plants
667624
for (int y = 0; y < maxHeight; y++) {
668-
//TODO: Should this grab state? It would be more expensive..
669-
Block relativeBlock = block.getRelative(relativeFace, y);
625+
final Block relativeBlock = originBlock.getRelative(relativeFace, y);
670626

671627
//Abandon our search if the block isn't multi
672628
if (isOneBlockPlant(relativeBlock.getType()))
673629
break;
674630

675631
brokenBlocks.add(relativeBlock);
676632
}
677-
678-
return brokenBlocks;
679633
}
680634

681635
/**

src/main/java/com/gmail/nossr50/util/MaterialMapStore.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,7 @@ public boolean isFood(@NotNull Material material) {
10031003
private void fillMultiBlockPlantSet() {
10041004
//Multi-Block Plants
10051005
multiBlockPlant.add("cactus");
1006+
multiBlockPlant.add("cactus_flower");
10061007
multiBlockPlant.add("chorus_plant");
10071008
multiBlockPlant.add("chorus_flower");
10081009
multiBlockPlant.add("sugar_cane");

0 commit comments

Comments
 (0)