mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 15: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
|
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
|
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)
|
You can sneak to break plants with a hoe in your hand (or just put the hoe away)
|
||||||
Hoes no longer give free replants
|
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
|
* @param owningPlugin the {@link Plugin} that created this metadata value
|
||||||
*/
|
*/
|
||||||
public RecentlyReplantedCropMeta(Plugin owningPlugin) {
|
public RecentlyReplantedCropMeta(Plugin owningPlugin, Boolean recentlyPlanted) {
|
||||||
super(owningPlugin, true);
|
super(owningPlugin, recentlyPlanted);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -424,11 +424,6 @@ public class BlockListener implements Listener {
|
|||||||
BlockState blockState = event.getBlock().getState();
|
BlockState blockState = event.getBlock().getState();
|
||||||
ItemStack heldItem = player.getInventory().getItemInMainHand();
|
ItemStack heldItem = player.getInventory().getItemInMainHand();
|
||||||
|
|
||||||
if (Herbalism.isRecentlyRegrown(blockState)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ItemUtils.isSword(heldItem)) {
|
if (ItemUtils.isSword(heldItem)) {
|
||||||
HerbalismManager herbalismManager = UserManager.getPlayer(player).getHerbalismManager();
|
HerbalismManager herbalismManager = UserManager.getPlayer(player).getHerbalismManager();
|
||||||
|
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package com.gmail.nossr50.runnables.skills;
|
package com.gmail.nossr50.runnables.skills;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.datatypes.meta.RecentlyReplantedCropMeta;
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
|
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.data.Ageable;
|
import org.bukkit.block.data.Ageable;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
@ -37,19 +39,23 @@ public class DelayedCropReplant extends BukkitRunnable {
|
|||||||
Block cropBlock = cropLocation.getBlock();
|
Block cropBlock = cropLocation.getBlock();
|
||||||
BlockState currentState = cropBlock.getState();
|
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()) {
|
if(blockBreakEvent.isCancelled()) {
|
||||||
wasImmaturePlant = true;
|
wasImmaturePlant = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Two kinds of air in Minecraft
|
//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
|
//The space is not currently occupied by a block so we can fill it
|
||||||
cropBlock.setType(cropMaterial);
|
cropBlock.setType(cropMaterial);
|
||||||
|
|
||||||
//Get new state (necessary?)
|
//Get new state (necessary?)
|
||||||
BlockState newState = cropBlock.getState();
|
BlockState newState = cropBlock.getState();
|
||||||
newState.setType(cropMaterial);
|
// newState.update();
|
||||||
newState.update();
|
|
||||||
Ageable ageable = (Ageable) newState.getBlockData();
|
Ageable ageable = (Ageable) newState.getBlockData();
|
||||||
|
|
||||||
//Crop age should always be 0 if the plant was immature
|
//Crop age should always be 0 if the plant was immature
|
||||||
@ -62,28 +68,30 @@ public class DelayedCropReplant extends BukkitRunnable {
|
|||||||
|
|
||||||
//Age the crop
|
//Age the crop
|
||||||
newState.setBlockData(ageable);
|
newState.setBlockData(ageable);
|
||||||
|
newState.update(true);
|
||||||
|
|
||||||
//Play an effect
|
//Play an effect
|
||||||
ParticleEffectUtils.playGreenThumbEffect(cropLocation);
|
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;
|
private final Location cropLoc;
|
||||||
|
|
||||||
public removePlantMeta(Location cropLoc) {
|
public markPlantAsOld(Location cropLoc) {
|
||||||
this.cropLoc = cropLoc;
|
this.cropLoc = cropLoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Block cropBlock = cropLoc.getBlock();
|
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;
|
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
|
* 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
|
* 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) {
|
private void processHerbalismOnBlocksBroken(BlockBreakEvent blockBreakEvent, HashSet<Block> brokenPlants) {
|
||||||
BlockState originalBreak = blockBreakEvent.getBlock().getState();
|
BlockState originalBreak = blockBreakEvent.getBlock().getState();
|
||||||
|
boolean greenThumbActivated = false;
|
||||||
//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;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: The design of Green Terra needs to change, this is a mess
|
//TODO: The design of Green Terra needs to change, this is a mess
|
||||||
if(Permissions.greenThumbPlant(getPlayer(), originalBreak.getType())) {
|
if(Permissions.greenThumbPlant(getPlayer(), originalBreak.getType())) {
|
||||||
if(!getPlayer().isSneaking())
|
if(!getPlayer().isSneaking()) {
|
||||||
processGreenThumbPlants(originalBreak, blockBreakEvent, isGreenTerraActive());
|
greenThumbActivated = processGreenThumbPlants(originalBreak, blockBreakEvent, isGreenTerraActive());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//When replanting a immature crop we cancel the block break event and back out
|
//When replanting a immature crop we cancel the block break event and back out
|
||||||
if(blockBreakEvent.isCancelled()) {
|
if(greenThumbActivated) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -659,8 +664,8 @@ public class HerbalismManager extends SkillManager {
|
|||||||
*/
|
*/
|
||||||
private void startReplantTask(int desiredCropAge, BlockBreakEvent blockBreakEvent, BlockState cropState, boolean isImmature) {
|
private void startReplantTask(int desiredCropAge, BlockBreakEvent blockBreakEvent, BlockState cropState, boolean isImmature) {
|
||||||
//Mark the plant as recently replanted to avoid accidental breakage
|
//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);
|
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 blockState The {@link BlockState} to check ability activation for
|
||||||
* @param greenTerra boolean to determine if greenTerra is active or not
|
* @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())) {
|
if(!ItemUtils.isHoe(blockBreakEvent.getPlayer().getInventory().getItemInMainHand())) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockData blockData = blockState.getBlockData();
|
BlockData blockData = blockState.getBlockData();
|
||||||
|
|
||||||
if (!(blockData instanceof Ageable)) {
|
if (!(blockData instanceof Ageable)) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ageable ageable = (Ageable) blockData;
|
Ageable ageable = (Ageable) blockData;
|
||||||
@ -714,30 +719,30 @@ public class HerbalismManager extends SkillManager {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack seedStack = new ItemStack(seed);
|
ItemStack seedStack = new ItemStack(seed);
|
||||||
|
|
||||||
if (!greenTerra && !RandomChanceUtil.checkRandomChanceExecutionSuccess(player, SubSkillType.HERBALISM_GREEN_THUMB, true)) {
|
if (!greenTerra && !RandomChanceUtil.checkRandomChanceExecutionSuccess(player, SubSkillType.HERBALISM_GREEN_THUMB, true)) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!playerInventory.containsAtLeast(seedStack, 1)) {
|
if (!playerInventory.containsAtLeast(seedStack, 1)) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!processGrowingPlants(blockState, ageable, blockBreakEvent, greenTerra)) {
|
if (!processGrowingPlants(blockState, ageable, blockBreakEvent, greenTerra)) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
playerInventory.removeItem(seedStack);
|
playerInventory.removeItem(seedStack);
|
||||||
player.updateInventory(); // Needed until replacement available
|
player.updateInventory(); // Needed until replacement available
|
||||||
//Play sound
|
//Play sound
|
||||||
SoundManager.sendSound(player, player.getLocation(), SoundType.ITEM_CONSUMED);
|
SoundManager.sendSound(player, player.getLocation(), SoundType.ITEM_CONSUMED);
|
||||||
|
return true;
|
||||||
new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0);
|
// new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean processGrowingPlants(BlockState blockState, Ageable ageable, BlockBreakEvent blockBreakEvent, boolean greenTerra) {
|
private boolean processGrowingPlants(BlockState blockState, Ageable ageable, BlockBreakEvent blockBreakEvent, boolean greenTerra) {
|
||||||
@ -747,31 +752,23 @@ public class HerbalismManager extends SkillManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int finalAge = 0;
|
int finalAge = 0;
|
||||||
int greenThumbStage = getGreenThumbStage();
|
int greenThumbStage = getGreenThumbStage(greenTerra);
|
||||||
|
|
||||||
//Immature plants will start over at 0
|
//Immature plants will start over at 0
|
||||||
if(!isAgeableMature(ageable)) {
|
if(!isAgeableMature(ageable)) {
|
||||||
blockBreakEvent.setCancelled(true);
|
blockBreakEvent.setCancelled(true);
|
||||||
startReplantTask(0, blockBreakEvent, blockState, true);
|
startReplantTask(0, blockBreakEvent, blockState, true);
|
||||||
blockState.setType(Material.AIR);
|
blockState.setType(Material.AIR);
|
||||||
blockState.update();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
blockState.setMetadata(mcMMO.greenThumbDataKey, new FixedMetadataValue(mcMMO.p, (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR)));
|
|
||||||
|
|
||||||
switch (blockState.getType()) {
|
switch (blockState.getType()) {
|
||||||
|
|
||||||
case POTATOES:
|
case POTATOES:
|
||||||
case CARROTS:
|
case CARROTS:
|
||||||
case WHEAT:
|
case WHEAT:
|
||||||
|
|
||||||
if (greenTerra) {
|
finalAge = getGreenThumbStage(greenTerra);
|
||||||
finalAge = 3;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
finalAge = getGreenThumbStage();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BEETROOTS:
|
case BEETROOTS:
|
||||||
@ -790,7 +787,7 @@ public class HerbalismManager extends SkillManager {
|
|||||||
|
|
||||||
case COCOA:
|
case COCOA:
|
||||||
|
|
||||||
if (greenTerra || getGreenThumbStage() > 1) {
|
if (getGreenThumbStage(greenTerra) >= 2) {
|
||||||
finalAge = 1;
|
finalAge = 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -807,7 +804,11 @@ public class HerbalismManager extends SkillManager {
|
|||||||
return true;
|
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);
|
return RankUtils.getRank(getPlayer(), SubSkillType.HERBALISM_GREEN_THUMB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user