mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-22 16:39:36 +00:00
1.5.6
This commit is contained in:
@@ -83,7 +83,6 @@ public class ConfigReader {
|
||||
cropGrowTimeList.forEach(time -> {
|
||||
if(time < 0 || time > 23999){
|
||||
AdventureManager.consoleMessage("<red>[CustomCrops] 农作物生长时间点必须位于0-23999之间");
|
||||
cropGrowTimeList.remove(time);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -119,9 +118,9 @@ public class ConfigReader {
|
||||
}
|
||||
|
||||
//农作物品质处理
|
||||
quality = config.getBoolean("config.quality.enable");
|
||||
quality = config.getBoolean("config.quality.enable",true);
|
||||
if (quality){
|
||||
String[] split = StringUtils.split(config.getString("config.quality.default-ratio"), "/");
|
||||
String[] split = StringUtils.split(config.getString("config.quality.default-ratio","17/2/1"), "/");
|
||||
double[] ratios = new double[3];
|
||||
ratios[0] = Double.parseDouble(split[0]);
|
||||
ratios[1] = Double.parseDouble(split[1]);
|
||||
@@ -139,7 +138,6 @@ public class ConfigReader {
|
||||
worldNames.forEach(worldName -> {
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world == null){
|
||||
worldNames.remove(worldName);
|
||||
AdventureManager.consoleMessage("<red>[CustomCrops] 世界" + worldName + "" + "不存在");
|
||||
}else {
|
||||
worlds.add(world);
|
||||
@@ -212,24 +210,31 @@ public class ConfigReader {
|
||||
public static String pot;
|
||||
public static String watered_pot;
|
||||
public static String glass;
|
||||
public static String sprinkler_1;
|
||||
public static String sprinkler_2;
|
||||
public static String sprinkler_1i;
|
||||
public static String sprinkler_2i;
|
||||
public static String dead;
|
||||
public static String soilDetector;
|
||||
public static boolean hasWaterLore;
|
||||
public static String waterLeft;
|
||||
public static String waterFull;
|
||||
public static String waterEmpty;
|
||||
public static String waterRight;
|
||||
public static List<String> waterLore;
|
||||
|
||||
public static void loadBasic(){
|
||||
YamlConfiguration config = getConfig("basic.yml");
|
||||
pot = config.getString("basic.pot");
|
||||
watered_pot = config.getString("basic.watered-pot");
|
||||
glass = config.getString("basic.greenhouse-glass");
|
||||
sprinkler_1 = config.getString("basic.sprinkler-1");
|
||||
sprinkler_2 = config.getString("basic.sprinkler-2");
|
||||
sprinkler_1i = config.getString("basic.sprinkler-1-item");
|
||||
sprinkler_2i = config.getString("basic.sprinkler-2-item");
|
||||
dead = config.getString("basic.dead-crop");
|
||||
soilDetector = StringUtils.split(config.getString("basic.soil-detector"),":")[1];
|
||||
pot = config.getString("basic.pot","customcrops:pot");
|
||||
watered_pot = config.getString("basic.watered-pot","customcrops:watered_pot");
|
||||
glass = config.getString("basic.greenhouse-glass","customcrops:greenhouse_glass");
|
||||
dead = config.getString("basic.dead-crop","customcrops:crop_stage_death");
|
||||
soilDetector = StringUtils.split(config.getString("basic.soil-detector","customcrops:soil_detector"),":")[1];
|
||||
|
||||
hasWaterLore = config.getBoolean("lore.watering-can.enable",false);
|
||||
if (hasWaterLore){
|
||||
waterLeft = config.getString("lore.watering-can.left");
|
||||
waterFull = config.getString("lore.watering-can.full");
|
||||
waterEmpty = config.getString("lore.watering-can.empty");
|
||||
waterRight = config.getString("lore.watering-can.right");
|
||||
waterLore = config.getStringList("lore.watering-can.lore");
|
||||
}
|
||||
|
||||
CANS.clear();
|
||||
if (config.contains("water-can")){
|
||||
|
||||
@@ -13,10 +13,6 @@ public class ItemSpawn implements Listener {
|
||||
if(event.getEntity() instanceof Item item) {
|
||||
if(CustomStack.byItemStack(item.getItemStack()) != null){
|
||||
String id = CustomStack.byItemStack(item.getItemStack()).getId();
|
||||
// if(ConfigReader.SPRINKLERS.get(id) != null){
|
||||
// item.remove();
|
||||
// item.getWorld().dropItem(item.getLocation() ,CustomStack.getInstance(ConfigReader.SPRINKLERS.get(id).getNamespacedID_1()).getItemStack());
|
||||
// }else
|
||||
if(id.contains("_stage_")){
|
||||
item.remove();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import de.tr7zw.changeme.nbtapi.NBTCompound;
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import dev.lone.itemsadder.api.CustomBlock;
|
||||
import dev.lone.itemsadder.api.CustomStack;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customcrops.ConfigReader;
|
||||
import net.momirealms.customcrops.datamanager.CropManager;
|
||||
import net.momirealms.customcrops.datamanager.PotManager;
|
||||
@@ -34,6 +36,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -54,62 +57,7 @@ public class RightClick implements Listener {
|
||||
Action action = event.getAction();
|
||||
if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK){
|
||||
ItemStack itemStack = event.getItem();
|
||||
if (itemStack == null){
|
||||
if (action != Action.RIGHT_CLICK_BLOCK) return;
|
||||
Block block = event.getClickedBlock();
|
||||
Location location = block.getLocation();
|
||||
CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block);
|
||||
if (customBlock == null) return;
|
||||
for (Integration integration : ConfigReader.Config.integration){
|
||||
if (!integration.canBreak(location, player)) return;
|
||||
}
|
||||
String namespacedID = customBlock.getNamespacedID();
|
||||
if (namespacedID.contains("_stage_")){
|
||||
if(namespacedID.equals(ConfigReader.Basic.dead)) return;
|
||||
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]);
|
||||
ThreadLocalRandom current = ThreadLocalRandom.current();
|
||||
int random = current.nextInt(cropInstance.getMin(), cropInstance.getMax() + 1);
|
||||
World world = location.getWorld();
|
||||
Location itemLoc = location.clone().add(0.5,0.2,0.5);
|
||||
Fertilizer fertilizer = PotManager.Cache.get(location.clone().subtract(0,1,0));
|
||||
if (fertilizer != null){
|
||||
if (fertilizer instanceof QualityCrop qualityCrop){
|
||||
int[] weights = qualityCrop.getChance();
|
||||
double weightTotal = weights[0] + weights[1] + weights[2];
|
||||
double rank_1 = weights[0]/(weightTotal);
|
||||
double rank_2 = 1 - weights[1]/(weightTotal);
|
||||
for (int i = 0; i < random; i++){
|
||||
double ran = Math.random();
|
||||
if (ran < rank_1){
|
||||
world.dropItem(itemLoc, CustomStack.getInstance(cropInstance.getQuality_1()).getItemStack());
|
||||
}else if(ran > rank_2){
|
||||
world.dropItem(itemLoc, CustomStack.getInstance(cropInstance.getQuality_2()).getItemStack());
|
||||
}else {
|
||||
world.dropItem(itemLoc, CustomStack.getInstance(cropInstance.getQuality_3()).getItemStack());
|
||||
}
|
||||
}
|
||||
}else {
|
||||
BreakBlock.normalDrop(cropInstance, random, itemLoc, world);
|
||||
}
|
||||
}
|
||||
else {
|
||||
BreakBlock.normalDrop(cropInstance, random, itemLoc, world);
|
||||
}
|
||||
}else {
|
||||
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]);
|
||||
if(crop.getReturnStage() != null){
|
||||
CustomBlock.place(crop.getReturnStage(), location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else {
|
||||
if (itemStack != null){
|
||||
NBTItem nbtItem = new NBTItem(itemStack);
|
||||
NBTCompound nbtCompound = nbtItem.getCompound("itemsadder");
|
||||
if (nbtCompound != null){
|
||||
@@ -179,12 +127,19 @@ public class RightClick implements Listener {
|
||||
if (wateringCan.getMax() > water){
|
||||
nbtItem.setInteger("WaterAmount", water + 1);
|
||||
player.getWorld().playSound(player.getLocation(), Sound.ITEM_BUCKET_FILL,1,1);
|
||||
itemStack.setItemMeta(nbtItem.getItem().getItemMeta());
|
||||
if (ConfigReader.Message.hasWaterInfo){
|
||||
String string = ConfigReader.Message.waterLeft + ConfigReader.Message.waterFull.repeat(water + 1) +
|
||||
ConfigReader.Message.waterEmpty.repeat(wateringCan.getMax() - water - 1) + ConfigReader.Message.waterRight;
|
||||
AdventureManager.playerActionbar(player, string.replace("{max_water}", String.valueOf(wateringCan.getMax())).replace("{water}", String.valueOf(water + 1)));
|
||||
}
|
||||
if (ConfigReader.Basic.hasWaterLore){
|
||||
String string = (ConfigReader.Basic.waterLeft + ConfigReader.Basic.waterFull.repeat(water + 1) +
|
||||
ConfigReader.Basic.waterEmpty.repeat(wateringCan.getMax() - water - 1) + ConfigReader.Basic.waterRight).replace("{max_water}", String.valueOf(wateringCan.getMax())).replace("{water}", String.valueOf(water + 1));
|
||||
List<String> lores = nbtItem.getCompound("display").getStringList("Lore");
|
||||
lores.clear();
|
||||
ConfigReader.Basic.waterLore.forEach(lore -> lores.add(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(lore.replace("{water_info}", string)))));
|
||||
}
|
||||
itemStack.setItemMeta(nbtItem.getItem().getItemMeta());
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -199,7 +154,6 @@ public class RightClick implements Listener {
|
||||
String namespacedID = customBlock.getNamespacedID();
|
||||
if (namespacedID.equals(ConfigReader.Basic.pot) || namespacedID.equals(ConfigReader.Basic.watered_pot)){
|
||||
nbtItem.setInteger("WaterAmount", water - 1);
|
||||
itemStack.setItemMeta(nbtItem.getItem().getItemMeta());
|
||||
player.getWorld().playSound(player.getLocation(), Sound.BLOCK_WATER_AMBIENT,1,1);
|
||||
waterPot(wateringCan.getWidth(), wateringCan.getLength(), block.getLocation(), player.getLocation().getYaw());
|
||||
if (ConfigReader.Message.hasWaterInfo){
|
||||
@@ -207,9 +161,16 @@ public class RightClick implements Listener {
|
||||
ConfigReader.Message.waterEmpty.repeat(wateringCan.getMax() - water + 1) + ConfigReader.Message.waterRight;
|
||||
AdventureManager.playerActionbar(player, string.replace("{max_water}", String.valueOf(wateringCan.getMax())).replace("{water}", String.valueOf(water -1)));
|
||||
}
|
||||
if (ConfigReader.Basic.hasWaterLore){
|
||||
String string = (ConfigReader.Basic.waterLeft + ConfigReader.Basic.waterFull.repeat(water - 1) +
|
||||
ConfigReader.Basic.waterEmpty.repeat(wateringCan.getMax() - water + 1) + ConfigReader.Basic.waterRight).replace("{max_water}", String.valueOf(wateringCan.getMax())).replace("{water}", String.valueOf(water -1));
|
||||
List<String> lores = nbtItem.getCompound("display").getStringList("Lore");
|
||||
lores.clear();
|
||||
ConfigReader.Basic.waterLore.forEach(lore -> lores.add(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(lore.replace("{water_info}", string)))));
|
||||
}
|
||||
itemStack.setItemMeta(nbtItem.getItem().getItemMeta());
|
||||
}else if (namespacedID.contains("_stage_")){
|
||||
nbtItem.setInteger("WaterAmount", water - 1);
|
||||
itemStack.setItemMeta(nbtItem.getItem().getItemMeta());
|
||||
player.getWorld().playSound(player.getLocation(), Sound.BLOCK_WATER_AMBIENT,1,1);
|
||||
waterPot(wateringCan.getWidth(), wateringCan.getLength(), block.getLocation().subtract(0,1,0), player.getLocation().getYaw());
|
||||
if (ConfigReader.Message.hasWaterInfo){
|
||||
@@ -217,6 +178,14 @@ public class RightClick implements Listener {
|
||||
ConfigReader.Message.waterEmpty.repeat(wateringCan.getMax() - water + 1) + ConfigReader.Message.waterRight;
|
||||
AdventureManager.playerActionbar(player, string.replace("{max_water}", String.valueOf(wateringCan.getMax())).replace("{water}", String.valueOf(water -1)));
|
||||
}
|
||||
if (ConfigReader.Basic.hasWaterLore){
|
||||
String string = (ConfigReader.Basic.waterLeft + ConfigReader.Basic.waterFull.repeat(water - 1) +
|
||||
ConfigReader.Basic.waterEmpty.repeat(wateringCan.getMax() - water + 1) + ConfigReader.Basic.waterRight).replace("{max_water}", String.valueOf(wateringCan.getMax())).replace("{water}", String.valueOf(water -1));
|
||||
List<String> lores = nbtItem.getCompound("display").getStringList("Lore");
|
||||
lores.clear();
|
||||
ConfigReader.Basic.waterLore.forEach(lore -> lores.add(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(lore.replace("{water_info}", string)))));
|
||||
}
|
||||
itemStack.setItemMeta(nbtItem.getItem().getItemMeta());
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -312,6 +281,61 @@ public class RightClick implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (action == Action.RIGHT_CLICK_BLOCK) {
|
||||
Block block = event.getClickedBlock();
|
||||
Location location = block.getLocation();
|
||||
CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block);
|
||||
if (customBlock == null) return;
|
||||
for (Integration integration : ConfigReader.Config.integration){
|
||||
if (!integration.canBreak(location, player)) return;
|
||||
}
|
||||
String namespacedID = customBlock.getNamespacedID();
|
||||
if (namespacedID.contains("_stage_")){
|
||||
if(namespacedID.equals(ConfigReader.Basic.dead)) return;
|
||||
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]);
|
||||
ThreadLocalRandom current = ThreadLocalRandom.current();
|
||||
int random = current.nextInt(cropInstance.getMin(), cropInstance.getMax() + 1);
|
||||
World world = location.getWorld();
|
||||
Location itemLoc = location.clone().add(0.5,0.2,0.5);
|
||||
Fertilizer fertilizer = PotManager.Cache.get(location.clone().subtract(0,1,0));
|
||||
if (fertilizer != null){
|
||||
if (fertilizer instanceof QualityCrop qualityCrop){
|
||||
int[] weights = qualityCrop.getChance();
|
||||
double weightTotal = weights[0] + weights[1] + weights[2];
|
||||
double rank_1 = weights[0]/(weightTotal);
|
||||
double rank_2 = 1 - weights[1]/(weightTotal);
|
||||
for (int i = 0; i < random; i++){
|
||||
double ran = Math.random();
|
||||
if (ran < rank_1){
|
||||
world.dropItem(itemLoc, CustomStack.getInstance(cropInstance.getQuality_1()).getItemStack());
|
||||
}else if(ran > rank_2){
|
||||
world.dropItem(itemLoc, CustomStack.getInstance(cropInstance.getQuality_2()).getItemStack());
|
||||
}else {
|
||||
world.dropItem(itemLoc, CustomStack.getInstance(cropInstance.getQuality_3()).getItemStack());
|
||||
}
|
||||
}
|
||||
}else {
|
||||
BreakBlock.normalDrop(cropInstance, random, itemLoc, world);
|
||||
}
|
||||
}
|
||||
else {
|
||||
BreakBlock.normalDrop(cropInstance, random, itemLoc, world);
|
||||
}
|
||||
}else {
|
||||
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]);
|
||||
if(crop.getReturnStage() != null){
|
||||
CustomBlock.place(crop.getReturnStage(), location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user