From 7a7f1c58e57a8ab3dc39f7321e153e2af492029f Mon Sep 17 00:00:00 2001 From: Li Junyu Date: Sun, 8 Sep 2024 16:19:07 +0800 Subject: [PATCH 1/2] Use `Holder` for crops to allow items as crops --- .../mods/kubejs/block/custom/CropBlockBuilder.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/dev/latvian/mods/kubejs/block/custom/CropBlockBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/custom/CropBlockBuilder.java index ae73b81ea..a0a9ff4fb 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/custom/CropBlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/custom/CropBlockBuilder.java @@ -13,6 +13,7 @@ import dev.latvian.mods.rhino.util.ReturnsSelf; import net.minecraft.advancements.critereon.StatePropertiesPredicate; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.BlockTags; import net.minecraft.world.item.Item; @@ -124,7 +125,7 @@ public List getShapes() { public transient ToIntFunction fertilizerCallback; public transient SurviveCallback surviveCallback; - public transient List> outputs; + public transient List, NumberProvider>> outputs; public CropBlockBuilder(ResourceLocation id) { super(id); @@ -160,13 +161,13 @@ public BlockBuilder noItem() { } @Info("Add a crop output with exactly one output.") - public CropBlockBuilder crop(Item output) { + public CropBlockBuilder crop(Holder output) { crop(output, ConstantValue.exactly(1.0f)); return this; } @Info("Add a crop output with a specific amount.") - public CropBlockBuilder crop(Item output, NumberProvider chance) { + public CropBlockBuilder crop(Holder output, NumberProvider chance) { outputs.add(new Pair<>(output, chance)); return this; } @@ -229,7 +230,10 @@ public LootTable generateLootTable() { var builder = LootTable.lootTable(); for (var output : outputs) { - var cropItem = LootItem.lootTableItem(output.getFirst()) + if (!output.getFirst().isBound()) { + continue; + } + var cropItem = LootItem.lootTableItem(output.getFirst().value()) .apply(SetItemCountFunction.setCount(output.getSecond())) .when(mature); builder.withPool(LootPool.lootPool().add(cropItem)); From 5a7932094c2c22a93a7f27d1b86d31539f2b72b6 Mon Sep 17 00:00:00 2001 From: Li Junyu Date: Sun, 8 Sep 2024 16:29:50 +0800 Subject: [PATCH 2/2] Added `noSeeds` to prevent seeds from dropping in the loot table --- .../mods/kubejs/block/custom/CropBlockBuilder.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/latvian/mods/kubejs/block/custom/CropBlockBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/custom/CropBlockBuilder.java index a0a9ff4fb..2a8738c63 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/custom/CropBlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/custom/CropBlockBuilder.java @@ -68,7 +68,7 @@ public ShapeBuilder(int age) { @Info(""" Describe the shape of the crop at a specific age. - + min/max coordinates are double values between 0 and 16. """) public ShapeBuilder shape(int age, double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { @@ -126,6 +126,7 @@ public List getShapes() { public transient SurviveCallback surviveCallback; public transient List, NumberProvider>> outputs; + public transient boolean noSeeds; public CropBlockBuilder(ResourceLocation id) { super(id); @@ -141,6 +142,7 @@ public CropBlockBuilder(ResourceLocation id) { hardness = 0.0f; resistance = 0.0f; outputs = new ArrayList<>(); + noSeeds = false; notSolid = true; soundType(SoundType.CROP); @@ -160,6 +162,12 @@ public BlockBuilder noItem() { return this; } + @Info("Remove seed drops from the loot table, does not prevent seed item from creating.") + public CropBlockBuilder noSeeds() { + this.noSeeds = true; + return this; + } + @Info("Add a crop output with exactly one output.") public CropBlockBuilder crop(Holder output) { crop(output, ConstantValue.exactly(1.0f)); @@ -239,7 +247,7 @@ public LootTable generateLootTable() { builder.withPool(LootPool.lootPool().add(cropItem)); } - if (itemBuilder != null) { + if (itemBuilder != null && !noSeeds) { var pool = LootPool.lootPool().add(LootItem.lootTableItem(itemBuilder.get()) .when(mature) .otherwise(LootItem.lootTableItem(itemBuilder.get()))