Allow the Scythe to harvest crops in an AOE (#159)

This commit is contained in:
Yannick Marcotte-Gourde authored and GitHub committed 2025-04-02 12:07:47 -05:00
1 parent eb0ac72963
commit d370627703
11 files changed
+219 -1

No files matched your search

@@ -0,0 +1,12 @@
package tconstruct.api.harvesting;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public interface CropHarvestHandler {
boolean couldHarvest(World world, int x, int y, int z);
boolean tryHarvest(ItemStack stack, EntityPlayer player, World world, int x, int y, int z);
}
@@ -0,0 +1,18 @@
package tconstruct.api.harvesting;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class CropHarvestHandlers {
private static List<CropHarvestHandler> cropHarvestHandlers = new ArrayList<>();
public static void registerCropHarvestHandler(CropHarvestHandler handler) {
cropHarvestHandlers.add(handler);
}
public static List<CropHarvestHandler> getCropHarvestHandlers() {
return Collections.unmodifiableList(cropHarvestHandlers);
}
}
@@ -0,0 +1,32 @@
package tconstruct.api.harvesting;
import net.minecraft.block.BlockCrops;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class VanillaCropsHarvestHandler implements CropHarvestHandler {
@Override
public boolean couldHarvest(World world, int x, int y, int z) {
return world.getBlock(x, y, z) instanceof BlockCrops;
}
@Override
public boolean tryHarvest(ItemStack stack, EntityPlayer player, World world, int x, int y, int z) {
int blockMetadata = world.getBlockMetadata(x, y, z);
boolean shouldHarvest = couldHarvest(world, x, y, z) && blockMetadata >= 7;
if (shouldHarvest) {
world.getBlock(x, y, z).dropBlockAsItem(
world,
x,
y,
z,
world.getBlockMetadata(x, y, z),
EnchantmentHelper.getFortuneModifier(player));
world.setBlockMetadataWithNotify(x, y, z, 0, 2);
}
return shouldHarvest;
}
}