continued work on lumber-axe
This commit is contained in:
parent
534be2bd67
commit
c3b90f4df1
4 changed files with 204 additions and 5 deletions
|
@ -90,7 +90,7 @@ public class LumberAxe
|
||||||
ItemMeta diamondLumAxeMeta = diamondLumberAxe.getItemMeta();
|
ItemMeta diamondLumAxeMeta = diamondLumberAxe.getItemMeta();
|
||||||
|
|
||||||
// Define lore
|
// Define lore
|
||||||
String loreString = "Based off of item from PowerMining/Tinkers' Construct";
|
String loreString = "Based off of item from Tinkers' Construct";
|
||||||
List<String> lore = new ArrayList<String>() {{ add(loreString); }};
|
List<String> lore = new ArrayList<String>() {{ add(loreString); }};
|
||||||
woodLumAxeMeta.setLore(lore);
|
woodLumAxeMeta.setLore(lore);
|
||||||
stoneLumAxeMeta.setLore(lore);
|
stoneLumAxeMeta.setLore(lore);
|
||||||
|
|
|
@ -33,6 +33,10 @@ public class BlockListener implements Listener
|
||||||
gcPlugin.getServer().getPluginManager().registerEvents(this, gcPlugin);
|
gcPlugin.getServer().getPluginManager().registerEvents(this, gcPlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the breaking of blocks via the hammer/excavator
|
||||||
|
* @param bbEvent The event that triggered this method
|
||||||
|
*/
|
||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
public void Break(BlockBreakEvent bbEvent)
|
public void Break(BlockBreakEvent bbEvent)
|
||||||
{
|
{
|
||||||
|
@ -60,13 +64,13 @@ public class BlockListener implements Listener
|
||||||
PlayerInteractListener pListener = gcPlugin.GetPlayerInteractListener();
|
PlayerInteractListener pListener = gcPlugin.GetPlayerInteractListener();
|
||||||
BlockFace blockFace = pListener.GetFaceByName(pName);
|
BlockFace blockFace = pListener.GetFaceByName(pName);
|
||||||
|
|
||||||
// getDurability deprecated, must now go through meta information
|
// Grab durability information
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
Damageable dMeta = (Damageable)meta;
|
Damageable dMeta = (Damageable)meta;
|
||||||
int currDur = dMeta.getDamage();
|
int currDur = dMeta.getDamage();
|
||||||
int maxDur = item.getType().getMaxDurability();
|
int maxDur = item.getType().getMaxDurability();
|
||||||
|
|
||||||
// Used in determining if an extra block was broken
|
// Used in determining if an extra block was broken (for durability)
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
|
|
||||||
// Iterates through to break surrounding blocks
|
// Iterates through to break surrounding blocks
|
||||||
|
@ -108,4 +112,70 @@ public class BlockListener implements Listener
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the breaking of blocks via the lumber-axe
|
||||||
|
* @param bbEvent The event that triggered this method
|
||||||
|
*/
|
||||||
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
|
public void Chop(BlockBreakEvent bbEvent)
|
||||||
|
{
|
||||||
|
// Grab current tool information
|
||||||
|
Player player = bbEvent.getPlayer();
|
||||||
|
ItemStack item = player.getInventory().getItemInMainHand();
|
||||||
|
Material itemType = item.getType();
|
||||||
|
|
||||||
|
// Only do extra block-breaking if the player is not sneaking (method of disabling) or if the player doesn't have the appropriate tools
|
||||||
|
if (player != null && (player instanceof Player))
|
||||||
|
{
|
||||||
|
if (player.isSneaking())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!ToolUtil.IsLumberAxe(item))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get block information via the player listener
|
||||||
|
Block block = bbEvent.getBlock();
|
||||||
|
|
||||||
|
// Grab durability information
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
Damageable dMeta = (Damageable)meta;
|
||||||
|
int currDur = dMeta.getDamage();
|
||||||
|
int maxDur = item.getType().getMaxDurability();
|
||||||
|
|
||||||
|
// Used in determining if an extra block was broken (for durability)
|
||||||
|
boolean success = false;
|
||||||
|
|
||||||
|
for (Block b : ToolUtil.GetUpwardLogs(block))
|
||||||
|
{
|
||||||
|
// Determine the block type and position
|
||||||
|
Material blockMat = b.getType();
|
||||||
|
Location blockLoc = b.getLocation();
|
||||||
|
|
||||||
|
// Determine whether an appropriate tool is being used
|
||||||
|
boolean isAxe = ToolUtil.IsLumberAxeable(item, blockMat);
|
||||||
|
|
||||||
|
if (isAxe)
|
||||||
|
{
|
||||||
|
success = true;
|
||||||
|
b.breakNaturally();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do extra damage to durability if extra blocks were broken
|
||||||
|
if (success && !item.getEnchantments().containsKey(Enchantment.DURABILITY))
|
||||||
|
{
|
||||||
|
int addToDamage = 2;
|
||||||
|
if (itemType == Material.DIAMOND_PICKAXE && itemType == Material.DIAMOND_SHOVEL)
|
||||||
|
{
|
||||||
|
addToDamage = 1;
|
||||||
|
}
|
||||||
|
dMeta.setDamage(currDur + addToDamage);
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,26 @@ public class BlockRef
|
||||||
add(Material.SOUL_SAND);
|
add(Material.SOUL_SAND);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of all valid lumber-axe blocks (must be a log that stacks upward)
|
||||||
|
*/
|
||||||
|
public static ArrayList<Material> ValidLumberAxeBlocks = new ArrayList<Material>()
|
||||||
|
{{
|
||||||
|
add(Material.ACACIA_LOG);
|
||||||
|
add(Material.BIRCH_LOG);
|
||||||
|
add(Material.DARK_OAK_LOG);
|
||||||
|
add(Material.JUNGLE_LOG);
|
||||||
|
add(Material.OAK_LOG);
|
||||||
|
add(Material.SPRUCE_LOG);
|
||||||
|
|
||||||
|
add(Material.STRIPPED_ACACIA_LOG);
|
||||||
|
add(Material.STRIPPED_BIRCH_LOG);
|
||||||
|
add(Material.STRIPPED_DARK_OAK_LOG);
|
||||||
|
add(Material.STRIPPED_JUNGLE_LOG);
|
||||||
|
add(Material.STRIPPED_OAK_LOG);
|
||||||
|
add(Material.STRIPPED_SPRUCE_LOG);
|
||||||
|
}};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of all valid hammers (pickaxes)
|
* A list of all valid hammers (pickaxes)
|
||||||
*/
|
*/
|
||||||
|
@ -93,4 +113,16 @@ public class BlockRef
|
||||||
add(Material.GOLDEN_SHOVEL);
|
add(Material.GOLDEN_SHOVEL);
|
||||||
add(Material.DIAMOND_SHOVEL);
|
add(Material.DIAMOND_SHOVEL);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of all valid lumber-axes (axes)
|
||||||
|
*/
|
||||||
|
public static ArrayList<Material> ValidLumberAxes = new ArrayList<Material>()
|
||||||
|
{{
|
||||||
|
add(Material.WOODEN_AXE);
|
||||||
|
add(Material.STONE_AXE);
|
||||||
|
add(Material.IRON_AXE);
|
||||||
|
add(Material.GOLDEN_AXE);
|
||||||
|
add(Material.DIAMOND_AXE);
|
||||||
|
}};
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package lightling.gibsoniacraft.util;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
@ -37,8 +38,18 @@ public class ToolUtil
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether an item is a valid hammer
|
* Determines whether a block is axe-able
|
||||||
* @param mat The material being checked
|
* @param mat The material being checked
|
||||||
|
* @return Whether the block is axe-able
|
||||||
|
*/
|
||||||
|
public static boolean IsAxeable(Material mat)
|
||||||
|
{
|
||||||
|
return BlockRef.ValidLumberAxeBlocks.contains(mat);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether an item is a valid hammer
|
||||||
|
* @param item The item being checked
|
||||||
* @return Whether the item is a valid hammer
|
* @return Whether the item is a valid hammer
|
||||||
*/
|
*/
|
||||||
public static boolean IsHammer(ItemStack item)
|
public static boolean IsHammer(ItemStack item)
|
||||||
|
@ -53,7 +64,7 @@ public class ToolUtil
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether an item is a valid excavator
|
* Determines whether an item is a valid excavator
|
||||||
* @param mat The material being checked
|
* @param item The item being checked
|
||||||
* @return Whether the item is a valid excavator
|
* @return Whether the item is a valid excavator
|
||||||
*/
|
*/
|
||||||
public static boolean IsExcavator(ItemStack item)
|
public static boolean IsExcavator(ItemStack item)
|
||||||
|
@ -66,6 +77,21 @@ public class ToolUtil
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether an item is a valid lumber-axe
|
||||||
|
* @param item The item being checked
|
||||||
|
* @return Whether the item is a valid lumber-axe
|
||||||
|
*/
|
||||||
|
public static boolean IsLumberAxe(ItemStack item)
|
||||||
|
{
|
||||||
|
List<String> lore = item.getLore();
|
||||||
|
Material mat = item.getType();
|
||||||
|
if (lore != null && mat != null)
|
||||||
|
return BlockRef.ValidLumberAxes.contains(mat) && lore.contains("Based off of item from Tinkers' Construct");
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether a valid hammer can take place
|
* Determines whether a valid hammer can take place
|
||||||
* @param ham The item that should be a hammer
|
* @param ham The item that should be a hammer
|
||||||
|
@ -88,6 +114,17 @@ public class ToolUtil
|
||||||
return IsDiggable(block) && IsExcavator(exc);
|
return IsDiggable(block) && IsExcavator(exc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether a valid lumber-axe execution can take place
|
||||||
|
* @param axe The item that should be a lumber-axe
|
||||||
|
* @param block The block that should be axe-able
|
||||||
|
* @return Valid or invalid action
|
||||||
|
*/
|
||||||
|
public static boolean IsLumberAxeable(ItemStack axe, Material block)
|
||||||
|
{
|
||||||
|
return IsAxeable(block) && IsLumberAxe(axe);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Grabs the surrounding blocks in the world from the one that was mined/dug, and adds them to a list
|
* Grabs the surrounding blocks in the world from the one that was mined/dug, and adds them to a list
|
||||||
* @param blockFace The face that was targeted (changes the direction of the 3x3 grid)
|
* @param blockFace The face that was targeted (changes the direction of the 3x3 grid)
|
||||||
|
@ -155,6 +192,66 @@ public class ToolUtil
|
||||||
return blocks;
|
return blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ArrayList<Block> GetUpwardLogs(Block target)
|
||||||
|
{
|
||||||
|
// Create the list to work with
|
||||||
|
ArrayList<Block> blocks = new ArrayList<Block>();
|
||||||
|
|
||||||
|
// Reference the world-space
|
||||||
|
World world = target.getWorld();
|
||||||
|
|
||||||
|
// Determine the anchor XYZ coordinates
|
||||||
|
int x = target.getX();
|
||||||
|
int y = target.getY();
|
||||||
|
int z = target.getZ();
|
||||||
|
|
||||||
|
// Create control for loop
|
||||||
|
boolean moreBlocks = true;
|
||||||
|
|
||||||
|
// Grab all logs in a tree
|
||||||
|
do
|
||||||
|
{
|
||||||
|
// Variable that ends loop if remains 0
|
||||||
|
int blocksAbove = 0;
|
||||||
|
|
||||||
|
// Grab the surrounding blocks that may be wood
|
||||||
|
for (int i = -2; i <= 2; i++)
|
||||||
|
{
|
||||||
|
for (int j = -2; j <= 2; j++)
|
||||||
|
{
|
||||||
|
// Add all the surrounding logs to the list
|
||||||
|
Block temp = world.getBlockAt(x + i, y, z + j);
|
||||||
|
if (BlockRef.ValidLumberAxeBlocks.contains(temp.getType()))
|
||||||
|
{
|
||||||
|
blocks.add(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine if there are still blocks left
|
||||||
|
Block tempAbove = world.getBlockAt(x + i, y + 1, z + j);
|
||||||
|
if (BlockRef.ValidLumberAxeBlocks.contains(temp.getType()))
|
||||||
|
{
|
||||||
|
blocksAbove++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there are still blocks left, go up a level for the for-loop
|
||||||
|
if (blocksAbove != 0)
|
||||||
|
{
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, end the loop
|
||||||
|
else
|
||||||
|
{
|
||||||
|
moreBlocks = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (moreBlocks);
|
||||||
|
|
||||||
|
return blocks;
|
||||||
|
}
|
||||||
|
|
||||||
// TO-DO: Implement enchantments
|
// TO-DO: Implement enchantments
|
||||||
|
|
||||||
// TO-DO: Implement scythes (3x3 harvest) and tillers (3x3 hoe)
|
// TO-DO: Implement scythes (3x3 harvest) and tillers (3x3 hoe)
|
||||||
|
|
Reference in a new issue