Skip to content

Commit

Permalink
Merge pull request #898 from Prunoideae/1.21.1/crop-holder
Browse files Browse the repository at this point in the history
Use `Holder<Item>` for crops to allow items as crops
  • Loading branch information
LatvianModder authored Sep 16, 2024
2 parents 7105ad6 + 5a79320 commit 5c8b4cf
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,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) {
Expand Down Expand Up @@ -124,7 +125,8 @@ public List<VoxelShape> getShapes() {
public transient ToIntFunction<RandomTickCallbackJS> fertilizerCallback;
public transient SurviveCallback surviveCallback;

public transient List<Pair<Item, NumberProvider>> outputs;
public transient List<Pair<Holder<Item>, NumberProvider>> outputs;
public transient boolean noSeeds;

public CropBlockBuilder(ResourceLocation id) {
super(id);
Expand All @@ -140,6 +142,7 @@ public CropBlockBuilder(ResourceLocation id) {
hardness = 0.0f;
resistance = 0.0f;
outputs = new ArrayList<>();
noSeeds = false;
notSolid = true;

soundType(SoundType.CROP);
Expand All @@ -159,14 +162,20 @@ 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(Item output) {
public CropBlockBuilder crop(Holder<Item> 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<Item> output, NumberProvider chance) {
outputs.add(new Pair<>(output, chance));
return this;
}
Expand Down Expand Up @@ -229,13 +238,16 @@ 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));
}

if (itemBuilder != null) {
if (itemBuilder != null && !noSeeds) {
var pool = LootPool.lootPool().add(LootItem.lootTableItem(itemBuilder.get())
.when(mature)
.otherwise(LootItem.lootTableItem(itemBuilder.get()))
Expand Down

0 comments on commit 5c8b4cf

Please sign in to comment.