mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
More tweaks to GT
This commit is contained in:
parent
a333f36fd8
commit
a598796c99
@ -1,4 +1,6 @@
|
||||
Version 2.1.115
|
||||
Cocoa plants now require GT of at least 2 to start at the second stage of growth
|
||||
Green Terra now boosts growth on Green Thumb by 1 stage (doesn't go above the maximum value though)
|
||||
Green Thumb now requires a hoe to activate
|
||||
You can sneak to break plants with a hoe in your hand (or just put the hoe away)
|
||||
Hoes no longer give free replants
|
||||
|
@ -10,8 +10,8 @@ public class RecentlyReplantedCropMeta extends FixedMetadataValue {
|
||||
*
|
||||
* @param owningPlugin the {@link Plugin} that created this metadata value
|
||||
*/
|
||||
public RecentlyReplantedCropMeta(Plugin owningPlugin) {
|
||||
super(owningPlugin, true);
|
||||
public RecentlyReplantedCropMeta(Plugin owningPlugin, Boolean recentlyPlanted) {
|
||||
super(owningPlugin, recentlyPlanted);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -424,11 +424,6 @@ public class BlockListener implements Listener {
|
||||
BlockState blockState = event.getBlock().getState();
|
||||
ItemStack heldItem = player.getInventory().getItemInMainHand();
|
||||
|
||||
if (Herbalism.isRecentlyRegrown(blockState)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ItemUtils.isSword(heldItem)) {
|
||||
HerbalismManager herbalismManager = UserManager.getPlayer(player).getHerbalismManager();
|
||||
|
||||
|
@ -1,10 +1,12 @@
|
||||
package com.gmail.nossr50.runnables.skills;
|
||||
|
||||
import com.gmail.nossr50.datatypes.meta.RecentlyReplantedCropMeta;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.Ageable;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
@ -37,19 +39,23 @@ public class DelayedCropReplant extends BukkitRunnable {
|
||||
Block cropBlock = cropLocation.getBlock();
|
||||
BlockState currentState = cropBlock.getState();
|
||||
|
||||
//Remove the metadata marking the block as recently replanted
|
||||
new markPlantAsOld(blockBreakEvent.getBlock().getLocation()).runTaskLater(mcMMO.p, 20*5);
|
||||
|
||||
if(blockBreakEvent.isCancelled()) {
|
||||
wasImmaturePlant = true;
|
||||
}
|
||||
|
||||
//Two kinds of air in Minecraft
|
||||
if(currentState.getType().equals(Material.AIR) || currentState.getType().equals(Material.CAVE_AIR)) {
|
||||
if(currentState.getType().equals(cropMaterial) || currentState.getType().equals(Material.AIR) || currentState.getType().equals(Material.CAVE_AIR)) {
|
||||
// if(currentState.getBlock().getRelative(BlockFace.DOWN))
|
||||
//The space is not currently occupied by a block so we can fill it
|
||||
cropBlock.setType(cropMaterial);
|
||||
|
||||
//Get new state (necessary?)
|
||||
BlockState newState = cropBlock.getState();
|
||||
newState.setType(cropMaterial);
|
||||
newState.update();
|
||||
// newState.update();
|
||||
|
||||
Ageable ageable = (Ageable) newState.getBlockData();
|
||||
|
||||
//Crop age should always be 0 if the plant was immature
|
||||
@ -62,28 +68,30 @@ public class DelayedCropReplant extends BukkitRunnable {
|
||||
|
||||
//Age the crop
|
||||
newState.setBlockData(ageable);
|
||||
newState.update(true);
|
||||
|
||||
//Play an effect
|
||||
ParticleEffectUtils.playGreenThumbEffect(cropLocation);
|
||||
|
||||
//Remove the metadata marking the block as recently replanted
|
||||
new removePlantMeta(blockBreakEvent.getBlock().getLocation()).runTaskLater(mcMMO.p, 20);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class removePlantMeta extends BukkitRunnable {
|
||||
private class markPlantAsOld extends BukkitRunnable {
|
||||
|
||||
private final Location cropLoc;
|
||||
|
||||
public removePlantMeta(Location cropLoc) {
|
||||
public markPlantAsOld(Location cropLoc) {
|
||||
this.cropLoc = cropLoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Block cropBlock = cropLoc.getBlock();
|
||||
cropBlock.removeMetadata(mcMMO.REPLANT_META_KEY, mcMMO.p);
|
||||
if(cropBlock.getMetadata(mcMMO.REPLANT_META_KEY).size() > 0)
|
||||
cropBlock.setMetadata(mcMMO.REPLANT_META_KEY, new RecentlyReplantedCropMeta(mcMMO.p, false));
|
||||
|
||||
ParticleEffectUtils.playFluxEffect(cropLocation);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,14 +58,4 @@ public class Herbalism {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the block has a recently grown crop from Green Thumb
|
||||
*
|
||||
* @param blockState
|
||||
* The {@link BlockState} to check green thumb regrown for
|
||||
* @return true if the block is recently regrown, false otherwise
|
||||
*/
|
||||
public static boolean isRecentlyRegrown(BlockState blockState) {
|
||||
return blockState.hasMetadata(mcMMO.greenThumbDataKey) && !SkillUtils.cooldownExpired(blockState.getMetadata(mcMMO.greenThumbDataKey).get(0).asInt(), 1);
|
||||
}
|
||||
}
|
||||
|
@ -139,6 +139,16 @@ public class HerbalismManager extends SkillManager {
|
||||
return;
|
||||
}
|
||||
|
||||
//Check if the plant was recently replanted
|
||||
if(blockBreakEvent.getBlock().getMetadata(mcMMO.REPLANT_META_KEY).size() >= 1) {
|
||||
if(blockBreakEvent.getBlock().getMetadata(mcMMO.REPLANT_META_KEY).get(0).asBoolean()) {
|
||||
//Crop is recently replanted to back out of destroying it
|
||||
blockBreakEvent.setCancelled(true);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* There are single-block plants and multi-block plants in Minecraft
|
||||
* In order to give out proper rewards, we need to collect all blocks that would be broken from this event
|
||||
@ -161,22 +171,17 @@ public class HerbalismManager extends SkillManager {
|
||||
*/
|
||||
private void processHerbalismOnBlocksBroken(BlockBreakEvent blockBreakEvent, HashSet<Block> brokenPlants) {
|
||||
BlockState originalBreak = blockBreakEvent.getBlock().getState();
|
||||
|
||||
//Check if the plant was recently replanted
|
||||
if(blockBreakEvent.getBlock().getMetadata(mcMMO.REPLANT_META_KEY).size() >= 1) {
|
||||
//Crop is recently replanted to back out of destroying it
|
||||
blockBreakEvent.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
boolean greenThumbActivated = false;
|
||||
|
||||
//TODO: The design of Green Terra needs to change, this is a mess
|
||||
if(Permissions.greenThumbPlant(getPlayer(), originalBreak.getType())) {
|
||||
if(!getPlayer().isSneaking())
|
||||
processGreenThumbPlants(originalBreak, blockBreakEvent, isGreenTerraActive());
|
||||
if(!getPlayer().isSneaking()) {
|
||||
greenThumbActivated = processGreenThumbPlants(originalBreak, blockBreakEvent, isGreenTerraActive());
|
||||
}
|
||||
}
|
||||
|
||||
//When replanting a immature crop we cancel the block break event and back out
|
||||
if(blockBreakEvent.isCancelled()) {
|
||||
if(greenThumbActivated) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -659,8 +664,8 @@ public class HerbalismManager extends SkillManager {
|
||||
*/
|
||||
private void startReplantTask(int desiredCropAge, BlockBreakEvent blockBreakEvent, BlockState cropState, boolean isImmature) {
|
||||
//Mark the plant as recently replanted to avoid accidental breakage
|
||||
blockBreakEvent.getBlock().setMetadata(mcMMO.REPLANT_META_KEY, new RecentlyReplantedCropMeta(mcMMO.p));
|
||||
new DelayedCropReplant(blockBreakEvent, cropState, desiredCropAge, isImmature).runTaskLater(mcMMO.p, 20 * 2);
|
||||
blockBreakEvent.getBlock().setMetadata(mcMMO.REPLANT_META_KEY, new RecentlyReplantedCropMeta(mcMMO.p, true));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -669,15 +674,15 @@ public class HerbalismManager extends SkillManager {
|
||||
* @param blockState The {@link BlockState} to check ability activation for
|
||||
* @param greenTerra boolean to determine if greenTerra is active or not
|
||||
*/
|
||||
private void processGreenThumbPlants(BlockState blockState, BlockBreakEvent blockBreakEvent, boolean greenTerra) {
|
||||
private boolean processGreenThumbPlants(BlockState blockState, BlockBreakEvent blockBreakEvent, boolean greenTerra) {
|
||||
if(!ItemUtils.isHoe(blockBreakEvent.getPlayer().getInventory().getItemInMainHand())) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
BlockData blockData = blockState.getBlockData();
|
||||
|
||||
if (!(blockData instanceof Ageable)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
Ageable ageable = (Ageable) blockData;
|
||||
@ -714,30 +719,30 @@ public class HerbalismManager extends SkillManager {
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack seedStack = new ItemStack(seed);
|
||||
|
||||
if (!greenTerra && !RandomChanceUtil.checkRandomChanceExecutionSuccess(player, SubSkillType.HERBALISM_GREEN_THUMB, true)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!playerInventory.containsAtLeast(seedStack, 1)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!processGrowingPlants(blockState, ageable, blockBreakEvent, greenTerra)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
playerInventory.removeItem(seedStack);
|
||||
player.updateInventory(); // Needed until replacement available
|
||||
//Play sound
|
||||
SoundManager.sendSound(player, player.getLocation(), SoundType.ITEM_CONSUMED);
|
||||
|
||||
new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0);
|
||||
return true;
|
||||
// new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0);
|
||||
}
|
||||
|
||||
private boolean processGrowingPlants(BlockState blockState, Ageable ageable, BlockBreakEvent blockBreakEvent, boolean greenTerra) {
|
||||
@ -747,31 +752,23 @@ public class HerbalismManager extends SkillManager {
|
||||
}
|
||||
|
||||
int finalAge = 0;
|
||||
int greenThumbStage = getGreenThumbStage();
|
||||
int greenThumbStage = getGreenThumbStage(greenTerra);
|
||||
|
||||
//Immature plants will start over at 0
|
||||
if(!isAgeableMature(ageable)) {
|
||||
blockBreakEvent.setCancelled(true);
|
||||
startReplantTask(0, blockBreakEvent, blockState, true);
|
||||
blockState.setType(Material.AIR);
|
||||
blockState.update();
|
||||
return true;
|
||||
}
|
||||
|
||||
blockState.setMetadata(mcMMO.greenThumbDataKey, new FixedMetadataValue(mcMMO.p, (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR)));
|
||||
|
||||
switch (blockState.getType()) {
|
||||
|
||||
case POTATOES:
|
||||
case CARROTS:
|
||||
case WHEAT:
|
||||
|
||||
if (greenTerra) {
|
||||
finalAge = 3;
|
||||
}
|
||||
else {
|
||||
finalAge = getGreenThumbStage();
|
||||
}
|
||||
finalAge = getGreenThumbStage(greenTerra);
|
||||
break;
|
||||
|
||||
case BEETROOTS:
|
||||
@ -790,7 +787,7 @@ public class HerbalismManager extends SkillManager {
|
||||
|
||||
case COCOA:
|
||||
|
||||
if (greenTerra || getGreenThumbStage() > 1) {
|
||||
if (getGreenThumbStage(greenTerra) >= 2) {
|
||||
finalAge = 1;
|
||||
}
|
||||
else {
|
||||
@ -807,7 +804,11 @@ public class HerbalismManager extends SkillManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
private int getGreenThumbStage() {
|
||||
private int getGreenThumbStage(boolean greenTerraActive) {
|
||||
if(greenTerraActive)
|
||||
return Math.min(RankUtils.getHighestRank(SubSkillType.HERBALISM_GREEN_THUMB),
|
||||
RankUtils.getRank(getPlayer(), SubSkillType.HERBALISM_GREEN_THUMB) + 1);
|
||||
|
||||
return RankUtils.getRank(getPlayer(), SubSkillType.HERBALISM_GREEN_THUMB);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user