Add hoe harvesting.

master
dragontamerfred 2019-10-04 19:01:03 +02:00
parent 12216e6e7e
commit b6740b9de3
5 changed files with 100 additions and 1 deletions

View File

@ -15,6 +15,8 @@ Currently included:
- 2 paper + 1 iron ingot -> 1 name tag
- 1 wool (any color) -> 4 string
- 3 leather + 2 string + 2 iron ingot -> 1 saddle
- 1 blue ice -> 9 packed ice
- 1 packed ice -> 9 ice
### Dropped seed planting
Automatically plants seed dropped on tilled soil.
@ -32,6 +34,9 @@ Allow players to shift right-click on any armor stand to swap armor with it.
### Nether sponge drying
Instantly dry wet sponges when they are placed in the nether.
### Hoe harvesting
When breaking crops with a hoe you break a range around them. This drastically speeds up manual harvesting of crop farms.
## Planned tweaks
- Dynamite
- Sign editing

View File

@ -0,0 +1,64 @@
package nl.kallestruik.vanillatweaks.HoeHarvesting;
import nl.kallestruik.vanillatweaks.config;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.data.Ageable;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
public class HoeHarvestingHandler implements Listener {
@EventHandler
public void onHoeBreaksBlock(BlockBreakEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
World world = block.getWorld();
ItemStack itemInHand = player.getInventory().getItemInMainHand();
int range;
if (itemInHand.getType() == Material.WOODEN_HOE)
range = config.HOE_HARVESTING_RANGE_WOOD;
else if (itemInHand.getType() == Material.STONE_HOE)
range = config.HOE_HARVESTING_RANGE_STONE;
else if (itemInHand.getType() == Material.IRON_HOE)
range = config.HOE_HARVESTING_RANGE_IRON;
else if (itemInHand.getType() == Material.GOLDEN_HOE)
range = config.HOE_HARVESTING_RANGE_GOLD;
else if (itemInHand.getType() == Material.DIAMOND_HOE)
range = config.HOE_HARVESTING_RANGE_DIAMOND;
else
return;
if (!isCrop(block.getType()))
return;
Location startLocation = block.getLocation();
for (int x = -range; x <= range; x++) {
for (int z = -range; z <= range; z++) {
Block b = world.getBlockAt(startLocation.clone().add(x, 0, z));
if (isCrop(b.getType())) {
Ageable ageable = (Ageable) b.getBlockData();
if (ageable.getAge() == ageable.getMaximumAge()) {
b.breakNaturally();
}
}
}
}
}
private static boolean isCrop(Material material) {
return material == Material.WHEAT ||
material == Material.BEETROOTS ||
material == Material.CARROTS ||
material == Material.POTATOES;
}
}

View File

@ -2,6 +2,7 @@ package nl.kallestruik.vanillatweaks;
import nl.kallestruik.vanillatweaks.ArmorStandSwapping.ArmorStandSwappingHandler;
import nl.kallestruik.vanillatweaks.CraftingTweaks.CraftingTweaks;
import nl.kallestruik.vanillatweaks.HoeHarvesting.HoeHarvestingHandler;
import nl.kallestruik.vanillatweaks.NetherSpongeDrying.NetherSpongeHandler;
import nl.kallestruik.vanillatweaks.SeedDropPlanting.SeedDropPlanting;
import nl.kallestruik.vanillatweaks.ToggleTrample.CommandToggletrample;
@ -47,6 +48,10 @@ public final class VanillaTweaks extends JavaPlugin {
getServer().getPluginManager().registerEvents(new NetherSpongeHandler(), this);
}
if (config.HOE_HARVESTING_ENABLED) {
getServer().getPluginManager().registerEvents(new HoeHarvestingHandler(), this);
}
} catch (IOException | InvalidConfigurationException | NullPointerException e) {
util.printException(e);
}

View File

@ -24,6 +24,13 @@ public class config {
public static boolean NETHER_SPONGE_DRYING_ENABLED;
public static boolean HOE_HARVESTING_ENABLED;
public static int HOE_HARVESTING_RANGE_WOOD;
public static int HOE_HARVESTING_RANGE_STONE;
public static int HOE_HARVESTING_RANGE_IRON;
public static int HOE_HARVESTING_RANGE_GOLD;
public static int HOE_HARVESTING_RANGE_DIAMOND;
public static void load(File file) throws IOException, InvalidConfigurationException {
if (!file.getParentFile().exists())
file.getParentFile().mkdirs();
@ -47,5 +54,14 @@ public class config {
ARMOR_STAND_SWAPPING_ENABLED = config.getBoolean("armor-stand-swapping.enabled");
NETHER_SPONGE_DRYING_ENABLED = config.getBoolean("nether-sponge-drying.enabled");
HOE_HARVESTING_ENABLED = config.getBoolean("hoe-harvesting.enabled");
HOE_HARVESTING_RANGE_WOOD = config.getInt("hoe-harvesting.ranges.wood");
HOE_HARVESTING_RANGE_STONE = config.getInt("hoe-harvesting.ranges.stone");
HOE_HARVESTING_RANGE_IRON = config.getInt("hoe-harvesting.ranges.iron");
HOE_HARVESTING_RANGE_GOLD = config.getInt("hoe-harvesting.ranges.gold");
HOE_HARVESTING_RANGE_DIAMOND = config.getInt("hoe-harvesting.ranges.diamond");
}
}

View File

@ -17,4 +17,13 @@ armor-stand-swapping:
enabled: true
nether-sponge-drying:
enabled: true
enabled: true
hoe-harvesting:
enabled: true
ranges:
wood: 1
stone: 1
iron: 1
gold: 1
diamond: 2