mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-27 03:04:44 +02:00
Use getItemInMainHand()
Add 1.9 blocks to be detected for experience rewards. Add experience rewards for the Chorus plant. Add experience rewards for the Shulker mob.
This commit is contained in:
@ -137,7 +137,7 @@ public class AcrobaticsManager extends SkillManager {
|
||||
|
||||
Player player = getPlayer();
|
||||
|
||||
if (player.getItemInHand().getType() == Material.ENDER_PEARL || player.isInsideVehicle()) {
|
||||
if (player.getInventory().getItemInMainHand().getType() == Material.ENDER_PEARL || player.isInsideVehicle()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,6 @@ public class ExcavationManager extends SkillManager {
|
||||
excavationBlockCheck(blockState);
|
||||
excavationBlockCheck(blockState);
|
||||
|
||||
SkillUtils.handleDurabilityChange(getPlayer().getItemInHand(), Config.getInstance().getAbilityToolDamage());
|
||||
SkillUtils.handleDurabilityChange(getPlayer().getInventory().getItemInMainHand(), Config.getInstance().getAbilityToolDamage());
|
||||
}
|
||||
}
|
||||
|
@ -134,8 +134,8 @@ public class FishingManager extends SkillManager {
|
||||
player.playSound(location, SoundAdapter.GHAST_SCREAM, Misc.GHAST_VOLUME, Misc.getGhastPitch());
|
||||
}
|
||||
|
||||
if (player.getItemInHand().getType() == Material.FISHING_ROD) {
|
||||
player.setItemInHand(null);
|
||||
if (player.getInventory().getItemInMainHand().getType() == Material.FISHING_ROD) {
|
||||
player.getInventory().setItemInMainHand(null);
|
||||
}
|
||||
|
||||
LivingEntity kraken = (LivingEntity) world.spawnEntity(player.getEyeLocation(), (Misc.getRandom().nextInt(100) == 0 ? EntityType.CHICKEN : EntityType.SQUID));
|
||||
@ -491,7 +491,7 @@ public class FishingManager extends SkillManager {
|
||||
*/
|
||||
private FishingTreasure getFishingTreasure() {
|
||||
double diceRoll = Misc.getRandom().nextDouble() * 100;
|
||||
diceRoll -= getPlayer().getItemInHand().getEnchantmentLevel(Enchantment.LUCK);
|
||||
diceRoll -= getPlayer().getInventory().getItemInMainHand().getEnchantmentLevel(Enchantment.LUCK);
|
||||
|
||||
FishingTreasure treasure = null;
|
||||
|
||||
|
@ -9,6 +9,9 @@ import org.bukkit.material.SmoothBrick;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class Herbalism {
|
||||
public static int farmersDietRankLevel1 = AdvancedConfig.getInstance().getFarmerDietRankChange();
|
||||
@ -46,31 +49,89 @@ public class Herbalism {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Block> findChorusPlant(Block target) {
|
||||
return findChorusPlant(target, true);
|
||||
}
|
||||
|
||||
private static List<Block> findChorusPlant(Block target, boolean origin) {
|
||||
List<Block> blocks = new ArrayList<Block>();
|
||||
|
||||
if(target.getType() != Material.CHORUS_PLANT) {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
blocks.add(target);
|
||||
|
||||
Block relative = target.getRelative(BlockFace.UP, 1);
|
||||
if(relative.getType() == Material.CHORUS_PLANT) {
|
||||
blocks.addAll(findChorusPlant(relative, false));
|
||||
}
|
||||
|
||||
if(origin || target.getRelative(BlockFace.DOWN, 1).getType() == Material.CHORUS_PLANT) {
|
||||
relative = target.getRelative(BlockFace.NORTH, 1);
|
||||
if(relative.getType() == Material.CHORUS_PLANT) {
|
||||
blocks.addAll(findChorusPlant(relative, false));
|
||||
}
|
||||
|
||||
relative = target.getRelative(BlockFace.SOUTH, 1);
|
||||
if(relative.getType() == Material.CHORUS_PLANT) {
|
||||
blocks.addAll(findChorusPlant(relative, false));
|
||||
}
|
||||
|
||||
relative = target.getRelative(BlockFace.EAST, 1);
|
||||
if(relative.getType() == Material.CHORUS_PLANT) {
|
||||
blocks.addAll(findChorusPlant(relative, false));
|
||||
}
|
||||
|
||||
relative = target.getRelative(BlockFace.WEST, 1);
|
||||
if(relative.getType() == Material.CHORUS_PLANT) {
|
||||
blocks.addAll(findChorusPlant(relative, false));
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList<Block>(new LinkedHashSet<Block>(blocks));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the drop amounts for cacti & sugar cane based on the blocks above them.
|
||||
* Calculate the drop amounts for multi block plants based on the blocks relative to them.
|
||||
*
|
||||
* @param blockState The {@link BlockState} of the bottom block of the plant
|
||||
* @return the number of bonus drops to award from the blocks in this plant
|
||||
*/
|
||||
protected static int calculateCatciAndSugarDrops(BlockState blockState) {
|
||||
protected static int calculateMultiBlockPlantDrops(BlockState blockState) {
|
||||
Block block = blockState.getBlock();
|
||||
Material blockType = blockState.getType();
|
||||
int dropAmount = mcMMO.getPlaceStore().isTrue(block) ? 0 : 1;
|
||||
|
||||
// Handle the two blocks above it - cacti & sugar cane can only grow 3 high naturally
|
||||
for (int y = 1; y < 3; y++) {
|
||||
Block relativeBlock = block.getRelative(BlockFace.UP, y);
|
||||
|
||||
if (relativeBlock.getType() != blockType) {
|
||||
break;
|
||||
if(blockType == Material.CHORUS_PLANT) {
|
||||
dropAmount = 1;
|
||||
|
||||
if(block.getRelative(BlockFace.DOWN, 1).getType() == Material.ENDER_STONE) {
|
||||
List<Block> blocks = findChorusPlant(block);
|
||||
|
||||
dropAmount = blocks.size();
|
||||
|
||||
/*for(Block b : blocks) {
|
||||
b.breakNaturally();
|
||||
}*/
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Handle the two blocks above it - cacti & sugar cane can only grow 3 high naturally
|
||||
for (int y = 1; y < 3; y++) {
|
||||
Block relativeBlock = block.getRelative(BlockFace.UP, y);
|
||||
|
||||
if (mcMMO.getPlaceStore().isTrue(relativeBlock)) {
|
||||
mcMMO.getPlaceStore().setFalse(relativeBlock);
|
||||
}
|
||||
else {
|
||||
dropAmount++;
|
||||
if (relativeBlock.getType() != blockType) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (mcMMO.getPlaceStore().isTrue(relativeBlock)) {
|
||||
mcMMO.getPlaceStore().setFalse(relativeBlock);
|
||||
}
|
||||
else {
|
||||
dropAmount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,21 +52,15 @@ public class HerbalismManager extends SkillManager {
|
||||
Player player = getPlayer();
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
|
||||
if (item.getAmount() <= 0)
|
||||
return false;
|
||||
|
||||
return item.getType() == Material.SEEDS && BlockUtils.canMakeMossy(blockState) && Permissions.greenThumbBlock(player, blockState.getType());
|
||||
return item.getAmount() > 0 && item.getType() == Material.SEEDS && BlockUtils.canMakeMossy(blockState) && Permissions.greenThumbBlock(player, blockState.getType());
|
||||
}
|
||||
|
||||
public boolean canUseShroomThumb(BlockState blockState) {
|
||||
Player player = getPlayer();
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
Material itemType = item.getType();
|
||||
|
||||
if (item.getAmount() <= 0)
|
||||
return false;
|
||||
|
||||
return (itemType == Material.RED_MUSHROOM || itemType == Material.BROWN_MUSHROOM) && BlockUtils.canMakeShroomy(blockState) && Permissions.secondaryAbilityEnabled(player, SecondaryAbility.SHROOM_THUMB);
|
||||
return item.getAmount() > 0 && (itemType == Material.RED_MUSHROOM || itemType == Material.BROWN_MUSHROOM) && BlockUtils.canMakeShroomy(blockState) && Permissions.secondaryAbilityEnabled(player, SecondaryAbility.SHROOM_THUMB);
|
||||
}
|
||||
|
||||
public boolean canUseHylianLuck() {
|
||||
@ -129,12 +123,12 @@ public class HerbalismManager extends SkillManager {
|
||||
public void herbalismBlockCheck(BlockState blockState) {
|
||||
Player player = getPlayer();
|
||||
Material material = blockState.getType();
|
||||
boolean oneBlockPlant = !(material == Material.CACTUS || material == Material.SUGAR_CANE_BLOCK);
|
||||
boolean oneBlockPlant = !(material == Material.CACTUS || material == Material.CHORUS_PLANT || material == Material.SUGAR_CANE_BLOCK);
|
||||
|
||||
if (oneBlockPlant && mcMMO.getPlaceStore().isTrue(blockState)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!canBlockCheck()) {
|
||||
return;
|
||||
}
|
||||
@ -161,6 +155,10 @@ public class HerbalismManager extends SkillManager {
|
||||
xp = ExperienceConfig.getInstance().getFlowerAndGrassXp(blockState.getData());
|
||||
}
|
||||
else {
|
||||
if(material == Material.CHORUS_FLOWER && blockState.getRawData() != 5) {
|
||||
return;
|
||||
}
|
||||
|
||||
xp = ExperienceConfig.getInstance().getXp(skill, material);
|
||||
}
|
||||
|
||||
@ -169,7 +167,7 @@ public class HerbalismManager extends SkillManager {
|
||||
}
|
||||
|
||||
if (!oneBlockPlant) {
|
||||
amount = Herbalism.calculateCatciAndSugarDrops(blockState);
|
||||
amount = Herbalism.calculateMultiBlockPlantDrops(blockState);
|
||||
xp *= amount;
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public class MiningManager extends SkillManager {
|
||||
public boolean canDetonate() {
|
||||
Player player = getPlayer();
|
||||
|
||||
return canUseBlastMining() && player.isSneaking() && player.getItemInHand().getType() == BlastMining.detonator && Permissions.remoteDetonation(player);
|
||||
return canUseBlastMining() && player.isSneaking() && player.getInventory().getItemInMainHand().getType() == BlastMining.detonator && Permissions.remoteDetonation(player);
|
||||
}
|
||||
|
||||
public boolean canUseBlastMining() {
|
||||
@ -68,14 +68,14 @@ public class MiningManager extends SkillManager {
|
||||
Material material = blockState.getType();
|
||||
|
||||
if (mcMMOPlayer.getAbilityMode(skill.getAbility())) {
|
||||
SkillUtils.handleDurabilityChange(getPlayer().getItemInHand(), Config.getInstance().getAbilityToolDamage());
|
||||
SkillUtils.handleDurabilityChange(getPlayer().getInventory().getItemInMainHand(), Config.getInstance().getAbilityToolDamage());
|
||||
}
|
||||
|
||||
if ((mcMMO.getModManager().isCustomMiningBlock(blockState) && !mcMMO.getModManager().getBlock(blockState).isDoubleDropEnabled()) || material != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(skill, material)) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean silkTouch = player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH);
|
||||
boolean silkTouch = player.getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH);
|
||||
|
||||
for (int i = mcMMOPlayer.getAbilityMode(skill.getAbility()) ? 2 : 1; i != 0; i--) {
|
||||
if (SkillUtils.activationSuccessful(SecondaryAbility.MINING_DOUBLE_DROPS, getPlayer(), getSkillLevel(), activationChance)) {
|
||||
|
@ -94,7 +94,7 @@ public class SalvageManager extends SkillManager {
|
||||
|
||||
salvageableAmount = Math.max((int) (salvageableAmount * getMaxSalvagePercentage()), 1); // Always get at least something back, if you're capable of salvaging it.
|
||||
|
||||
player.setItemInHand(new ItemStack(Material.AIR));
|
||||
player.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
|
||||
location.add(0, 1, 0);
|
||||
|
||||
Map<Enchantment, Integer> enchants = item.getEnchantments();
|
||||
|
@ -83,7 +83,7 @@ public class SmeltingManager extends SkillManager {
|
||||
// We need to distribute Mining XP here, because the block break event gets cancelled
|
||||
applyXpGain(Mining.getBlockXp(blockState), XPGainReason.PVE);
|
||||
|
||||
SkillUtils.handleDurabilityChange(getPlayer().getItemInHand(), Config.getInstance().getAbilityToolDamage());
|
||||
SkillUtils.handleDurabilityChange(getPlayer().getInventory().getItemInMainHand(), Config.getInstance().getAbilityToolDamage());
|
||||
|
||||
Misc.dropItems(blockState.getLocation(), item, isSecondSmeltSuccessful() ? 2 : 1);
|
||||
|
||||
|
@ -257,7 +257,7 @@ public class TamingManager extends SkillManager {
|
||||
private void callOfTheWild(EntityType type, int summonAmount) {
|
||||
Player player = getPlayer();
|
||||
|
||||
ItemStack heldItem = player.getItemInHand();
|
||||
ItemStack heldItem = player.getInventory().getItemInMainHand();
|
||||
int heldItemAmount = heldItem.getAmount();
|
||||
Location location = player.getLocation();
|
||||
|
||||
@ -326,7 +326,7 @@ public class TamingManager extends SkillManager {
|
||||
ParticleEffectUtils.playCallOfTheWildEffect(entity);
|
||||
}
|
||||
|
||||
player.setItemInHand(heldItemAmount == summonAmount ? null : new ItemStack(heldItem.getType(), heldItemAmount - summonAmount));
|
||||
player.getInventory().setItemInMainHand(heldItemAmount == summonAmount ? null : new ItemStack(heldItem.getType(), heldItemAmount - summonAmount));
|
||||
|
||||
String lifeSpan = "";
|
||||
if (tamingCOTWLength > 0) {
|
||||
|
@ -43,13 +43,13 @@ public class UnarmedManager extends SkillManager {
|
||||
}
|
||||
|
||||
public boolean canDisarm(LivingEntity target) {
|
||||
return target instanceof Player && ((Player) target).getItemInHand().getType() != Material.AIR && Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbility.DISARM);
|
||||
return target instanceof Player && ((Player) target).getInventory().getItemInMainHand().getType() != Material.AIR && Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbility.DISARM);
|
||||
}
|
||||
|
||||
public boolean canDeflect() {
|
||||
Player player = getPlayer();
|
||||
|
||||
return ItemUtils.isUnarmed(player.getItemInHand()) && Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbility.DEFLECT);
|
||||
return ItemUtils.isUnarmed(player.getInventory().getItemInMainHand()) && Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbility.DEFLECT);
|
||||
}
|
||||
|
||||
public boolean canUseBlockCracker() {
|
||||
@ -95,13 +95,13 @@ public class UnarmedManager extends SkillManager {
|
||||
return;
|
||||
}
|
||||
|
||||
Item item = Misc.dropItem(defender.getLocation(), defender.getItemInHand());
|
||||
Item item = Misc.dropItem(defender.getLocation(), defender.getInventory().getItemInMainHand());
|
||||
|
||||
if (item != null && AdvancedConfig.getInstance().getDisarmProtected()) {
|
||||
item.setMetadata(mcMMO.disarmedItemKey, UserManager.getPlayer(defender).getPlayerMetadata());
|
||||
}
|
||||
|
||||
defender.setItemInHand(new ItemStack(Material.AIR));
|
||||
defender.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
|
||||
defender.sendMessage(LocaleLoader.getString("Skills.Disarmed"));
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ public class WoodcuttingManager extends SkillManager {
|
||||
}
|
||||
|
||||
// If the tool can't sustain the durability loss
|
||||
if (!Woodcutting.handleDurabilityLoss(treeFellerBlocks, player.getItemInHand())) {
|
||||
if (!Woodcutting.handleDurabilityLoss(treeFellerBlocks, player.getInventory().getItemInMainHand())) {
|
||||
player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFeller.Splinter"));
|
||||
|
||||
double health = player.getHealth();
|
||||
|
Reference in New Issue
Block a user