9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-22 16:39:36 +00:00
This commit is contained in:
Xiao-MoMi
2022-08-01 19:26:20 +08:00
parent 9caf4804cd
commit 3b02acf333
3 changed files with 21 additions and 10 deletions

View File

@@ -146,10 +146,13 @@ public class CropManager {
}
Location potLocation = seedLocation.clone().subtract(0,1,0);
CustomBlock pot = CustomBlock.byAlreadyPlaced(potLocation.getBlock());
if (pot == null) return;
String potNamespacedID = pot.getNamespacedID();
String[] cropNameList = StringUtils.split(id,"_");
CropInstance cropInstance = ConfigReader.CROPS.get(cropNameList[0]);
if (pot == null || cropInstance == null){
data.set(stringBuilder.toString(), null);
return;
}
int random = new Random().nextInt(ConfigReader.Config.timeToGrow);
if (potNamespacedID.equals(ConfigReader.Basic.watered_pot)){
//如果启用季节限制且农作物有季节需求
@@ -207,7 +210,7 @@ public class CropManager {
}
}, random);
}else {
if (cropInstance.getReturnStage() == null && !ConfigReader.Season.enable) data.set(stringBuilder.toString(), null);
if (!ConfigReader.Season.enable) data.set(stringBuilder.toString(), null);
bukkitScheduler.runTaskLater(CustomCrops.instance, () -> {
CustomBlock.remove(potLocation);
CustomBlock.place(ConfigReader.Basic.pot, potLocation);
@@ -222,6 +225,8 @@ public class CropManager {
CustomBlock.place(ConfigReader.Basic.dead, seedLocation);
}, random);
}
}else {
data.set(stringBuilder.toString(), null);
}
});
}
@@ -277,10 +282,13 @@ public class CropManager {
}
Location potLocation = seedLocation.clone().subtract(0,1,0);
CustomBlock pot = CustomBlock.byAlreadyPlaced(potLocation.getBlock());
if (pot == null) return;
String potNamespacedID = pot.getNamespacedID();
String[] cropNameList = StringUtils.split(id,"_");
CropInstance cropInstance = ConfigReader.CROPS.get(cropNameList[0]);
if (pot == null || cropInstance == null){
data.set(stringBuilder.toString(), null);
return;
}
int random = new Random().nextInt(ConfigReader.Config.timeToGrow);
if (potNamespacedID.equals(ConfigReader.Basic.watered_pot)){
if (ConfigReader.Season.enable && cropInstance.getSeasons() != null){
@@ -337,7 +345,7 @@ public class CropManager {
}
}, random);
}else {
if (cropInstance.getReturnStage() == null && !ConfigReader.Season.enable) data.set(stringBuilder.toString(), null);
if (!ConfigReader.Season.enable) data.set(stringBuilder.toString(), null);
bukkitScheduler.runTaskLater(CustomCrops.instance, () -> {
CustomBlock.remove(potLocation);
CustomBlock.place(ConfigReader.Basic.pot, potLocation);
@@ -352,6 +360,8 @@ public class CropManager {
CustomBlock.place(ConfigReader.Basic.dead, seedLocation);
}, random);
}
}else {
data.set(stringBuilder.toString(), null);
}
});
}

View File

@@ -369,8 +369,8 @@ public class RightClick implements Listener {
String[] cropNameList = StringUtils.split(customBlock.getId(), "_");
int nextStage = Integer.parseInt(cropNameList[2]) + 1;
if (CustomBlock.getInstance(StringUtils.chop(namespacedID) + nextStage) == null) {
if (ConfigReader.Config.quality){
CropInstance cropInstance = ConfigReader.CROPS.get(cropNameList[0]);
if (ConfigReader.Config.quality){
ThreadLocalRandom current = ThreadLocalRandom.current();
int random = current.nextInt(cropInstance.getMin(), cropInstance.getMax() + 1);
World world = location.getWorld();
@@ -417,10 +417,10 @@ public class RightClick implements Listener {
customBlock.getLoot().forEach(loot-> location.getWorld().dropItem(location.clone().add(0.5,0.2,0.5), loot));
}
CustomBlock.remove(location);
CropInstance crop = ConfigReader.CROPS.get(cropNameList[0]);
AdventureManager.playerSound(player, ConfigReader.Sounds.harvestSource, ConfigReader.Sounds.harvestKey);
if(crop.getReturnStage() != null){
CustomBlock.place(crop.getReturnStage(), location);
if(cropInstance.getReturnStage() != null){
CustomBlock.place(cropInstance.getReturnStage(), location);
CropManager.Cache.put(location, cropNameList[0]);
}
}
}

View File

@@ -58,8 +58,9 @@ crops:
1: customcrops:cabbage
2: customcrops:cabbage_silver_star
3: customcrops:cabbage_golden_star
gigantic: customcrops:gigantic_cabbage
gigantic-chance: 0.01
gigantic:
block: customcrops:gigantic_cabbage
chance: 0.01
season:
- spring