From eae665c1c51caa9fdea1354ba8f5dd412ad6bfb2 Mon Sep 17 00:00:00 2001 From: GJ Date: Mon, 25 Jun 2012 09:39:02 -0400 Subject: [PATCH] Added ability for custom blocks to drop a range of items. MOD BLOCK FILES WILL NEED TO BE REDONE. --- Changelog.txt | 8 ++++-- .../config/mods/CustomBlocksConfig.java | 9 +++--- .../nossr50/datatypes/mods/CustomBlock.java | 22 ++++++++++++++- .../nossr50/skills/gathering/Herbalism.java | 15 +++++++++- .../nossr50/skills/gathering/Mining.java | 14 +++++++++- .../nossr50/skills/gathering/WoodCutting.java | 28 +++++++++++++++++-- src/main/resources/blocks.yml | 24 ++++++++++------ 7 files changed, 99 insertions(+), 21 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 71990f14b..f3a8ab258 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -7,9 +7,11 @@ Key: ! Change - Removal -Version 1.3.10-dev - = Fixed admin chat being seen by everyone - = Fixed players never being removed from memory (memory leak) +Version 1.3.10-dev + + Added permission node for Iron Grip ability (mcmmo.ability.unarmed.irongrip) + + Added ability for custom blocks to drop a range of items. + = Fixed players never being removed from memory (memory leak) + = Fixed admin chat being seen by everyone Version 1.3.09 + Added compatibility with AntiCheat (Which I highly recommend to prevent cheating) diff --git a/src/main/java/com/gmail/nossr50/config/mods/CustomBlocksConfig.java b/src/main/java/com/gmail/nossr50/config/mods/CustomBlocksConfig.java index 0eba9e247..3eaa158c6 100644 --- a/src/main/java/com/gmail/nossr50/config/mods/CustomBlocksConfig.java +++ b/src/main/java/com/gmail/nossr50/config/mods/CustomBlocksConfig.java @@ -63,7 +63,8 @@ public class CustomBlocksConfig extends ModConfigLoader{ boolean dropItem = config.getBoolean(skillType + "." + blockName + ".Drop_Item", false); int dropID = config.getInt(skillType + "." + blockName + ".Drop_Item_ID", 0); byte dropData = (byte) config.getInt(skillType + "." + blockName + ".Drop_Item_Data_Value", 0); - int dropAmount = config.getInt(skillType + "." + blockName + ".Drop_Item_Amount", 1); + int minimumDropAmount = config.getInt(skillType + "." + blockName + ".Min_Drop_Item_Amount", 1); + int maxiumDropAmount = config.getInt(skillType + "." + blockName + ".Max_Drop_Item_Amount", 1); if (id == 0) { plugin.getLogger().warning("Missing ID. This block will be skipped."); @@ -80,13 +81,13 @@ public class CustomBlocksConfig extends ModConfigLoader{ ItemStack blockItem; if (dropItem) { - itemDrop = new ItemStack(dropID, dropAmount, (short) 0, dropData); + itemDrop = new ItemStack(dropID, 1, (short) 0, dropData); } else { - itemDrop = new ItemStack(id, dropAmount, (short) 0, data); + itemDrop = new ItemStack(id, 1, (short) 0, data); } - block = new CustomBlock(itemDrop, tier, xp, data, id); + block = new CustomBlock(minimumDropAmount, maxiumDropAmount, itemDrop, tier, xp, data, id); blockItem = new ItemStack(id, 1, (short) 0, data); if (skillType.equals("Mining") && config.getBoolean(skillType + "." + blockName + ".Is_Ore")) { diff --git a/src/main/java/com/gmail/nossr50/datatypes/mods/CustomBlock.java b/src/main/java/com/gmail/nossr50/datatypes/mods/CustomBlock.java index 00f0511e1..4f225e3c9 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/mods/CustomBlock.java +++ b/src/main/java/com/gmail/nossr50/datatypes/mods/CustomBlock.java @@ -8,13 +8,17 @@ public class CustomBlock { private int xpGain; private int tier; private ItemStack itemDrop; + private int minimumDropAmount; + private int maximumDropAmount; - public CustomBlock(ItemStack itemDrop, int tier, int xpGain, byte dataValue, int itemID) { + public CustomBlock(int minimumDropAmount, int maximumDropAmount, ItemStack itemDrop, int tier, int xpGain, byte dataValue, int itemID) { this.itemID = itemID; this.dataValue = dataValue; this.xpGain = xpGain; this.tier = tier; this.itemDrop = itemDrop; + this.minimumDropAmount = minimumDropAmount; + this.maximumDropAmount = maximumDropAmount; } public int getItemID() { @@ -56,4 +60,20 @@ public class CustomBlock { public void setItemDrop(ItemStack itemDrop) { this.itemDrop = itemDrop; } + + public int getMinimumDropAmount() { + return minimumDropAmount; + } + + public void setMinimumDropAmount(int minimumDropAmount) { + this.minimumDropAmount = minimumDropAmount; + } + + public int getMaximumDropAmount() { + return maximumDropAmount; + } + + public void setMaximumDropAmount(int maximumDropAmount) { + this.maximumDropAmount = maximumDropAmount; + } } diff --git a/src/main/java/com/gmail/nossr50/skills/gathering/Herbalism.java b/src/main/java/com/gmail/nossr50/skills/gathering/Herbalism.java index 927f19e5c..7a52d9c5c 100644 --- a/src/main/java/com/gmail/nossr50/skills/gathering/Herbalism.java +++ b/src/main/java/com/gmail/nossr50/skills/gathering/Herbalism.java @@ -17,6 +17,7 @@ import com.gmail.nossr50.config.mods.CustomBlocksConfig; import com.gmail.nossr50.datatypes.AbilityType; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.datatypes.mods.CustomBlock; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.runnables.GreenThumbTimer; import com.gmail.nossr50.util.Misc; @@ -281,7 +282,19 @@ public class Herbalism { default: if (customPlant) { - Misc.dropItem(loc, is); + CustomBlock customBlock = ModChecks.getCustomBlock(block); + int minimumDropAmount = customBlock.getMinimumDropAmount(); + int maximumDropAmount = customBlock.getMaximumDropAmount(); + + is = customBlock.getItemDrop(); + + if (minimumDropAmount != maximumDropAmount) { + Misc.dropItems(loc, is, minimumDropAmount); + Misc.randomDropItems(loc, is, 50, maximumDropAmount - minimumDropAmount); + } + else { + Misc.dropItems(loc, is, minimumDropAmount); + } } break; } diff --git a/src/main/java/com/gmail/nossr50/skills/gathering/Mining.java b/src/main/java/com/gmail/nossr50/skills/gathering/Mining.java index 8dd5f4c99..f4b88c5e7 100644 --- a/src/main/java/com/gmail/nossr50/skills/gathering/Mining.java +++ b/src/main/java/com/gmail/nossr50/skills/gathering/Mining.java @@ -15,6 +15,7 @@ import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.datatypes.mods.CustomBlock; import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import com.gmail.nossr50.spout.SpoutSounds; import com.gmail.nossr50.util.Misc; @@ -196,8 +197,19 @@ public class Mining { default: if (ModChecks.isCustomMiningBlock(block)) { + CustomBlock customBlock = ModChecks.getCustomBlock(block); + int minimumDropAmount = customBlock.getMinimumDropAmount(); + int maximumDropAmount = customBlock.getMaximumDropAmount(); + item = ModChecks.getCustomBlock(block).getItemDrop(); - Misc.dropItem(loc, item); + + if (minimumDropAmount != maximumDropAmount) { + Misc.dropItems(loc, item, minimumDropAmount); + Misc.randomDropItems(loc, item, 50, maximumDropAmount - minimumDropAmount); + } + else { + Misc.dropItems(loc, item, minimumDropAmount); + } } break; } diff --git a/src/main/java/com/gmail/nossr50/skills/gathering/WoodCutting.java b/src/main/java/com/gmail/nossr50/skills/gathering/WoodCutting.java index 6c07be74c..dda02baca 100644 --- a/src/main/java/com/gmail/nossr50/skills/gathering/WoodCutting.java +++ b/src/main/java/com/gmail/nossr50/skills/gathering/WoodCutting.java @@ -116,7 +116,18 @@ public class WoodCutting { x.setData((byte) 0x0); x.setType(Material.AIR); - Misc.dropItem(x.getLocation(), item); + int minimumDropAmount = block.getMinimumDropAmount(); + int maximumDropAmount = block.getMaximumDropAmount(); + + item = block.getItemDrop(); + + if (minimumDropAmount != maximumDropAmount) { + Misc.dropItems(x.getLocation(), item, minimumDropAmount); + Misc.randomDropItems(x.getLocation(), item, 50, maximumDropAmount - minimumDropAmount); + } + else { + Misc.dropItems(x.getLocation(), item, minimumDropAmount); + } } else if (ModChecks.isCustomLeafBlock(x)) { CustomBlock block = ModChecks.getCustomBlock(x); @@ -298,9 +309,20 @@ public class WoodCutting { Location location; if (configInstance.getBlockModsEnabled() && ModChecks.isCustomLogBlock(block)) { - item = ModChecks.getCustomBlock(block).getItemDrop(); + CustomBlock customBlock = ModChecks.getCustomBlock(block); + int minimumDropAmount = customBlock.getMinimumDropAmount(); + int maximumDropAmount = customBlock.getMaximumDropAmount(); + + item = customBlock.getItemDrop(); location = block.getLocation(); - Misc.dropItem(location, item); + + if (minimumDropAmount != maximumDropAmount) { + Misc.dropItems(location, item, minimumDropAmount); + Misc.randomDropItems(location, item, 50, maximumDropAmount - minimumDropAmount); + } + else { + Misc.dropItems(location, item, minimumDropAmount); + } return; } else { diff --git a/src/main/resources/blocks.yml b/src/main/resources/blocks.yml index b93b03f93..f41d2cf98 100644 --- a/src/main/resources/blocks.yml +++ b/src/main/resources/blocks.yml @@ -9,7 +9,8 @@ Excavation: Drop_Item: false Drop_Item_ID: 999 Drop_Item_Data_Value: 0 - Drop_Item_Amount: 1 + Min_Drop_Item_Amount: 1 + Max_Drop_Item_Amount: 1 Block_2: ID: 999 Data_Value: 0 @@ -17,7 +18,8 @@ Excavation: Drop_Item: false Drop_Item_ID: 999 Drop_Item_Data_Value: 0 - Drop_Item_Amount: 1 + Min_Drop_Item_Amount: 1 + Max_Drop_Item_Amount: 1 # # Settings for Custom Herbalism Blocks @@ -30,7 +32,8 @@ Herbalism: Drop_Item: false Drop_Item_ID: 999 Drop_Item_Data_Value: 0 - Drop_Item_Amount: 1 + Min_Drop_Item_Amount: 1 + Max_Drop_Item_Amount: 1 Block_2: ID: 999 Data_Value: 0 @@ -38,7 +41,8 @@ Herbalism: Drop_Item: false Drop_Item_ID: 999 Drop_Item_Data_Value: 0 - Drop_Item_Amount: 1 + Min_Drop_Item_Amount: 1 + Max_Drop_Item_Amount: 1 # # Settings for Custom Mining Blocks @@ -53,7 +57,8 @@ Mining: Drop_Item: false Drop_Item_ID: 999 Drop_Item_Data_Value: 0 - Drop_Item_Amount: 1 + Min_Drop_Item_Amount: 1 + Max_Drop_Item_Amount: 1 Block_2: ID: 999 Data_Value: 0 @@ -63,7 +68,8 @@ Mining: Drop_Item: false Drop_Item_ID: 999 Drop_Item_Data_Value: 0 - Drop_Item_Amount: 1 + Min_Drop_Item_Amount: 1 + Max_Drop_Item_Amount: 1 # # Settings for Custom Woodcutting Blocks @@ -77,7 +83,8 @@ Woodcutting: Drop_Item: false Drop_Item_ID: 999 Drop_Item_Data_Value: 0 - Drop_Item_Amount: 1 + Min_Drop_Item_Amount: 1 + Max_Drop_Item_Amount: 1 Block_2: ID: 999 Data_Value: 0 @@ -86,4 +93,5 @@ Woodcutting: Drop_Item: false Drop_Item_ID: 999 Drop_Item_Data_Value: 0 - Drop_Item_Amount: 1 \ No newline at end of file + Min_Drop_Item_Amount: 1 + Max_Drop_Item_Amount: 1 \ No newline at end of file