mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-19 15:09:25 +00:00
Added more vanilla blocks support
This commit is contained in:
@@ -359,7 +359,7 @@ public class PotBlock extends AbstractCustomCropsBlock {
|
||||
future.thenAcceptAsync((run) -> {
|
||||
if (!run) return;
|
||||
// work as vanilla farmland
|
||||
if (config.vanillaFarmland()) return;
|
||||
if (config.disablePluginMechanism()) return;
|
||||
|
||||
boolean hasNaturalWater = false;
|
||||
boolean waterChanged = false;
|
||||
@@ -620,7 +620,7 @@ public class PotBlock extends AbstractCustomCropsBlock {
|
||||
}
|
||||
|
||||
public void updateBlockAppearance(Location location, PotConfig config, boolean hasWater, @Nullable Fertilizer fertilizer) {
|
||||
if (config.vanillaFarmland()) return;
|
||||
if (config.disablePluginMechanism()) return;
|
||||
String appearance = config.getPotAppearance(hasWater, fertilizer == null ? null : fertilizer.type());
|
||||
BukkitCustomCropsPlugin.getInstance().getItemManager().placeBlock(location, appearance);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class SprinklerBlock extends AbstractCustomCropsBlock {
|
||||
|
||||
@@ -295,7 +294,7 @@ public class SprinklerBlock extends AbstractCustomCropsBlock {
|
||||
CustomCropsBlockState anotherState = optionalState.get();
|
||||
if (anotherState.type() instanceof PotBlock potBlock) {
|
||||
PotConfig potConfig = potBlock.config(anotherState);
|
||||
if (!potConfig.vanillaFarmland()) {
|
||||
if (!potConfig.disablePluginMechanism()) {
|
||||
if (config.potWhitelist().contains(potConfig.id())) {
|
||||
if (potBlock.addWater(anotherState, potConfig, config.wateringAmount())) {
|
||||
BukkitCustomCropsPlugin.getInstance().getScheduler().sync().run(
|
||||
|
||||
@@ -82,6 +82,9 @@ public class FertilizerItem extends AbstractCustomCropsItem {
|
||||
// if the clicked block is a pot
|
||||
PotConfig potConfig = Registries.ITEM_TO_POT.get(targetBlockID);
|
||||
if (potConfig != null) {
|
||||
if (potConfig.disablePluginMechanism()) {
|
||||
return InteractionResult.COMPLETE;
|
||||
}
|
||||
// check pot whitelist
|
||||
if (!fertilizerConfig.whitelistPots().contains(potConfig.id())) {
|
||||
ActionManager.trigger(context, fertilizerConfig.wrongPotActions());
|
||||
|
||||
@@ -286,7 +286,7 @@ public class WateringCanItem extends AbstractCustomCropsItem {
|
||||
|
||||
PotConfig potConfig = Registries.ITEM_TO_POT.get(targetBlockID);
|
||||
if (potConfig != null) {
|
||||
if (potConfig.vanillaFarmland())
|
||||
if (potConfig.disablePluginMechanism())
|
||||
return InteractionResult.COMPLETE;
|
||||
// need to click the upper face
|
||||
if (blockFace != BlockFace.UP)
|
||||
|
||||
@@ -27,6 +27,7 @@ import net.momirealms.customcrops.common.util.Pair;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -67,7 +68,7 @@ public interface PotConfig {
|
||||
*
|
||||
* @return True if disabled
|
||||
*/
|
||||
boolean vanillaFarmland();
|
||||
boolean disablePluginMechanism();
|
||||
|
||||
/**
|
||||
* Gets the methods available for watering the pot.
|
||||
@@ -236,6 +237,14 @@ public interface PotConfig {
|
||||
*/
|
||||
Builder vanillaFarmland(boolean vanillaFarmland);
|
||||
|
||||
/**
|
||||
* Mark this pot as a vanilla one and disable plugin mechanisms
|
||||
*
|
||||
* @param vanillaPots pots
|
||||
* @return The current instance of the Builder.
|
||||
*/
|
||||
Builder vanillaPots(List<String> vanillaPots);
|
||||
|
||||
/**
|
||||
* Sets whether the pot can accept rain as a source of water.
|
||||
*
|
||||
|
||||
@@ -24,16 +24,17 @@ import net.momirealms.customcrops.api.misc.water.WaterBar;
|
||||
import net.momirealms.customcrops.api.misc.water.WateringMethod;
|
||||
import net.momirealms.customcrops.api.requirement.Requirement;
|
||||
import net.momirealms.customcrops.common.util.Pair;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.type.Farmland;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public class PotConfigImpl implements PotConfig {
|
||||
|
||||
private final String id;
|
||||
private final boolean vanillaFarmland;
|
||||
private final boolean disablePluginSystem;
|
||||
private final Pair<String, String> basicAppearance;
|
||||
private final HashMap<FertilizerType, Pair<String, String>> potAppearanceMap;
|
||||
private final Set<String> blocks = new HashSet<>();
|
||||
@@ -77,7 +78,8 @@ public class PotConfigImpl implements PotConfig {
|
||||
Action<Player>[] breakActions,
|
||||
Action<Player>[] addWaterActions,
|
||||
Action<Player>[] fullWaterActions,
|
||||
Action<Player>[] maxFertilizerActions
|
||||
Action<Player>[] maxFertilizerActions,
|
||||
List<String> vanillaPots
|
||||
) {
|
||||
this.id = id;
|
||||
this.vanillaFarmland = vanillaFarmland;
|
||||
@@ -109,10 +111,19 @@ public class PotConfigImpl implements PotConfig {
|
||||
this.wetBlocks.add(pair.right());
|
||||
}
|
||||
if (vanillaFarmland) {
|
||||
disablePluginSystem = true;
|
||||
this.blocks.clear();
|
||||
for (int i = 0; i <= 7; i++) {
|
||||
this.blocks.add("minecraft:farmland[moisture=" + i +"]");
|
||||
Farmland data = (Farmland) Material.FARMLAND.createBlockData();
|
||||
data.setMoisture(i);
|
||||
this.blocks.add(data.getAsString());
|
||||
}
|
||||
} else if (vanillaPots != null && !vanillaPots.isEmpty()) {
|
||||
disablePluginSystem = true;
|
||||
this.blocks.clear();
|
||||
this.blocks.addAll(vanillaPots);
|
||||
} else {
|
||||
disablePluginSystem = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,28 +134,28 @@ public class PotConfigImpl implements PotConfig {
|
||||
|
||||
@Override
|
||||
public int storage() {
|
||||
if (vanillaFarmland()) return 0;
|
||||
if (disablePluginMechanism()) return 0;
|
||||
return storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRainDropAccepted() {
|
||||
return isRainDropAccepted && !vanillaFarmland();
|
||||
return isRainDropAccepted && !disablePluginMechanism();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNearbyWaterAccepted() {
|
||||
return isNearbyWaterAccepted && !vanillaFarmland();
|
||||
return isNearbyWaterAccepted && !disablePluginMechanism();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean vanillaFarmland() {
|
||||
return vanillaFarmland;
|
||||
public boolean disablePluginMechanism() {
|
||||
return disablePluginSystem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WateringMethod[] wateringMethods() {
|
||||
if (vanillaFarmland()) return new WateringMethod[0];
|
||||
if (disablePluginMechanism()) return new WateringMethod[0];
|
||||
return wateringMethods;
|
||||
}
|
||||
|
||||
@@ -155,18 +166,19 @@ public class PotConfigImpl implements PotConfig {
|
||||
|
||||
@Override
|
||||
public boolean isWet(String blockID) {
|
||||
if (vanillaFarmland()) return false;
|
||||
if (disablePluginMechanism()) return false;
|
||||
return wetBlocks.contains(blockID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WaterBar waterBar() {
|
||||
if (disablePluginMechanism()) return null;
|
||||
return waterBar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int maxFertilizers() {
|
||||
if (vanillaFarmland) return 0;
|
||||
if (disablePluginMechanism()) return 0;
|
||||
return maxFertilizers;
|
||||
}
|
||||
|
||||
@@ -259,10 +271,11 @@ public class PotConfigImpl implements PotConfig {
|
||||
private Action<Player>[] addWaterActions;
|
||||
private Action<Player>[] fullWaterActions;
|
||||
private Action<Player>[] maxFertilizerActions;
|
||||
private List<String> vanillaPots = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public PotConfig build() {
|
||||
return new PotConfigImpl(id, vanillaFarmland, basicAppearance, potAppearanceMap, storage, isRainDropAccepted, isNearbyWaterAccepted, wateringMethods, waterBar, maxFertilizers, placeRequirements, breakRequirements, useRequirements, tickActions, reachLimitActions, interactActions, placeActions, breakActions, addWaterActions, fullWaterActions, maxFertilizerActions);
|
||||
return new PotConfigImpl(id, vanillaFarmland, basicAppearance, potAppearanceMap, storage, isRainDropAccepted, isNearbyWaterAccepted, wateringMethods, waterBar, maxFertilizers, placeRequirements, breakRequirements, useRequirements, tickActions, reachLimitActions, interactActions, placeActions, breakActions, addWaterActions, fullWaterActions, maxFertilizerActions, vanillaPots);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -283,6 +296,12 @@ public class PotConfigImpl implements PotConfig {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder vanillaPots(List<String> vanillaPots) {
|
||||
this.vanillaPots = vanillaPots;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder isRainDropAccepted(boolean isRainDropAccepted) {
|
||||
this.isRainDropAccepted = isRainDropAccepted;
|
||||
|
||||
@@ -38,6 +38,9 @@ public class ListUtils {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<String> toList(final Object obj) {
|
||||
if (obj == null) {
|
||||
return List.of();
|
||||
}
|
||||
if (obj instanceof String s) {
|
||||
return List.of(s);
|
||||
} else if (obj instanceof List<?> list) {
|
||||
|
||||
@@ -65,8 +65,9 @@ public class DebugDataCommand extends BukkitCommandFeature<CommandSender> {
|
||||
.sendMessage(AdventureHelper.miniMessage("<red>CustomCrops Data not found"));
|
||||
}
|
||||
});
|
||||
String bData = block.getBlockData().getAsString();
|
||||
BukkitCustomCropsPlugin.getInstance().getSenderFactory().wrap(player)
|
||||
.sendMessage(AdventureHelper.miniMessage("<green>Vanilla crop data: " + block.getBlockData().getAsString()));
|
||||
.sendMessage(AdventureHelper.miniMessage("<green>Vanilla crop data: <hover:show_text:'<yellow>Copy'><click:copy_to_clipboard:'"+bData+"'>" + bData + "</click>"));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import net.momirealms.customcrops.api.core.world.CustomCropsBlockState;
|
||||
import net.momirealms.customcrops.api.misc.value.TextValue;
|
||||
import net.momirealms.customcrops.api.misc.water.WaterBar;
|
||||
import net.momirealms.customcrops.api.requirement.RequirementManager;
|
||||
import net.momirealms.customcrops.common.util.ListUtils;
|
||||
import net.momirealms.customcrops.common.util.Pair;
|
||||
import net.momirealms.customcrops.common.util.TriFunction;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -116,6 +117,7 @@ public class ConfigType {
|
||||
PotConfig config = PotConfig.builder()
|
||||
.id(id)
|
||||
.vanillaFarmland(section.getBoolean("vanilla-farmland", false))
|
||||
.vanillaPots(ListUtils.toList(section.get("vanilla-blocks")))
|
||||
.storage(section.getInt("storage", 5))
|
||||
.isRainDropAccepted(section.getBoolean("absorb-rainwater", false))
|
||||
.isNearbyWaterAccepted(section.getBoolean("absorb-nearby-water", false))
|
||||
|
||||
Reference in New Issue
Block a user