2.1.18 - It turns out Kelp is actually made up of 2 blocks mixed together

This commit is contained in:
nossr50
2019-03-16 20:26:26 -07:00
parent 8994594ed4
commit 2f0a58b968
5 changed files with 64 additions and 4 deletions

View File

@ -91,7 +91,7 @@ public class Herbalism {
}
} else {
// Handle the two blocks above it - cacti & sugar cane can only grow 3 high naturally
for (int y = 1; y < 3; y++) {
for (int y = 1; y < 256; y++) {
Block relativeBlock = block.getRelative(BlockFace.UP, y);
if (relativeBlock.getType() != blockType) {
@ -109,6 +109,51 @@ public class Herbalism {
return dropAmount;
}
/**
* Calculate the drop amounts for kelp 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 calculateKelpPlantDrops(BlockState blockState) {
Block block = blockState.getBlock();
int dropAmount = mcMMO.getPlaceStore().isTrue(block) ? 0 : 1;
int kelpMaxHeight = 256;
// Handle the two blocks above it - cacti & sugar cane can only grow 3 high naturally
for (int y = 1; y < kelpMaxHeight; y++) {
Block relativeUpBlock = block.getRelative(BlockFace.UP, y);
if(!isKelp(relativeUpBlock))
break;
dropAmount = addKelpDrops(dropAmount, relativeUpBlock);
}
return dropAmount;
}
private static int addKelpDrops(int dropAmount, Block relativeBlock) {
if (isKelp(relativeBlock) && !mcMMO.getPlaceStore().isTrue(relativeBlock)) {
dropAmount++;
} else {
mcMMO.getPlaceStore().setFalse(relativeBlock);
}
return dropAmount;
}
private static boolean isKelp(Block relativeBlock) {
Material kelptype_1 = Material.KELP_PLANT;
Material kelptype_2 = Material.KELP;
return relativeBlock.getType() == kelptype_1 || relativeBlock.getType() == kelptype_2;
}
/**
* Convert blocks affected by the Green Thumb & Green Terra abilities.
*

View File

@ -126,7 +126,8 @@ public class HerbalismManager extends SkillManager {
public void herbalismBlockCheck(BlockState blockState) {
Player player = getPlayer();
Material material = blockState.getType();
boolean oneBlockPlant = !(material == Material.CACTUS || material == Material.CHORUS_PLANT || material == Material.SUGAR_CANE || material == Material.KELP_PLANT);
boolean oneBlockPlant = !(material == Material.CACTUS || material == Material.CHORUS_PLANT
|| material == Material.SUGAR_CANE || material == Material.KELP_PLANT || material == Material.KELP);
// Prevents placing and immediately breaking blocks for exp
if (oneBlockPlant && mcMMO.getPlaceStore().isTrue(blockState)) {
@ -158,7 +159,13 @@ public class HerbalismManager extends SkillManager {
}
if (!oneBlockPlant) {
amount = Herbalism.calculateMultiBlockPlantDrops(blockState);
//Kelp is actually two blocks mixed together
if(material == Material.KELP_PLANT || material == Material.KELP) {
amount = Herbalism.calculateKelpPlantDrops(blockState);
} else {
amount = Herbalism.calculateMultiBlockPlantDrops(blockState);
}
xp *= amount;
}