mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-27 11:14:44 +02:00
More tweaks to GT
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user