make hoe harvest faster
This commit is contained in:
parent
e4401d2b3d
commit
7f46b71e2f
@ -9,7 +9,7 @@
|
|||||||
loader_version=0.12.12
|
loader_version=0.12.12
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 1.18.1.1
|
mod_version = 1.18.1.2
|
||||||
maven_group = de.jottyfan.minecraft
|
maven_group = de.jottyfan.minecraft
|
||||||
archives_base_name = quickiefabric
|
archives_base_name = quickiefabric
|
||||||
|
|
||||||
|
@ -2,6 +2,9 @@ package de.jottyfan.minecraft.quickiefabric.tools;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import de.jottyfan.minecraft.quickiefabric.init.RegistryManager;
|
import de.jottyfan.minecraft.quickiefabric.init.RegistryManager;
|
||||||
@ -9,6 +12,7 @@ import net.fabricmc.fabric.api.tool.attribute.v1.ToolManager;
|
|||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
|
import net.minecraft.block.CropBlock;
|
||||||
import net.minecraft.item.HoeItem;
|
import net.minecraft.item.HoeItem;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
@ -16,8 +20,10 @@ import net.minecraft.item.ItemUsageContext;
|
|||||||
import net.minecraft.item.ToolMaterials;
|
import net.minecraft.item.ToolMaterials;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.math.Vec3i;
|
import net.minecraft.util.math.Vec3i;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -25,6 +31,9 @@ import net.minecraft.util.math.Vec3i;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ToolSpeedpowderHoe extends HoeItem implements ToolRangeable {
|
public class ToolSpeedpowderHoe extends HoeItem implements ToolRangeable {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(ToolSpeedpowderHoe.class);
|
||||||
|
|
||||||
public static final Integer DEFAULT_PLOW_RANGE = 4;
|
public static final Integer DEFAULT_PLOW_RANGE = 4;
|
||||||
public HarvestRange range;
|
public HarvestRange range;
|
||||||
|
|
||||||
@ -36,14 +45,19 @@ public class ToolSpeedpowderHoe extends HoeItem implements ToolRangeable {
|
|||||||
@Override
|
@Override
|
||||||
public ActionResult useOnBlock(ItemUsageContext context) {
|
public ActionResult useOnBlock(ItemUsageContext context) {
|
||||||
ActionResult res = super.useOnBlock(context);
|
ActionResult res = super.useOnBlock(context);
|
||||||
if (!ActionResult.PASS.equals(res)) {
|
boolean isCrop = context.getWorld().getBlockState(context.getBlockPos()).getBlock() instanceof CropBlock;
|
||||||
|
if (!ActionResult.PASS.equals(res) || isCrop) {
|
||||||
for (int x = -this.range.getxRange(); x <= this.range.getxRange(); x++) {
|
for (int x = -this.range.getxRange(); x <= this.range.getxRange(); x++) {
|
||||||
for (int y = -this.range.getyRange(); y <= this.range.getyRange(); y++) {
|
for (int y = -this.range.getyRange(); y <= this.range.getyRange(); y++) {
|
||||||
for (int z = -this.range.getzRange(); z <= this.range.getzRange(); z++) {
|
for (int z = -this.range.getzRange(); z <= this.range.getzRange(); z++) {
|
||||||
|
if (!isCrop) {
|
||||||
BlockHitResult bhr = new BlockHitResult(context.getHitPos(), Direction.UP,
|
BlockHitResult bhr = new BlockHitResult(context.getHitPos(), Direction.UP,
|
||||||
context.getBlockPos().add(new Vec3i(x, y, z)), isDamageable());
|
context.getBlockPos().add(new Vec3i(x, y, z)), isDamageable());
|
||||||
ItemUsageContext ctx = new ItemUsageContext(context.getPlayer(), context.getHand(), bhr);
|
ItemUsageContext ctx = new ItemUsageContext(context.getPlayer(), context.getHand(), bhr);
|
||||||
super.useOnBlock(ctx);
|
super.useOnBlock(ctx);
|
||||||
|
} else {
|
||||||
|
harvestIfPossible(context.getBlockPos().add(x, y, z), context.getWorld());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,6 +65,18 @@ public class ToolSpeedpowderHoe extends HoeItem implements ToolRangeable {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void harvestIfPossible(BlockPos pos, World world) {
|
||||||
|
BlockState blockState = world.getBlockState(pos);
|
||||||
|
Block block = blockState.getBlock();
|
||||||
|
if (block instanceof CropBlock) {
|
||||||
|
CropBlock cBlock = (CropBlock) block;
|
||||||
|
if (cBlock.isMature(blockState)) {
|
||||||
|
Block.dropStacks(blockState, world, pos);
|
||||||
|
world.setBlockState(pos, cBlock.withAge(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HarvestRange getRange(ItemStack stack) {
|
public HarvestRange getRange(ItemStack stack) {
|
||||||
// TODO: get range from stack
|
// TODO: get range from stack
|
||||||
|
Loading…
x
Reference in New Issue
Block a user