ExcessiveAmountsOfZombies / Croptopia

Fabric and Forge mod that adds crops and food to the game.
https://www.curseforge.com/minecraft/mc-mods/croptopia-fabric
90 stars 74 forks source link

Feature Suggestion: Replantable (and compostable) Crops #49

Closed BrekiTomasson closed 3 years ago

BrekiTomasson commented 3 years ago

While I agree with the game mechanic that you find seeds when destroying grass, I think the resulting crops should be replantable without having to turn them back into seeds first. Think, for example, of how you can pick carrots and potatoes from the ground and immediately replant them.

Doing this will improve the user experience of this mod and will also greatly simplify Farmer Villager automation, as there is no way currently to get the villagers to convert, for example, Cauliflower to Cauliflower Seeds to replant.

ExcessiveAmountsOfZombies commented 3 years ago

I can look into the first one at some point. Villager automation is more difficult as I believe the vanilla crops are hardcoded into their AI and I'm not sure if there is an easy way to add more.

BrekiTomasson commented 3 years ago

I've already got this working in a mod using a workaround - I've added the individual seeds as a guaranteed drop when harvesting the Croptopia crops so that Farmer villagers pick them up, then I've added Croptopia seeds to the list of allowable seeds that they can plant. Basically, I've got the following Mixin to VillagerEntity.class:

    @ModifyArg(method = "hasSeedToPlant", at = @At(value = "INVOKE",
        target = "Lnet/minecraft/inventory/SimpleInventory;containsAny(Ljava/util/Set;)Z"))
    private Set<Item> addPlantableSeeds(Set<Item> set) {
        return ImmutableSet.<Item>builder()
            .addAll(set)
            .addAll(Croptopia.SEEDS)
            .build();
    }

And then Croptopia.SEEDS looks like this:

private static List<String> PLANTED_CROPS = Arrays.asList("artichoke", "asparagus", "barley", "basil", "bellpepper", "blackbean", "blackberry", "blueberry", "broccoli", "cabbage", "cantaloupe", "cauliflower", "celery", "chile_pepper", "coffee", "corn", "cranberry", "cucumber", "currant", "eggplant", "elderberry", "garlic", "ginger", "grape", "greenbean", "greenonion", "honeydew", "hops", "kale", "kiwi", "leek", "lettuce", "mustard", "oat", "olive", "onion", "peanut", "pineapple", "radish", "raspberry", "rhubarb", "rice", "rutabaga", "saguaro", "soybean", "spinach", "squash", "strawberry", "sweetpotato", "tomatillo", "tomato", "turmeric", "turnip", "yam", "zucchini");

public static List<Item> SEEDS = PLANTED_CROPS.stream()
    .map(seed -> Registry.ITEM.get(cropSeed(seed)).asItem())
    .collect(Collectors.toList());

The cropSeed() method is just a simple shortcut that does this:

public static Identifier cropSeed(String crop) {
    return new Identifier("croptopia", crop + "_seed");
}

So yeah, not hardcoded.

ExcessiveAmountsOfZombies commented 3 years ago

ok, i'm not planning on changing the items themselves to be plantable, I'd rather people just modify the loot blocks if they want seeds to drop. That said, #68 allows villagers to harvest and plant croptopia crops/seeds. they'll pick them up and throw them too.

BrekiTomasson commented 3 years ago

Looking good, thanks!

BrekiTomasson commented 3 years ago

Any plans for when #68 will be merged and released?

ExcessiveAmountsOfZombies commented 3 years ago

soon, possibly the weekend, busy with studies again

ExcessiveAmountsOfZombies commented 3 years ago

1.3.2 for fabric is under review at the moment. I'll leave this open until I add this feature to forge

BrekiTomasson commented 3 years ago

I just noticed one minor thing you might want to consider adding, however. I was trying out the new version for Fabric and noticed that the villagers weren't treating their crops quite like normal crops. After some testing, I realized that it was because they weren't able to compost them.

You'll need to run this for every crop and seed:

CompostingChanceRegistry.INSTANCE.add(item, value);

The value is between 0f and 1f, how likely the seed/crop is to raise the level of your composter. Seeds tend to be 0.3f while harvested crops tend to be 0.65f, but you might want to make these values slightly larger for the "bigger" crops maybe.

BrekiTomasson commented 3 years ago

Opened a Pull Request #76 for the change mentioned above. Fabric-only, though, so you'll have to do the equivalent for Forge.

ExcessiveAmountsOfZombies commented 3 years ago

I added this to forge, probably for 1.4.0 so I'll close this now