mirror of
				https://github.com/mcMMO-Dev/mcMMO.git
				synced 2025-11-04 02:53:43 +01:00 
			
		
		
		
	Add BowType metadata
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										6
									
								
								src/main/java/com/gmail/nossr50/util/BowType.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src/main/java/com/gmail/nossr50/util/BowType.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
package com.gmail.nossr50.util;
 | 
			
		||||
 | 
			
		||||
public enum BowType {
 | 
			
		||||
    BOW,
 | 
			
		||||
    CROSSBOW
 | 
			
		||||
}
 | 
			
		||||
@@ -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";
 | 
			
		||||
 
 | 
			
		||||
@@ -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)) {
 | 
			
		||||
                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");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user