mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-27 19:24:44 +02:00
Mod support - XP gain & double drops should now work for custom blocks
EXCEPT Woodcutting. Custom excavation blocks will also never drop treasures.
This commit is contained in:
@ -1,11 +1,14 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.mods.CustomBlocksConfig;
|
||||
|
||||
public class BlockChecks {
|
||||
private static Config configInstance = Config.getInstance();
|
||||
private static boolean customBlocksEnabled = configInstance.getBlockModsEnabled();
|
||||
|
||||
/**
|
||||
* Checks to see if a block type awards XP.
|
||||
@ -13,8 +16,8 @@ public class BlockChecks {
|
||||
* @param block Block to check
|
||||
* @return true if the block type awards XP, false otherwise
|
||||
*/
|
||||
public static boolean shouldBeWatched(Material material) {
|
||||
switch (material) {
|
||||
public static boolean shouldBeWatched(Block block) {
|
||||
switch (block.getType()) {
|
||||
case BROWN_MUSHROOM:
|
||||
case CACTUS:
|
||||
case CLAY:
|
||||
@ -50,7 +53,12 @@ public class BlockChecks {
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customItems.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,7 +166,12 @@ public class BlockChecks {
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customHerbalismBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -187,7 +200,12 @@ public class BlockChecks {
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customMiningBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -209,7 +227,12 @@ public class BlockChecks {
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customExcavationBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,7 +250,12 @@ public class BlockChecks {
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customWoodcuttingBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -369,7 +369,7 @@ public class Combat {
|
||||
ItemStack inHand = attacker.getItemInHand();
|
||||
|
||||
if (Config.getInstance().getToolModsEnabled()) {
|
||||
if (ItemChecks.isCustomTool(inHand) && !ModChecks.toolAbilityEnabled(inHand)) {
|
||||
if (ItemChecks.isCustomTool(inHand) && !ModChecks.getToolFromItemStack(inHand).isAbilityEnabled()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1,37 +1,19 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.config.mods.CustomBlocksConfig;
|
||||
import com.gmail.nossr50.config.mods.LoadCustomArmor;
|
||||
import com.gmail.nossr50.config.mods.LoadCustomTools;
|
||||
import com.gmail.nossr50.datatypes.mods.CustomBlock;
|
||||
import com.gmail.nossr50.datatypes.mods.CustomItem;
|
||||
import com.gmail.nossr50.datatypes.mods.CustomTool;
|
||||
|
||||
public class ModChecks {
|
||||
private static LoadCustomTools toolInstance = LoadCustomTools.getInstance();
|
||||
private static LoadCustomArmor armorInstance = LoadCustomArmor.getInstance();
|
||||
|
||||
/**
|
||||
* Check if this custom tool can use abilities.
|
||||
*
|
||||
* @param item The custom item to check
|
||||
* @return true if the tool can use abilities, false otherwise
|
||||
*/
|
||||
public static boolean toolAbilityEnabled(ItemStack item) {
|
||||
int id = item.getTypeId();
|
||||
|
||||
if (!toolInstance.customIDs.contains(id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (CustomItem tool : toolInstance.customItems) {
|
||||
if (tool.getItemID() == id) {
|
||||
return ((CustomTool) tool).isAbilityEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
private static CustomBlocksConfig blocksInstance = CustomBlocksConfig.getInstance();
|
||||
|
||||
/**
|
||||
* Get the custom armor associated with an item.
|
||||
@ -76,4 +58,24 @@ public class ModChecks {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the custom block associated with an block.
|
||||
*
|
||||
* @param block The block to check
|
||||
* @return the armor if it exists, null otherwise
|
||||
*/
|
||||
public static CustomBlock getCustomBlock(Block block) {
|
||||
if (!blocksInstance.customItems.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (CustomBlock b : blocksInstance.customBlocks) {
|
||||
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user