diff --git a/build.gradle b/build.gradle index 9d339e9..b900a68 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } group 'no.hyp' -version '1.3.0' +version '1.3.1' sourceCompatibility = 1.16 targetCompatibility = 1.16 diff --git a/src/main/java/no/hyp/farmingupgrade/FarmingUpgradePlugin.java b/src/main/java/no/hyp/farmingupgrade/FarmingUpgradePlugin.java index 2131027..3dc5557 100644 --- a/src/main/java/no/hyp/farmingupgrade/FarmingUpgradePlugin.java +++ b/src/main/java/no/hyp/farmingupgrade/FarmingUpgradePlugin.java @@ -214,7 +214,7 @@ static ImmutableList readTools(ConfigurationSection configurati @Nullable var materialString = toolSection.getString("material"); @Nullable var material = materialString != null ? Material.matchMaterial(materialString) : null; @Nullable var lore = toolSection.getString("lore"); - var radius = toolSection.getInt("radius"); + var radius = toolSection.getDouble("radius"); var damage = toolSection.getInt("damage"); tools.add(new HarvestToolType(material, lore, radius, damage)); } @@ -374,12 +374,12 @@ void harvestSwingParticles(Player player) { } int calculateRadius(HarvestToolType toolType, ItemStack toolItem) { - var radius = 0; + var radius = 0.0; radius += toolType.radius(); var efficiencyRangePerLevel = configuration().harvestRadiusPerEfficiencyLevel(); radius += toolItem.getEnchantmentLevel(Enchantment.DIG_SPEED) * efficiencyRangePerLevel; radius = Math.min(10, radius); // Do not allow the radius to crash the server. - return radius; + return (int) radius; } /** @@ -398,68 +398,67 @@ boolean harvestCrop(Player player, Block block, ItemStack tool, boolean replant, callingBlockBreakEvent = true; Bukkit.getServer().getPluginManager().callEvent(upgradedEvent); callingBlockBreakEvent = false; - if (!upgradedEvent.isCancelled()) { - // A state representing the crop after the harvest. - BlockState state = block.getState(); - // Calculate drops depending on tool. - Collection itemDrops = block.getDrops(tool); - // Break the crop and spawn effects. - FarmingUpgradePlugin.breakBlockEffect(block, state, Sound.BLOCK_CROP_BREAK); - block.setType(Material.AIR); - - // Whether a seed has been collected for replanting. - boolean seedFound = false; - GameMode mode = player.getGameMode(); - // Drop items in survival. - if (upgradedEvent.isDropItems() && mode != GameMode.CREATIVE) { - // Search for a seed to replant the crop with if replanting is enabled. - if (replant) { - for (ItemStack itemDrop : itemDrops) { - // If replanting is enabled, and a seed is not found yet, search for one in this ItemStack. - if (!seedFound) { - int amount = itemDrop.getAmount(); - if (itemDrop.getType() == seed && amount >= 1) { - itemDrop.setAmount(amount - 1); - seedFound = true; - } + if (upgradedEvent.isCancelled()) return false; + // A state representing the crop after the harvest. + BlockState state = block.getState(); + // Calculate drops depending on tool. + Collection itemDrops = block.getDrops(tool); + // Break the crop and spawn effects. + FarmingUpgradePlugin.breakBlockEffect(block, state, Sound.BLOCK_CROP_BREAK); + block.setType(Material.AIR); + + // Whether a seed has been collected for replanting. + boolean seedFound = false; + GameMode mode = player.getGameMode(); + // Drop items in survival. + if (upgradedEvent.isDropItems() && mode != GameMode.CREATIVE) { + // Search for a seed to replant the crop with if replanting is enabled. + if (replant) { + for (ItemStack itemDrop : itemDrops) { + // If replanting is enabled, and a seed is not found yet, search for one in this ItemStack. + if (!seedFound) { + int amount = itemDrop.getAmount(); + if (itemDrop.getType() == seed && amount >= 1) { + itemDrop.setAmount(amount - 1); + seedFound = true; } } } - // If collect is enabled, items are sent to the inventory if there is space. - if (collect) { - Inventory inventory = player.getInventory(); - Set notAddedItems = new HashSet<>(); - for (ItemStack item : itemDrops) { - notAddedItems.addAll(inventory.addItem(item).values()); - } - itemDrops = notAddedItems; - //player.playSound(player.getLocation(), Sound.ENTITY_ITEM_PICKUP, 0.2f, 1.0f + random.nextFloat()); - } - // Calculate the dropped item entities. - List drops = new ArrayList<>(); - for (ItemStack itemDrop : itemDrops) { - if (itemDrop.getType().isItem() && itemDrop.getType() != Material.AIR && itemDrop.getAmount() >= 1) { - drops.add(block.getWorld().dropItemNaturally(block.getLocation(), itemDrop)); - } + } + // If collect is enabled, items are sent to the inventory if there is space. + if (collect) { + Inventory inventory = player.getInventory(); + Set notAddedItems = new HashSet<>(); + for (ItemStack item : itemDrops) { + notAddedItems.addAll(inventory.addItem(item).values()); } - // Send a BlockDropItemEvent for the drops. - List copy = Lists.newArrayList(drops); - BlockDropItemEvent dropEvent = new BlockDropItemEvent(block, state, player, copy); - Bukkit.getServer().getPluginManager().callEvent(dropEvent); - // Kill those items that were removed from the copied drop list, or all of them - // if the event is cancelled. - if (dropEvent.isCancelled()) { - copy.clear(); + itemDrops = notAddedItems; + //player.playSound(player.getLocation(), Sound.ENTITY_ITEM_PICKUP, 0.2f, 1.0f + random.nextFloat()); + } + // Calculate the dropped item entities. + List drops = new ArrayList<>(); + for (ItemStack itemDrop : itemDrops) { + if (itemDrop.getType().isItem() && itemDrop.getType() != Material.AIR && itemDrop.getAmount() >= 1) { + drops.add(block.getWorld().dropItemNaturally(block.getLocation(), itemDrop)); } - for (Item drop : drops) { - if (!copy.contains(drop)) { - drop.remove(); - } + } + // Send a BlockDropItemEvent for the drops. + List copy = Lists.newArrayList(drops); + BlockDropItemEvent dropEvent = new BlockDropItemEvent(block, state, player, copy); + Bukkit.getServer().getPluginManager().callEvent(dropEvent); + // Kill those items that were removed from the copied drop list, or all of them + // if the event is cancelled. + if (dropEvent.isCancelled()) { + copy.clear(); + } + for (Item drop : drops) { + if (!copy.contains(drop)) { + drop.remove(); } } - if (mode == GameMode.CREATIVE && replant) seedFound = true; // A crop is always replanted in creative mode. - if (seedFound) block.setType(state.getType()); // Replant the crop if the conditions are satisfied. } + if (mode == GameMode.CREATIVE && replant) seedFound = true; // A crop is always replanted in creative mode. + if (seedFound) block.setType(state.getType()); // Replant the crop if the conditions are satisfied. return true; } @@ -998,7 +997,7 @@ public static Optional findHighestMaterial(Collection materials return Optional.empty(); } - record HarvestToolType(@Nullable Material material, @Nullable String lore, int radius, int damage) { } + record HarvestToolType(@Nullable Material material, @Nullable String lore, double radius, int damage) { } record ReplantableCrop(Material crop, @Nullable Material seeds) { } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ee06294..3ef98ee 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -13,6 +13,7 @@ harvest: upgrade: true # A list of harvesting tools, their harvest radiï and the damage they take from harvesting crops. Note that if an item # has the unbreakable item attribute, it will never take any damage. + # The radius is a decimal, but is rounded down when used to find surrounding blocks. # The first entry that applies to an item, is the one that is used to determine radius and damage. If no entry applies # to an item, then the item is not a harvesting tool. An entry may only apply to an item with the same material. If an # entry has no material, then it may apply to an item with any material. An entry may only apply to an item which has @@ -21,29 +22,29 @@ harvest: tools: # # Fake enchantments # - lore: Harvest I -# radius: 2 +# radius: 1.5 # damage: 1 # - lore: Harvest II -# radius: 3 +# radius: 2.5 # damage: 1 # Hoes - material: WOODEN_HOE - radius: 0 + radius: 0.5 damage: 1 - material: STONE_HOE - radius: 0 + radius: 0.5 damage: 1 - material: IRON_HOE - radius: 1 + radius: 1.5 damage: 1 - material: GOLDEN_HOE - radius: 1 + radius: 1.5 damage: 1 - material: DIAMOND_HOE - radius: 2 + radius: 2.5 damage: 1 - material: NETHERITE_HOE - radius: 2 + radius: 2.5 damage: 1 # Swords - material: WOODEN_SWORD @@ -65,7 +66,7 @@ harvest: radius: 0 damage: 2 # Harvest radius increase from each level of the efficiency enchantment. A double whose product is rounded down. - radiusPerEfficiencyLevel: 0.4 + radiusPerEfficiencyLevel: 0.3 # The unbreaking enchantment has a chance to prevent hoes from taking damage when breaking crops. applyUnbreaking: true # Harvesting tools only break mature crops. diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 136d36d..50d247f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: FarmingUpgrade author: Torm description: Upgraded farming mechanics. -version: 1.3.0 +version: 1.3.1 main: no.hyp.farmingupgrade.FarmingUpgradePlugin api-version: 1.16 permissions: