Add BowType metadata

This commit is contained in:
nossr50 2023-12-20 16:53:20 -08:00
parent 25952154e3
commit 23b8e0a28c
6 changed files with 41 additions and 8 deletions

View File

@ -1,4 +1,5 @@
Version 2.2.000
TODO: com/gmail/nossr50/database/FlatFileDatabaseManager.java:109 reporting data entries that need correction on each launch
TODO: Add Xbows/Tridents to salvage/repair
TODO: Add unit test for combat XP values
TODO: Add unit test to determine crossbow or bow skill

View File

@ -128,13 +128,21 @@ public class EntityListener implements Listener {
ItemStack bow = event.getBow();
if (bow != null
&& bow.containsEnchantment(Enchantment.ARROW_INFINITE)) {
if (bow == null)
return;
// determine if bow or crossbow
BowType bowType = ItemUtils.isCrossbow(bow) ? BowType.CROSSBOW : BowType.BOW;
if (bow.containsEnchantment(Enchantment.ARROW_INFINITE)) {
projectile.setMetadata(MetadataConstants.METADATA_KEY_INF_ARROW, MetadataConstants.MCMMO_METADATA_VALUE);
}
// Set BowType, Force, and Distance metadata
projectile.setMetadata(MetadataConstants.METADATA_KEY_BOW_TYPE, new FixedMetadataValue(pluginRef, bowType));
projectile.setMetadata(MetadataConstants.METADATA_KEY_BOW_FORCE, new FixedMetadataValue(pluginRef, Math.min(event.getForce() * mcMMO.p.getAdvancedConfig().getForceMultiplier(), 1.0)));
projectile.setMetadata(MetadataConstants.METADATA_KEY_ARROW_DISTANCE, new FixedMetadataValue(pluginRef, projectile.getLocation()));
//Cleanup metadata in 1 minute in case normal collection falls through
CombatUtils.delayArrowMetaCleanup((Projectile) projectile);
}

View File

@ -0,0 +1,6 @@
package com.gmail.nossr50.util;
public enum BowType {
BOW,
CROSSBOW
}

View File

@ -14,6 +14,7 @@ public class MetadataConstants {
* Take great care if you ever modify the value of these keys
*/
public static final @NotNull String METADATA_KEY_REPLANT = "mcMMO: Recently Replanted";
public static final @NotNull String METADATA_KEY_BOW_TYPE = "mcMMO: Bow Type";
public static final @NotNull String METADATA_KEY_EXPLOSION_FROM_RUPTURE = "mcMMO: Rupture Explosion";
public static final @NotNull String METADATA_KEY_FISH_HOOK_REF = "mcMMO: Fish Hook Tracker";
public static final @NotNull String METADATA_KEY_DODGE_TRACKER = "mcMMO: Dodge Tracker";

View File

@ -481,17 +481,23 @@ public final class CombatUtils {
Projectile arrow = (Projectile) painSource;
ProjectileSource projectileSource = arrow.getShooter();
if (projectileSource instanceof Player player && mcMMO.p.getSkillTools().canCombatSkillsTrigger(PrimarySkillType.ARCHERY, target)) {
// TODO: Add metadata to projectiles to determine source weapon to process combat skills
if (projectileSource instanceof Player player) {
BowType bowType = getBowTypeFromMetadata(arrow);
if (!Misc.isNPCEntityExcludingVillagers(player) && mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.ARCHERY)) {
processArcheryCombat(target, player, event, arrow);
if (!Misc.isNPCEntityExcludingVillagers(player)) {
if(bowType == BowType.BOW && mcMMO.p.getSkillTools().canCombatSkillsTrigger(PrimarySkillType.ARCHERY, target)) {
processArcheryCombat(target, player, event, arrow);
} else if(bowType == BowType.CROSSBOW && mcMMO.p.getSkillTools().canCombatSkillsTrigger(PrimarySkillType.CROSSBOWS, target)) {
processCrossbowsCombat(target, player, event, arrow);
}
} else {
//Cleanup Arrow
cleanupArrowMetadata(arrow);
}
if (target.getType() != EntityType.CREEPER && !Misc.isNPCEntityExcludingVillagers(player) && mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.TAMING)) {
if (target.getType() != EntityType.CREEPER
&& !Misc.isNPCEntityExcludingVillagers(player)
&& mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(player, PrimarySkillType.TAMING)) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if(mcMMOPlayer == null)
@ -502,7 +508,18 @@ public final class CombatUtils {
}
}
}
}
private static BowType getBowTypeFromMetadata(Projectile projectile) {
// Return the BowType from the metadata, or default to BOW
if (projectile.hasMetadata(MetadataConstants.METADATA_KEY_BOW_TYPE)) {
List<MetadataValue> metadataValue = projectile.getMetadata(MetadataConstants.METADATA_KEY_BOW_TYPE);
if (!metadataValue.isEmpty()) {
return (BowType) metadataValue.get(0).value();
}
}
throw new IllegalStateException("BowType metadata is empty");
}
/**

View File

@ -72,10 +72,10 @@ class WoodcuttingTest extends MMOTestEnvironment {
woodcuttingManager.processBonusDropCheck(blockState);
// verify bonus drops were spawned
// TODO: Can fail if triple drops happen, need to update test
Mockito.verify(woodcuttingManager, Mockito.times(1)).spawnHarvestLumberBonusDrops(blockState);
}
@Test
void harvestLumberShouldNotDoubleDrop() {
mmoPlayer.modifySkill(PrimarySkillType.WOODCUTTING, 0);