import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Vec3;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
public class CarrotCollector {
private final Minecraft mc = Minecraft.getMinecraft();
public CarrotCollector() {
MinecraftForge.EVENT_BUS.register(this);
}
@SubscribeEvent
public void onTick(TickEvent.PlayerTickEvent event) {
if (mc.thePlayer == null || mc.theWorld == null) return;
for (int x = -5; x <= 5; x++) {
for (int z = -5; z <= 5; z++) {
for (int y = -1; y <= 2; y++) {
BlockPos pos = new BlockPos(mc.thePlayer.posX + x, mc.thePlayer.posY + y, mc.thePlayer.posZ + z);
if (mc.theWorld.getBlockState(pos).getBlock() == Blocks.carrots) {
harvestCarrot(pos);
return;
}
}
}
}
}
private void harvestCarrot(BlockPos pos) {
Vec3 vec = new Vec3(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
mc.thePlayer.setPositionAndUpdate(vec.xCoord, mc.thePlayer.posY, vec.zCoord);
mc.playerController.onPlayerRightClick(mc.thePlayer, mc.theWorld, mc.thePlayer.getHeldItem(), pos, EnumFacing.UP, vec);
}
}